Skip to content

Text in a flex row doesn't shrink below its longest word #2921

Closed

Description

@miniware9

Is there an existing issue for this?

  • I have searched the existing issues

Describe the issue

A Text that is a flex item of a row with flexShrink: 1 or flex: 1 can't
shrink below its longest unbroken word on web. An email address or a URL,
which has no space to wrap at, stays on one line, overflows the row and
pushes the row's other children out of it. On iOS and Android the same code
wraps the word.

Expected behavior

The Text shrinks to the space the row leaves it and wraps the word, as on
native. View already does this: its base style sets minWidth: 0, which
removes the minimum CSS gives a flex item, its min-content width
(https://www.w3.org/TR/css-flexbox-1/#min-size-auto). Text's base style
doesn't set it.

Steps to reproduce

  1. Clone the test case, run npm install, then npx expo start --web.
  2. Each of the three rows is 240px wide and holds a Text with an email
    address next to a 32px square. Under each row is the width onLayout
    reports for the Text.
  3. In Chrome 155, the rows styled flexShrink: 1 and flex: 1 report 392,
    and the square sits outside the row. The row styled
    flexShrink: 1, minWidth: 0 reports 198 and wraps.
  4. On an Android 17 emulator, all three rows report 198 and wrap.

react-native-web 0.21.4 (master at 3edc3e3 has the same Text styles),
React Native 0.88.0, Expo SDK 58.

Test case

https://github.com/miniware9/react-native-web-text-min-width

Additional comments

The closest is #760, the same
symptom, closed in 2018 without a test case. I'll open a pull request with a one-line fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions