Border can't be applied to <Text> in nested <Text> component
See original GitHub issueDescription
I have a view like:
<Text>
<Text>text 1</Text>
<Text style={{borderWidth: 1, borderColor: '#4285f4'}}>text 2</Text>
</Text>
I want text 2
to have a border while the whole text in same line or wrap to next line if too long.
Expected result
Real result
The border didn’t show up.
I tried to use View
to wrap them instead of nested Text
, border works fine but it can’t be layouted the way we want.
Additional Information
- React Native version: 0.30
- Platform: Only tested on iOS
- Operating System: macOS
Issue Analytics
- State:
- Created 7 years ago
- Reactions:3
- Comments:20 (4 by maintainers)
Top Results From Across the Web
react native - How to add border to nested text component?
I tried to just add borderWidth and borderColor etc. They work by themselves but not in nested text component. <Text style={styles.text}> <Text> ...
Read more >Text Override doesn't work on nested variants with interactive ...
So this is what I have: A Toggle element variant with states for enabled, hover, and active states. I set the interaction on...
Read more >Richer styling options for nested <Text> | Voters - React Native
This makes it difficult to style rich text applications where tokens, links, mentions, symbols, or inline sprites need to be styled inside. <Text>....
Read more >How to Add Text in Borders Using Basic HTML Elements
Only the top border of each <fieldset> element is kept visible while the remaining edges are transparent since the text of the <legend>...
Read more >Rich text element overview - Webflow University
Please note that styling these nested tags will affect elements in any RTE with the same class applied, or any child elements of...
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 FreeTop 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
Top GitHub Comments
@tbergq my solution (which is not ideal, but works for small amounts of text) is to tokenize every word; I.e.
.split(' ')
and then wrap each word in aView
. Now you can use flex-wrap to display your sentence plus any icons etc.Please note that this will create a lot of extra Views, which may cause perf issues; but in your use case it should be fine. You could always convert your view to an image if needed.
Any fix for this yet?