You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 12054e3
Browse filesBrowse the repository at this point in the historyBrowse files
fix(text): inherit parent styles in nested Text (#5040)
* fix(text): keep the parent variant when nesting Text
* docs(text): add nested Text example cases
* fix(text): inherit the parent style in nested Text
A nested Text or AnimatedText without a variant applied its fallback font unconditionally, overriding the font, weight, letter spacing and color it should have inherited from the enclosing text. React Native inherits these, so a nested one now declares only its own style. The shared context lives in its own module to keep the Text and AnimatedText imports one-directional. Fixes#4351.
* docs(text): show inherited weight in the nested Text example
* Update src/components/__tests__/Typography/Text.test.tsx
Co-authored-by: Mikita Kliushun <nikita.kliushun@gmail.com>
* Update src/components/Typography/Text.tsx
Co-authored-by: Mikita Kliushun <nikita.kliushun@gmail.com>
* perf(text): skip the nesting context when children cannot contain text
* refactor(text): trim comments and simplify the nested children check
Keep a comment only where it helps, in one line, and drop the context
sentence that the nested font change made wrong.
Check every child for an element instead of copying React Native's
three-child cutoff. The provider is still skipped when the children
are only strings or numbers.
* test(text): consolidate the nested Text tests
Assert that a nested Text sets no color of its own and inherits the
parent's, and cover a Text nested through another component. Fold the
test that did not check what its title said into the one above it,
drop the duplicate of the default font test, and replace the three
AnimatedText tests with one.
* fix(text): respect the theme prop of a nested Text
A nested Text or AnimatedText with its own theme renders like a
top-level one again, with the theme's color, as it does on main.
* fix(text): keep the parent color in a nested Text with a variant
A nested Text or AnimatedText with a variant now applies only the
variant font, so it no longer resets the color to onSurface. A Text
with a variant inside a contained Button keeps the button's label
color.
* docs(text): show the nested Text examples after the custom variant
The nested section was inserted above the Custom Variant sample, which
made that sample read as one of the nested cases.
* docs(migration): describe nested Text inheritance
---------
Co-authored-by: Mikita Kliushun <nikita.kliushun@gmail.com>
Copy file name to clipboardExpand all lines: docs/6.x/docs/guides/migration.md
+6Lines changed: 6 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -546,6 +546,12 @@ An accordion with a `left` element now indents only its `List.Item` children. An
546
546
547
547
`theme` set on `List.Accordion` no longer reaches its children either. Pass it to the child that needs the override.
548
548
549
+
### Text
550
+
551
+
A `Text` nested in another `Text` now inherits the parent's font and color, as React Native's own `Text` does. In 5.x it reset them to the theme's default font and `onSurface`, so a `Text` with a variant inside a contained `Button` lost the button's label color, and a plain `Text` inside a `Chip` lost the chip's font. A nested `Text` with a `variant` still takes that variant's font, and its own `style` still wins over the parent's. To give a nested `Text` its own color, set `color` in its `style`, or pass it a `theme`, which makes it render like a top-level `Text`.
552
+
553
+
On iOS and Android, a `Text` inside a `View` inside a `Text` renders in the platform's default color, so set its `color` or pass it a `theme`.
554
+
549
555
### ToggleButton
550
556
551
557
`ToggleButton`, `ToggleButton.Group` and `ToggleButton.Row` were removed. For an
0 commit comments