Skip to content

Commit

Permalink
necolas#2715 Override text-transform: capitalize behavior in Text com…
Browse files Browse the repository at this point in the history
…ponent to match with react-native
  • Loading branch information
Mak authored and Mak committed Sep 22, 2024
1 parent 54c14d6 commit e7b4d37
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions packages/react-native-web/src/exports/Text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ const Text: React.AbstractComponent<TextProps, HTMLElement & PlatformMethods> =
const componentDirection = props.dir || langDirection;
const writingDirection = componentDirection || contextDirection;

const capitalizeText = (text) => {
return text.toLowerCase().replace(/\b\w/g, (char) => char.toUpperCase());
};

const supportedProps = pickProps(rest);
supportedProps.dir = componentDirection;
// 'auto' by default allows browsers to infer writing direction (root elements only)
Expand All @@ -145,6 +149,15 @@ const Text: React.AbstractComponent<TextProps, HTMLElement & PlatformMethods> =
onPress && styles.pressable
];

if (props.style && props.style.textTransform === 'capitalize') {
supportedProps.children = React.Children.map(props.children, child => {
if (typeof child === 'string') {
return capitalizeText(child);
}
return child;
});
}

if (props.href != null) {
component = 'a';
if (hrefAttrs != null) {
Expand Down

0 comments on commit e7b4d37

Please sign in to comment.