react / react/react-native

Border can't be applied to nested <Text> components

Ouverte
#45,925 14 commentaires 2 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Needs: Triage :mag: Newer Patch Available
Langage dominant
C++
Étoiles
127k
Forks
25.3k
Merge moyen
1 j 23 h
PR mergées (30 j)
4

Description

Description

I'm rendering several Text components wrapped inside a parent Text component, like so:

<Text>
  <Text>text 1</Text>
  <Text style={{ borderWidth: 1, borderColor: 'red' }}>text 2</Text>
</Text>

I'm expecting "text 2" to have a red border, rendering inline along with "text 1". However, the border is not rendered.

If I change the container from Text to View, the border renders properly. However, there are scenarios where this is not feasible (e.g.: rendering inside a TextInput.

This issue was previously opened here and, arguably, wrongfully closed. The reason it was marked as closed was:

Nesting a Text component within a parent Text component is not supported.

However, the documentation clearly states the opposite:

Nested text

Both Android and iOS allow you to display formatted text by annotating ranges of a string with specific formatting like bold or colored text (NSAttributedString on iOS, SpannableString on Android). In practice, this is very tedious. For React Native, we decided to use web paradigm for this where you can nest text to achieve the same effect.

Steps to reproduce

Nest one Text element inside another, applying a border width/color to the nested element.

<Text>
  <Text>text 1</Text>
  <Text style={{ borderWidth: 1, borderColor: 'red' }}>text 2</Text>
</Text>
React Native Version

0.74.3

Affected Platforms

Runtime - Android, Runtime - iOS

Output of npx react-native info
System:
  OS: macOS 14.4.1
  CPU: (8) arm64 Apple M1
  Memory: 72.53 MB / 16.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 22.5.1
    path: /opt/homebrew/bin/node
  Yarn:
    version: 1.22.19
    path: /opt/homebrew/bin/yarn
  npm:
    version: 10.8.2
    path: /opt/homebrew/bin/npm
  Watchman: Not Found
Managers:
  CocoaPods: Not Found
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.5
      - iOS 17.5
      - macOS 14.5
      - tvOS 17.5
      - visionOS 1.2
      - watchOS 10.5
  Android SDK: Not Found
IDEs:
  Android Studio: 2023.1 AI-231.9392.1.2311.11330709
  Xcode:
    version: 15.4/15F31d
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 22.0.1
    path: /opt/homebrew/opt/openjdk/bin/javac
  Ruby:
    version: 3.3.3
    path: /Users/mhuggins/.rvm/rubies/ruby-3.3.3/bin/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.74.3
    wanted: 0.74.3
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: Not found
  newArchEnabled: Not found
iOS:
  hermesEnabled: Not found
  newArchEnabled: Not found


### Stacktrace or Logs

```text
N/A
Reproducer

https://snack.expo.dev/@huggie/nested-text-border-bug

Screenshots and Videos

No response

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez par le reproducteur Expo Snack lié et la documentation React Native sur le texte imbriqué, puis suivez la manière dont les styles de Text imbriqué sont gérés sur Android et iOS. Reproduisez le cas décrit dans l’issue et vérifiez qu’un Text imbriqué avec borderWidth et borderColor rend sa bordure inline à l’intérieur d’un Text parent sans perturber le comportement existant du texte imbriqué.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
react-native
Domaine
mobile
Type d'issue
Bug
Difficulté
4/5
Temps estimé
3-5 jours
Activité
Calme
Clarté
Plutôt claire
Accessibilité débutants
44/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.