Skip to content

Commit 29fcd9a

Browse files
committed
[change] Text is position relative by default
Match default Text rendering in React Native. Fix #2498
1 parent 47d77ac commit 29fcd9a

File tree

3 files changed

+71
-32
lines changed

3 files changed

+71
-32
lines changed

packages/react-native-web/src/exports/AppRegistry/__tests__/index-test.node.js

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import AppRegistry from '..';
99
import React from 'react';
1010
import ReactDOMServer from 'react-dom/server';
1111
import StyleSheet from '../../StyleSheet';
12+
import Text from '../../Text';
1213
import View from '../../View';
1314

1415
const NoopComponent = () => React.createElement('div');
@@ -44,13 +45,20 @@ describe('AppRegistry', () => {
4445
html{-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;-webkit-tap-highlight-color:rgba(0,0,0,0);}
4546
input::-webkit-search-cancel-button,input::-webkit-search-decoration,input::-webkit-search-results-button,input::-webkit-search-results-decoration{display:none;}
4647
[stylesheet-group=\\"1\\"]{}
48+
.css-text-13q1o4w{background-color:rgba(0,0,0,0.00);border:0 solid black;box-sizing:border-box;color:rgba(0,0,0,1.00);display:inline;font:14px -apple-system,BlinkMacSystemFont,\\"Segoe UI\\",Roboto,Helvetica,Arial,sans-serif;list-style:none;margin:0px;padding:0px;position:relative;text-align:inherit;text-decoration:none;white-space:pre-wrap;word-wrap:break-word;}
49+
.css-textHasAncestor-1jxf684{background-color:rgba(0,0,0,0.00);border:0 solid black;box-sizing:border-box;color:inherit;display:inline;font:inherit;list-style:none;margin:0px;padding:0px;position:relative;text-align:inherit;text-decoration:none;white-space:inherit;word-wrap:break-word;}
4750
.css-view-175oi2r{align-items:stretch;background-color:rgba(0,0,0,0.00);border:0 solid black;box-sizing:border-box;display:flex;flex-basis:auto;flex-direction:column;flex-shrink:0;list-style:none;margin:0px;min-height:0px;min-width:0px;padding:0px;position:relative;text-decoration:none;z-index:0;}
4851
[stylesheet-group=\\"2\\"]{}
52+
.r-display-krxsd3{display:-webkit-box;}
4953
.r-display-xoduu5{display:inline-flex;}
5054
.r-flex-13awgt0{flex:1;}
55+
.r-overflow-1udh08x{overflow-x:hidden;overflow-y:hidden;}
5156
[stylesheet-group=\\"3\\"]{}
57+
.r-WebkitBoxOrient-8akbws{-webkit-box-orient:vertical;}
5258
.r-bottom-1p0dtai{bottom:0px;}
59+
.r-cursor-1loqt21{cursor:pointer;}
5360
.r-left-1d2f490{left:0px;}
61+
.r-maxWidth-dnmrzs{max-width:100%;}
5462
.r-pointerEvents-105ug2t{pointer-events:auto!important;}
5563
.r-pointerEvents-12vffkv>*{pointer-events:auto;}
5664
.r-pointerEvents-12vffkv{pointer-events:none!important;}
@@ -59,7 +67,12 @@ describe('AppRegistry', () => {
5967
.r-pointerEvents-ah5dr5{pointer-events:auto!important;}
6068
.r-position-u8s1d{position:absolute;}
6169
.r-right-zchlnj{right:0px;}
62-
.r-top-ipm5af{top:0px;}</style>"
70+
.r-textOverflow-1udbk01{text-overflow:ellipsis;}
71+
.r-top-ipm5af{top:0px;}
72+
.r-userSelect-1xnzce8{-moz-user-select:text;-webkit-user-select:text;user-select:text;}
73+
.r-userSelect-lrvibr{-moz-user-select:none;-webkit-user-select:none;user-select:none;}
74+
.r-whiteSpace-3s2u2q{white-space:nowrap;}
75+
.r-wordWrap-1iln25a{word-wrap:normal;}</style>"
6376
`);
6477
});
6578

@@ -78,7 +91,8 @@ describe('AppRegistry', () => {
7891
};
7992

8093
// First render "RootComponent"
81-
const RootComponent = () => React.createElement(View);
94+
const RootComponent = () =>
95+
React.createElement(View, React.createElement(Text));
8296
AppRegistry.registerComponent('App', () => RootComponent);
8397
const first = getApplicationStyles('App');
8498
expect(first).toMatchInlineSnapshot(`
@@ -88,13 +102,20 @@ describe('AppRegistry', () => {
88102
html{-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;-webkit-tap-highlight-color:rgba(0,0,0,0);}
89103
input::-webkit-search-cancel-button,input::-webkit-search-decoration,input::-webkit-search-results-button,input::-webkit-search-results-decoration{display:none;}
90104
[stylesheet-group=\\"1\\"]{}
105+
.css-text-13q1o4w{background-color:rgba(0,0,0,0.00);border:0 solid black;box-sizing:border-box;color:rgba(0,0,0,1.00);display:inline;font:14px -apple-system,BlinkMacSystemFont,\\"Segoe UI\\",Roboto,Helvetica,Arial,sans-serif;list-style:none;margin:0px;padding:0px;position:relative;text-align:inherit;text-decoration:none;white-space:pre-wrap;word-wrap:break-word;}
106+
.css-textHasAncestor-1jxf684{background-color:rgba(0,0,0,0.00);border:0 solid black;box-sizing:border-box;color:inherit;display:inline;font:inherit;list-style:none;margin:0px;padding:0px;position:relative;text-align:inherit;text-decoration:none;white-space:inherit;word-wrap:break-word;}
91107
.css-view-175oi2r{align-items:stretch;background-color:rgba(0,0,0,0.00);border:0 solid black;box-sizing:border-box;display:flex;flex-basis:auto;flex-direction:column;flex-shrink:0;list-style:none;margin:0px;min-height:0px;min-width:0px;padding:0px;position:relative;text-decoration:none;z-index:0;}
92108
[stylesheet-group=\\"2\\"]{}
109+
.r-display-krxsd3{display:-webkit-box;}
93110
.r-display-xoduu5{display:inline-flex;}
94111
.r-flex-13awgt0{flex:1;}
112+
.r-overflow-1udh08x{overflow-x:hidden;overflow-y:hidden;}
95113
[stylesheet-group=\\"3\\"]{}
114+
.r-WebkitBoxOrient-8akbws{-webkit-box-orient:vertical;}
96115
.r-bottom-1p0dtai{bottom:0px;}
116+
.r-cursor-1loqt21{cursor:pointer;}
97117
.r-left-1d2f490{left:0px;}
118+
.r-maxWidth-dnmrzs{max-width:100%;}
98119
.r-pointerEvents-105ug2t{pointer-events:auto!important;}
99120
.r-pointerEvents-12vffkv>*{pointer-events:auto;}
100121
.r-pointerEvents-12vffkv{pointer-events:none!important;}
@@ -103,7 +124,12 @@ describe('AppRegistry', () => {
103124
.r-pointerEvents-ah5dr5{pointer-events:auto!important;}
104125
.r-position-u8s1d{position:absolute;}
105126
.r-right-zchlnj{right:0px;}
106-
.r-top-ipm5af{top:0px;}"
127+
.r-textOverflow-1udbk01{text-overflow:ellipsis;}
128+
.r-top-ipm5af{top:0px;}
129+
.r-userSelect-1xnzce8{-moz-user-select:text;-webkit-user-select:text;user-select:text;}
130+
.r-userSelect-lrvibr{-moz-user-select:none;-webkit-user-select:none;user-select:none;}
131+
.r-whiteSpace-3s2u2q{white-space:nowrap;}
132+
.r-wordWrap-1iln25a{word-wrap:normal;}"
107133
`);
108134

109135
// Second render "AlternativeComponent"
@@ -124,15 +150,22 @@ describe('AppRegistry', () => {
124150
html{-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;-webkit-tap-highlight-color:rgba(0,0,0,0);}
125151
input::-webkit-search-cancel-button,input::-webkit-search-decoration,input::-webkit-search-results-button,input::-webkit-search-results-decoration{display:none;}
126152
[stylesheet-group=\\"1\\"]{}
153+
.css-text-13q1o4w{background-color:rgba(0,0,0,0.00);border:0 solid black;box-sizing:border-box;color:rgba(0,0,0,1.00);display:inline;font:14px -apple-system,BlinkMacSystemFont,\\"Segoe UI\\",Roboto,Helvetica,Arial,sans-serif;list-style:none;margin:0px;padding:0px;position:relative;text-align:inherit;text-decoration:none;white-space:pre-wrap;word-wrap:break-word;}
154+
.css-textHasAncestor-1jxf684{background-color:rgba(0,0,0,0.00);border:0 solid black;box-sizing:border-box;color:inherit;display:inline;font:inherit;list-style:none;margin:0px;padding:0px;position:relative;text-align:inherit;text-decoration:none;white-space:inherit;word-wrap:break-word;}
127155
.css-view-175oi2r{align-items:stretch;background-color:rgba(0,0,0,0.00);border:0 solid black;box-sizing:border-box;display:flex;flex-basis:auto;flex-direction:column;flex-shrink:0;list-style:none;margin:0px;min-height:0px;min-width:0px;padding:0px;position:relative;text-decoration:none;z-index:0;}
128156
[stylesheet-group=\\"2\\"]{}
129157
.r-borderWidth-1bee2fs{border-bottom-width:1234px;border-left-width:1234px;border-right-width:1234px;border-top-width:1234px;}
158+
.r-display-krxsd3{display:-webkit-box;}
130159
.r-display-xoduu5{display:inline-flex;}
131160
.r-flex-13awgt0{flex:1;}
161+
.r-overflow-1udh08x{overflow-x:hidden;overflow-y:hidden;}
132162
[stylesheet-group=\\"3\\"]{}
163+
.r-WebkitBoxOrient-8akbws{-webkit-box-orient:vertical;}
133164
.r-backgroundColor-aot4c7{background-color:rgba(128,0,128,1.00);}
134165
.r-bottom-1p0dtai{bottom:0px;}
166+
.r-cursor-1loqt21{cursor:pointer;}
135167
.r-left-1d2f490{left:0px;}
168+
.r-maxWidth-dnmrzs{max-width:100%;}
136169
.r-pointerEvents-105ug2t{pointer-events:auto!important;}
137170
.r-pointerEvents-12vffkv>*{pointer-events:auto;}
138171
.r-pointerEvents-12vffkv{pointer-events:none!important;}
@@ -141,7 +174,12 @@ describe('AppRegistry', () => {
141174
.r-pointerEvents-ah5dr5{pointer-events:auto!important;}
142175
.r-position-u8s1d{position:absolute;}
143176
.r-right-zchlnj{right:0px;}
144-
.r-top-ipm5af{top:0px;}"
177+
.r-textOverflow-1udbk01{text-overflow:ellipsis;}
178+
.r-top-ipm5af{top:0px;}
179+
.r-userSelect-1xnzce8{-moz-user-select:text;-webkit-user-select:text;user-select:text;}
180+
.r-userSelect-lrvibr{-moz-user-select:none;-webkit-user-select:none;user-select:none;}
181+
.r-whiteSpace-3s2u2q{white-space:nowrap;}
182+
.r-wordWrap-1iln25a{word-wrap:normal;}"
145183
`);
146184

147185
// Third render "RootComponent" again

packages/react-native-web/src/exports/Text/__tests__/__snapshots__/index-test.js.snap

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22

33
exports[`components/Text default 1`] = `
44
<div
5-
class="css-text-1rynq56"
5+
class="css-text-13q1o4w"
66
dir="auto"
77
/>
88
`;
99

1010
exports[`components/Text nested 1`] = `
1111
<div
12-
class="css-text-1rynq56"
12+
class="css-text-13q1o4w"
1313
dir="auto"
1414
>
1515
<span
16-
class="css-textHasAncestor-1qaijid"
16+
class="css-textHasAncestor-1jxf684"
1717
data-testid="child"
1818
/>
1919
</div>
@@ -22,44 +22,44 @@ exports[`components/Text nested 1`] = `
2222
exports[`components/Text prop "aria-label" value is set 1`] = `
2323
<div
2424
aria-label="accessibility label"
25-
class="css-text-1rynq56"
25+
class="css-text-13q1o4w"
2626
dir="auto"
2727
/>
2828
`;
2929

3030
exports[`components/Text prop "aria-labelledby" value is set 1`] = `
3131
<div
3232
aria-labelledby="123"
33-
class="css-text-1rynq56"
33+
class="css-text-13q1o4w"
3434
dir="auto"
3535
/>
3636
`;
3737

3838
exports[`components/Text prop "aria-live" value is set 1`] = `
3939
<div
4040
aria-live="polite"
41-
class="css-text-1rynq56"
41+
class="css-text-13q1o4w"
4242
dir="auto"
4343
/>
4444
`;
4545

4646
exports[`components/Text prop "dir" value is "ltr" 1`] = `
4747
<div
48-
class="css-text-1rynq56"
48+
class="css-text-13q1o4w"
4949
dir="ltr"
5050
/>
5151
`;
5252

5353
exports[`components/Text prop "dir" value is "rtl" 1`] = `
5454
<div
55-
class="css-text-1rynq56"
55+
class="css-text-13q1o4w"
5656
dir="rtl"
5757
/>
5858
`;
5959

6060
exports[`components/Text prop "href" href with accessibilityRole 1`] = `
6161
<a
62-
class="css-text-1rynq56"
62+
class="css-text-13q1o4w"
6363
dir="auto"
6464
href="https://example.com"
6565
role="presentation"
@@ -68,30 +68,30 @@ exports[`components/Text prop "href" href with accessibilityRole 1`] = `
6868

6969
exports[`components/Text prop "href" value is set 1`] = `
7070
<a
71-
class="css-text-1rynq56"
71+
class="css-text-13q1o4w"
7272
dir="auto"
7373
href="https://example.com"
7474
/>
7575
`;
7676

7777
exports[`components/Text prop "hrefAttrs" null values are excluded 1`] = `
7878
<a
79-
class="css-text-1rynq56"
79+
class="css-text-13q1o4w"
8080
dir="auto"
8181
href="https://example.com"
8282
/>
8383
`;
8484

8585
exports[`components/Text prop "hrefAttrs" requires "href" 1`] = `
8686
<div
87-
class="css-text-1rynq56"
87+
class="css-text-13q1o4w"
8888
dir="auto"
8989
/>
9090
`;
9191

9292
exports[`components/Text prop "hrefAttrs" target variant is set 1`] = `
9393
<a
94-
class="css-text-1rynq56"
94+
class="css-text-13q1o4w"
9595
dir="auto"
9696
href="https://example.com"
9797
target="_blank"
@@ -100,7 +100,7 @@ exports[`components/Text prop "hrefAttrs" target variant is set 1`] = `
100100

101101
exports[`components/Text prop "hrefAttrs" value is set 1`] = `
102102
<a
103-
class="css-text-1rynq56"
103+
class="css-text-13q1o4w"
104104
dir="auto"
105105
download="filename.jpg"
106106
href="https://example.com"
@@ -111,68 +111,68 @@ exports[`components/Text prop "hrefAttrs" value is set 1`] = `
111111

112112
exports[`components/Text prop "lang" ar 1`] = `
113113
<div
114-
class="css-text-1rynq56"
114+
class="css-text-13q1o4w"
115115
dir="rtl"
116116
lang="ar"
117117
/>
118118
`;
119119

120120
exports[`components/Text prop "lang" fr 1`] = `
121121
<div
122-
class="css-text-1rynq56"
122+
class="css-text-13q1o4w"
123123
dir="ltr"
124124
lang="fr"
125125
/>
126126
`;
127127

128128
exports[`components/Text prop "lang" undefined 1`] = `
129129
<div
130-
class="css-text-1rynq56"
130+
class="css-text-13q1o4w"
131131
dir="auto"
132132
/>
133133
`;
134134

135135
exports[`components/Text prop "lang" with dir 1`] = `
136136
<div
137-
class="css-text-1rynq56"
137+
class="css-text-13q1o4w"
138138
dir="ltr"
139139
lang="ar"
140140
/>
141141
`;
142142

143143
exports[`components/Text prop "nativeID" value is set 1`] = `
144144
<div
145-
class="css-text-1rynq56"
145+
class="css-text-13q1o4w"
146146
dir="auto"
147147
id="nativeID"
148148
/>
149149
`;
150150

151151
exports[`components/Text prop "numberOfLines" value is set 1`] = `
152152
<div
153-
class="css-text-1rynq56 r-WebkitBoxOrient-8akbws r-display-krxsd3 r-maxWidth-dnmrzs r-overflow-1udh08x r-textOverflow-1udbk01"
153+
class="css-text-13q1o4w r-WebkitBoxOrient-8akbws r-display-krxsd3 r-maxWidth-dnmrzs r-overflow-1udh08x r-textOverflow-1udbk01"
154154
dir="auto"
155155
/>
156156
`;
157157

158158
exports[`components/Text prop "numberOfLines" value is set to one 1`] = `
159159
<div
160-
class="css-text-1rynq56 r-maxWidth-dnmrzs r-overflow-1udh08x r-textOverflow-1udbk01 r-whiteSpace-3s2u2q r-wordWrap-1iln25a"
160+
class="css-text-13q1o4w r-maxWidth-dnmrzs r-overflow-1udh08x r-textOverflow-1udbk01 r-whiteSpace-3s2u2q r-wordWrap-1iln25a"
161161
dir="auto"
162162
/>
163163
`;
164164

165165
exports[`components/Text prop "role" value alters HTML element 1`] = `
166166
<article
167-
class="css-text-1rynq56"
167+
class="css-text-13q1o4w"
168168
dir="auto"
169169
role="article"
170170
/>
171171
`;
172172

173173
exports[`components/Text prop "role" value is "button" 1`] = `
174174
<button
175-
class="css-text-1rynq56"
175+
class="css-text-13q1o4w"
176176
dir="auto"
177177
role="button"
178178
type="button"
@@ -181,37 +181,37 @@ exports[`components/Text prop "role" value is "button" 1`] = `
181181

182182
exports[`components/Text prop "role" value is set 1`] = `
183183
<div
184-
class="css-text-1rynq56"
184+
class="css-text-13q1o4w"
185185
dir="auto"
186186
role="presentation"
187187
/>
188188
`;
189189

190190
exports[`components/Text prop "selectable" value of false 1`] = `
191191
<div
192-
class="css-text-1rynq56 r-userSelect-lrvibr"
192+
class="css-text-13q1o4w r-userSelect-lrvibr"
193193
dir="auto"
194194
/>
195195
`;
196196

197197
exports[`components/Text prop "selectable" value of true 1`] = `
198198
<div
199-
class="css-text-1rynq56 r-userSelect-1xnzce8"
199+
class="css-text-13q1o4w r-userSelect-1xnzce8"
200200
dir="auto"
201201
/>
202202
`;
203203

204204
exports[`components/Text prop "style" value is set 1`] = `
205205
<div
206-
class="css-text-1rynq56"
206+
class="css-text-13q1o4w"
207207
dir="auto"
208208
style="border-top-width: 5px; border-right-width: 5px; border-bottom-width: 5px; border-left-width: 5px;"
209209
/>
210210
`;
211211

212212
exports[`components/Text prop "testID" value is set 1`] = `
213213
<div
214-
class="css-text-1rynq56"
214+
class="css-text-13q1o4w"
215215
data-testid="123"
216216
dir="auto"
217217
/>

packages/react-native-web/src/exports/Text/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ const textStyle = {
192192
listStyle: 'none',
193193
margin: 0,
194194
padding: 0,
195+
position: 'relative',
195196
textAlign: 'inherit',
196197
textDecoration: 'none',
197198
whiteSpace: 'pre-wrap',

0 commit comments

Comments
 (0)