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

Nested Text components do not inherit style #4351

Open
joebochill opened this issue Mar 21, 2024 · 1 comment
Open

Nested Text components do not inherit style #4351

joebochill opened this issue Mar 21, 2024 · 1 comment
Labels

Comments

@joebochill
Copy link

Current behaviour

When nesting Text components, the child component does not inherit the style of the parent element.

Expected behaviour

I would expect the styles to be inherited and overridden by the child component instead of simply overridden. The Text component from react-native exhibits this behavior.

How to reproduce?

Nest a Text component inside another Text component and apply styles to both (e.g., color on one and fontWeight on the other). Note the nested component ignores the styles set on the parent component.

https://snack.expo.dev/lfm3PI-XWFR_YP56qwbn7

Preview

image

What have you tried so far?

Replacing the nested Text element with the react-native version (instead of RNP) fixes the inheritance, but you lose the default styles from RNP that you may wish to preserve (e.g., if the nested Text is a different variant from the parent, you need to manually apply all of the variant styles to the nested element).

Your Environment

software version
ios 17.2
android 30
react-native 0.73.2
react-native-paper 4.9.2
node 18.17.1
yarn 1.22.19
expo sdk 50.0.0
@rayan1810
Copy link

As per my understanding, this is caused due to the default color applied from the theme to a NativeText internally. Ideally, it should be overridden by the parent text if that has any conflicting style passed in style prop.

The solution I'm proposing is to provide the Text component with its own context that can be read by the child Text component and merged with the default styling from the theme. Here's the PR with the suggested changes, It's still a WIP, hoping for a little review from the maintainers if this is aligned with them or not before completing it.

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

No branches or pull requests

2 participants