Skip to content

Commit e7b4d37

Browse files
MakMak
Mak
authored and
Mak
committed
necolas#2715 Override text-transform: capitalize behavior in Text component to match with react-native
1 parent 54c14d6 commit e7b4d37

File tree

1 file changed

+13
-0
lines changed
  • packages/react-native-web/src/exports/Text

1 file changed

+13
-0
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ const Text: React.AbstractComponent<TextProps, HTMLElement & PlatformMethods> =
121121
const componentDirection = props.dir || langDirection;
122122
const writingDirection = componentDirection || contextDirection;
123123

124+
const capitalizeText = (text) => {
125+
return text.toLowerCase().replace(/\b\w/g, (char) => char.toUpperCase());
126+
};
127+
124128
const supportedProps = pickProps(rest);
125129
supportedProps.dir = componentDirection;
126130
// 'auto' by default allows browsers to infer writing direction (root elements only)
@@ -145,6 +149,15 @@ const Text: React.AbstractComponent<TextProps, HTMLElement & PlatformMethods> =
145149
onPress && styles.pressable
146150
];
147151

152+
if (props.style && props.style.textTransform === 'capitalize') {
153+
supportedProps.children = React.Children.map(props.children, child => {
154+
if (typeof child === 'string') {
155+
return capitalizeText(child);
156+
}
157+
return child;
158+
});
159+
}
160+
148161
if (props.href != null) {
149162
component = 'a';
150163
if (hrefAttrs != null) {

0 commit comments

Comments
 (0)