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 not respected for <Select.Item> on web #58

Open
bryanmylee opened this issue Feb 1, 2025 · 0 comments
Open

asChild not respected for <Select.Item> on web #58

bryanmylee opened this issue Feb 1, 2025 · 0 comments

Comments

@bryanmylee
Copy link
Contributor

On web, <Select.Item asChild> does nothing.

Why are we not passing asChild through on the Select.Item component for select.web? I just spent 30 minutes trying to figure out why Radix wasn't forwarding <Select.Item> to my custom <Button> component, only to see in the source code for @rn-primitives/packages/select/src/select.web.tsx:

const Item = React.forwardRef<ItemRef, ItemProps>(
  ({ asChild, closeOnPress = true, label, value, children, ...props }, ref) => {
    const { labelForValueRef } = useRootContext();
    labelForValueRef.current[value] = label;
    return (
      <ItemContext.Provider value={{ itemValue: value, label: label }}>
        <Slot.Pressable ref={ref} {...props}>
          <Select.Item textValue={label} value={value} disabled={props.disabled ?? undefined}>
            <>{children as React.ReactNode}</>
          </Select.Item>
        </Slot.Pressable>
      </ItemContext.Provider>
    );
  }
);

Is there a reason why we're passing <>{children}</> as children and not forwarding asChild? If this is an oversight, I'm happy to open another PR for it.

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

1 participant