question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Nested <Text> clicks

See original GitHub issue

Hey.

I want to render some hypertext, e.g

var hypertext = 'this is <a href="http://facebook.com">facebook.com</a> link';

I tried programmatically splitting into

<Text>
  <Text>this is </Text>
  <Text onPress={this.onLinkPress} style={{color: '#0000ff'}}>facebook.com</Text>
  <Text> link</Text>
</Text>

but obviously onPress wouldn’t work, because nested text is transformed.

  1. Should a message be thrown if onPress is being set on the nested text?
  2. Is there any good way to get a click handler on the link?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

23reactions
breadadamscommented, Oct 28, 2016

I know this is an old issue, but stumbled across it today after getting an error:

views nested within a <Text> must have a width and height

I got this from trying to insert a <TouchableOpacity> inside a text component. Like @brentvatne suggested.

For me, the correct solution was a mix of your two answers:

<Text>
  <Text>{`This is `}</Text>
    <Text
        style={{color: '#0000ff'}}
        onPress={() => { AlertIOS.alert('hi!') }}>
        {`facebook.com`}
     </Text>
  <Text>{` link`}</Text>
</Text>
0reactions
agentcoopercommented, Apr 27, 2015

Ok, thanks everyone, this actually works fine, I was just passing wrong this 😩 Made a small module as a result https://github.com/agentcooper/react-native-hypertext

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why are 2 clicks necessary to edit a text field which is placed ...
When you click the first time the cell is editable and you are alreadyediting the cell. The coach of course does not know...
Read more >
How to click a div with certain text in a nested div using cypress?
I'd like to click on the div with the class box containing the <a>link2</a> tag. I have tried this : cy.get(`.main>div`).contains('link2').
Read more >
Conquer nested elements clicks tracking in GTM - Medium
Conquer nested elements clicks tracking in GTM ... Usually, analytics events/hits are tied to some element's click based on ... Text to speech....
Read more >
Format lists in Keynote on Mac - Apple Support
Select the text you want to format. In the Format sidebar, click the Text tab, then click the Style button near the top...
Read more >
Add bullets or numbers to text - Microsoft Support
Nested lists (you can press Tab or click Increase List Level Increase Indent button to create the same effect, but a new indented...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found