Skip to content

Commit b6ef1d3

Browse files
committed
[fix] handle "monospace" font-family on web
This hack corrects the inheritance and scaling of font size when the font-family is "monospace".
1 parent fd6ccbc commit b6ef1d3

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

packages/react-native-web/src/exports/StyleSheet/__tests__/__snapshots__/createReactDOMStyle-test.js.snap

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,15 @@ Object {
66
}
77
`;
88

9+
exports[`apis/StyleSheet/createReactDOMStyle fontFamily fontFamily: "monospace" 1`] = `
10+
Object {
11+
"fontFamily": "monospace, monospace",
12+
}
13+
`;
14+
915
exports[`apis/StyleSheet/createReactDOMStyle fontFamily general case 1`] = `
1016
Object {
11-
"fontFamily": "Georgia, Times",
17+
"fontFamily": "Georgia, Times, serif",
1218
}
1319
`;
1420

packages/react-native-web/src/exports/StyleSheet/__tests__/createReactDOMStyle-test.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,11 @@ describe('apis/StyleSheet/createReactDOMStyle', () => {
122122

123123
describe('fontFamily', () => {
124124
test('general case', () => {
125-
expect(createReactDOMStyle({ fontFamily: 'Georgia, Times' })).toMatchSnapshot();
125+
expect(createReactDOMStyle({ fontFamily: 'Georgia, Times, serif' })).toMatchSnapshot();
126+
});
127+
128+
test('fontFamily: "monospace"', () => {
129+
expect(createReactDOMStyle({ fontFamily: 'monospace' })).toMatchSnapshot();
126130
});
127131

128132
test('fontFamily: "System"', () => {

packages/react-native-web/src/exports/StyleSheet/createReactDOMStyle.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ const borderWidthProps = {
6060
borderLeftWidth: true
6161
};
6262

63+
const monospaceFontStack = 'monospace, monospace';
6364
const systemFontStack =
6465
'-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Ubuntu, "Helvetica Neue", sans-serif';
6566

@@ -234,8 +235,13 @@ const createReducer = (style, styleProps) => {
234235
}
235236

236237
case 'fontFamily': {
237-
const isSystem = value === 'System';
238-
resolvedStyle.fontFamily = isSystem ? systemFontStack : value;
238+
if (value === 'System') {
239+
resolvedStyle.fontFamily = systemFontStack;
240+
} else if (value === 'monospace') {
241+
resolvedStyle.fontFamily = monospaceFontStack;
242+
} else {
243+
resolvedStyle.fontFamily = value;
244+
}
239245
break;
240246
}
241247

0 commit comments

Comments
 (0)