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

StyleSheet: word-break property to wrap long continuous strings #760

Closed
joncursi opened this issue Jan 10, 2018 · 17 comments
Closed

StyleSheet: word-break property to wrap long continuous strings #760

joncursi opened this issue Jan 10, 2018 · 17 comments

Comments

@joncursi
Copy link

joncursi commented Jan 10, 2018

Do you want to request a feature or report a bug?

Both.

What is the current behavior?

I have a very long string that I need to wrap to multiple lines, but it looks like this CSS property is not supported (word-break: all?).

When this component is rendered on native, the text wraps as desired:

img_5200

When rendered on web, the text will not wrap to multiple lines, which causes the component to break out of the layout and create scrollbars.

Demo: https://cheddur-rgsymrxmda.now.sh/story/7NcMectnqEW4QivYj -> the cryptocurrency address.

If you shrink your viewport, you see:

screen_shot_2018-01-09_at_11_03_36_pm

  • Browser: all
  • React Native for Web (version): 0.1.16
  • React (version): 16.2.0
@necolas
Copy link
Owner

necolas commented Jan 11, 2018

You app doesn't load. Please can you create a simple test case from the glitch demo included in the issue template

@necolas necolas changed the title [CSS]: word-break property to wrap long continuous strings StyleSheet: word-break property to wrap long continuous strings Jan 11, 2018
@necolas
Copy link
Owner

necolas commented Jan 20, 2018

Going to close this if there's no update soon

@necolas
Copy link
Owner

necolas commented Jan 20, 2018

Please can you make a reduced test case on glitch

@necolas necolas closed this as completed Jan 22, 2018
@dmeehan1968
Copy link

In case its of help, as it seems related, I had problems with getting a deeply nested Text node wrapping correctly. I got it working on Native, but couldn't figure it out on web without a lot of head scratch. This comment details what worked for me.

facebook/react-native#1438 (comment)

@necolas
Copy link
Owner

necolas commented Feb 4, 2018

What's an example of code that produces the issue?

@export-mike
Copy link

@necolas it appears a single long string that doesn't have spaces causes this issue.

@necolas
Copy link
Owner

necolas commented Jan 11, 2019

I'm just asking for someone to provide a reduced test case on codesandbox, as is mentioned as being required in the issue template. Help me to help you.

@airandfingers
Copy link

Hi @necolas, I'm seeing this issue now, though I could just be using Flexbox incorrectly.

Here's a reduced case (I could reduce it a bit more, but this shows the Flexbox context I'm operating in): https://codesandbox.io/embed/7wlorrx3p1

@airandfingers
Copy link

Update: This SO question pointed me to the answer: flexShrink: 1 fixes this.

Fixed reduced case: https://codesandbox.io/embed/7wlorrx3p1

@redefinered
Copy link

@airandfingers that is not the issue. I think just by reading it is pretty easy to understand. It's the long words that does not break and goes off the screen.

@redefinered
Copy link

redefinered commented Apr 22, 2020

to replicate the issue put this component in render <Text>ldjahflkasdjhflakshjflaksjhdflakshdjflaksjhdfalksjdhflaskdfhjlaskdfjhaslkdfhjlaskjdfhlaskjhdfajsdhflaksjdhflaskdfhalskdfhj</Text>

@redefinered
Copy link

@necolas

@redefinered
Copy link

It's too easy to understand, our brains are just too complicated.

@jtomaszewski
Copy link

So word-break isn't supported in react-native-web at this moment at all? I'm sure it should be supported. That's the only way to wrap long words (like explained above), besides CSS hyphenation maybe. Why is this closed?

@jtomaszewski
Copy link

This issue should be reopen. There should be a way to specify word-break: break-word on the web platform. That's the only way to force long words to be broken on the web. (Unless you know a better cross-browser-platform way to do it, I'm happy to learn. flex-shrink won't do it).

Currently our workaround is a bit troublesome and goes like this:

  1. Add global <style> to our index.html with the following:
[word-break="break-word"] {
  word-break: break-word;
}
  1. In js code, using ref and setNativeProps add the [word-break="break-word"] attribute to the element like this:
  const viewRef = useRef<View>(null);
  useEffect(() => {
    if (Platform.OS !== "web" || !containerRef.current) return;
    viewRef.current.setNativeProps({ ["word-break"]: "break-word" });
  }, [viewRef]);

  return (
    <View ref={viewRef}>...</View>
  );

@nicolaslazzos
Copy link

Or you can simply add { wordBreak: "break-word" } to the View style.

@srinivasan-fh
Copy link

srinivasan-fh commented Jun 17, 2024

1.Add global <style> to our index.html with the following:

<style>
#work-break-my-text-view {
   word-break: break-word;
}
</style>
  1. Add testID in the View:
    <View testId='work-break-my-text-view'></View>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants