[TextView] [CSS] text-transform support?
Hey,
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.
Not sure I understand the request - what do you want exactly that you can't do with plain JavaScript?
On Jul 22, 2015, at 11:22 AM, Mike Grabowski [email protected] wrote:
Hey, 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:
{'something'.toUpperCase()} but having universal apps in mind, basic support for upperCase and lowerCase would be nice. If the answer to my question is Yes - I am happy to add in this in a PR.— Reply to this email directly or view it on GitHub.
Well, just wondering what are the pros/cons of implementing textTransform so we don't have to use plain JS (it's mainly for the sake of CSS-like approach as I am happy with plain JS anyway). Not a real issue, feel free to close if no point in implementing.
Our general philosophy on RN is not to provide APIs unless they both provide clear value and can't be reasonably done otherwise. Since you can easily use JS to do this, I don't think we'll provide specific support for it. On Wed, Jul 22, 2015 at 1:10 PM Mike Grabowski [email protected] wrote:
Well, just wondering what are the pros/cons of implementing textTransform so we don't have to use plain JS (it's mainly for the sake of CSS-like approach as I am happy with plain JS anyway). Not a real issue, feel free to close if no point in implementing.
— Reply to this email directly or view it on GitHub https://github.com/facebook/react-native/issues/2088#issuecomment-123668794 .
Adding on to @sahrens' comment above, if anyone comes across some use cases where there is a significant benefit to doing this in a style rather than with JS, please post them here so we can consider!
+1 strongly in favor of keeping code in user space.
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> to CITY rather than City. 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:
<View { ...style('field') }>
<TextInput
{ ...style('input') }
/>
<Text { ...style('label') }>Address Line 1</Text>
</View>
<View { ...style('field') }>
<TextInput
{ ...style('input') }
/>
<Text { ...style('label') }>Address Line 2</Text>
</View>
<View { ...style('field') }>
<TextInput
{ ...style('input') }
/>
<Text { ...style('label') }>City</Text>
</View>
<View { ...style('field') }>
<TextInput
{ ...style('input') }
/>
<Text { ...style('label') }>State</Text>
</View>
<View { ...style('field') }>
<TextInput
{ ...style('input') }
/>
<Text { ...style('label') }>Zipcode</Text>
</View>
And the same code modified for small caps:
<View { ...style('field') }>
<TextInput
{ ...style('input') }
/>
<Text { ...style('label.upper') }>{'Address Line 1'.toUpperCase()}</Text>
</View>
<View { ...style('field') }>
<TextInput
{ ...style('input') }
/>
<Text { ...style('label.upper') }>{'Address Line 2'.toUpperCase()}</Text>
</View>
<View { ...style('field') }>
<TextInput
{ ...style('input') }
/>
<Text { ...style('label.upper') }>{'City'.toUpperCase()}</Text>
</View>
<View { ...style('field') }>
<TextInput
{ ...style('input') }
/>
<Text { ...style('label.upper') }>{'State'.toUpperCase()}</Text>
</View>
<View { ...style('field') }>
<TextInput
{ ...style('input') }
/>
<Text { ...style('label.upper') }>{'Zipcode'.toUpperCase()}</Text>
</View>
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.
Another option is to wrap the Text component with one that adds the capabilities that you want, so then if you have the uppercase prop set on it, it will toUpperCase() everything. Can you create an issue on ProductPains that includes the great description of the problem that you just stated @jonlong?
@brentvatne sure thing — done: https://productpains.com/post/react-native/texttransform-should-be-available-in-stylesheet/
+1 I really need this on a specific app that uses it a lot. Thanks!
I'm in a situation where I can't access the Text tags directly that I want to put uppercase because I'm dynamically generating them - thus, applying conditional JS is much harder than just passing in styles.
+1 for me as well. I am a designer which likes to develop UI's when I get the chance. Unfortunately, my Javascript skills are not great, yet. Having a more CSS centric approach to building UI's would really help me. Granted I should probably just learn Javascript and be done with it. However, I am sure there are others like me which like to code UI's but have not reached the level where they can use Javascript as an alternative. My 2 cents.
+1 it's clearly a style concern. it was a concern on the web and now on mobile. I wouldn't want to worry about conditionally upper-casing text of a button component every time I use it but rather specify its style exactly like color or font-size, especially when I have to support two different style for the same component, each one with different text-transform style (Android vs iOs)
+1
+1
+1
+1
+1
the advantage of css "class" is to not duplicate codes.
I strongly think we need "whole supports" css system for RN.
+1