[TextView] [CSS] text-transform support?
See original GitHub issueHey,
Given recent updates to text-decoration
implementation, I was wondering if this would’ve been in scope of React Native? I know we can pretty easily do this:
<Text>{'something'.toUpperCase()}</Text>
but having universal apps in mind, basic support for upperCase
and lowerCase
would be nice.
<Text style={{textTransform: 'uppercase'}}>something</Text>
Depending on how Text is rendered, either basic NSString bindings below might be used or plain JS methods:
capitalize
- NSString -capitalizedStringuppercase
- NSString -uppercaseStringlowercase
- NSString -lowercaseString
If the answer to my question is Yes - I am happy to add in this in a PR.
Issue Analytics
- State:
- Created 8 years ago
- Reactions:98
- Comments:94 (10 by maintainers)
Top Results From Across the Web
text-transform - CSS: Cascading Style Sheets - MDN Web Docs
The text-transform CSS property specifies how to capitalize an element's text. It can be used to make text appear in all-uppercase or ...
Read more >How to set <Text> text to upper case in react native
Android textTransform support has been added in 0.59 version. It accepts one of these options: none; uppercase; lowercase; capitalize. The actual iOS commit, ......
Read more >TextStyle should support Text Transformation (ex. all caps) for ...
Most UI Designer see text transformations like all caps as part of the styling but Compose does not. Currently TextStyle doesn't provide any...
Read more >Text Style Props
Specifies font weight. The values 'normal' and 'bold' are supported for most fonts. Not all fonts have a variant for each of the...
Read more >UI & Styling | NativeScript
NativeScript supports percentage values for width , height and margin . ... CSS property text-transform ) - Sets the text transform individually for...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Just stumbled upon this thread from Google; I’d say that adding
textTransform
support is necessary to separate your concerns. As others have pointed out, you can do this in JS, however what’s the point in having a class full of styles and then having to use JS to force caps.Say a couple of months down the line you don’t wish to use caps any more then you’ve got to trawl through your app removing all the references to it. Having this as a style would alleviate that problem.
@brentvatne Just dropping in to echo @mikefrancis’s comments, which are right on the money in my experience.
Here’s a quick example from a project I’m working on. This is the same screen with two different design options — labels rendered in title case, or labels rendered in small caps.
There’s two things that make a
textTransform
property attractive to me in this case. The first is that I think there’s a semantic difference between setting the actual content of<Text>
toCITY
rather thanCity
. If preserving that semantic state is important, then I think this becomes a matter of style.The second is to @mikefrancis’s points around separation of concerns and maintainability. If it’s a matter of style, then it makes sense to manage it with CSS.
Here’s a sample of the JSX for both of those views:
Title Case:
And the same code modified for small caps:
In the second version, a simple design change requires a lot of updates to the template content itself. Even going the “Find and Replace” route would be pretty tricky.
I also find that in many scenarios, small caps tend to look better with a little bit of
letterSpacing
applied. In that case, I’d also end up modifying my styles too.IMO, it’s a lot of overhead for a common use case, and something that could go from all this to a single line in a stylesheet with
textTransform
support.