Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#2715 Override text-transform: capitalize behavior in Text component … #2716

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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