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

asChild throws error when setting style on child component with array style for React Native Web #3107

Open
bryanmylee opened this issue Sep 6, 2024 · 1 comment

Comments

@bryanmylee
Copy link

Bug report

Current Behavior

In React Native Web, using @radix-ui/react-slot for asChild over a child component with array styles throws an error.

<Link href="/details" asChild>
  <Pressable style={[styles.button, dynamic.button]} />
</Link>

/// Failed to set an indexed property [0] on 'CSSStyleDeclaration': Indexed property setter is not supported.

Expected behavior

Styles should be forwarded properly onto an array style for React Native Web, since @radix-ui/react-slot is being used

Reproducible example

Expo Snack

Suggested solution

We should provide a separate export for React Native Web that would handle style merging differently given the availability of the array style syntax in React Native.

<Link href="/details" asChild style={{ color: 'white' }}>
  <Pressable style={{ backgroundColor: 'red' }} />
</Link>
/// becomes
<Pressable style={[{ color: 'white' }, { backgroundColor: 'red' }]} />

<Link href="/details" asChild style={{ color: 'white' }}>
  <Pressable style={[style1, style2]} />
</Link>
/// becomes
<Pressable style={[{ color: 'white' }, style1, style2]} />

Additional context

Expo Router has started using @radix-ui/react-slot for its Link component to support asChild.

Your environment

Software Name(s) Version
Radix Package(s) react-slot 1.0.1
React n/a 18.2.0
Browser Chrome 128.0.6613.113
Assistive tech n/a
Node n/a
npm/yarn npm 10.2.3
Operating System macOS Sonoma 14.5
@bryanmylee bryanmylee changed the title asChild fails to set style on child component with array style for React Native Web asChild throws error when setting style on child component with array style for React Native Web Sep 6, 2024
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

2 participants
@bryanmylee and others