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

fix(shadcn): Select asChild prop is unsupported #5905

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

lime517
Copy link

@lime517 lime517 commented Nov 22, 2024

Summary of issue

Using the <SelectTrigger> component with the asChild prop results in the following error:

Error: React.Children.only expected to receive a single React element child.

This is due to the <ChevronDown> icon being included as second descendant of <SelectTrigger>, even when asChild is TRUE. asChild requires that there is only one descendant.

Solution

Conditionally render <ChevronDown> inside a fragment that includes {children} if props.asChild is not set. If props.asChild is set, then simply render {children}. There are no visual changes with this solution.

Notes

This is my first contribution to shadcn/ui - let me know if I'm missing any details! I could not find any existing issue reports for this.

Copy link

vercel bot commented Nov 22, 2024

Someone is attempting to deploy a commit to the shadcn-pro Team on Vercel.

A member of the Team first needs to authorize it.

@branxy
Copy link

branxy commented Nov 23, 2024

I'd like to mention there's a related issue on this in radix-ui repo: folks in the comments arrived at the same conclusion that the current solution should be to conditionally render the icon.

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

Successfully merging this pull request may close these issues.

2 participants