radix-ui / primitives

Radix Primitives is an open-source UI component library for building high-quality, accessible design systems and web apps. Maintained by @workos.
https://radix-ui.com/primitives
MIT License
14.84k stars 720 forks source link

[Select] Not inheriting `disabled` from parent fieldset #2417

Open piotrkulpinski opened 9 months ago

piotrkulpinski commented 9 months ago

Bug report

Hi, I just noticed a small, but important issue with Select Primitive. If you wrap it with a <fieldset disabled></fieldset> it'll not inherit the disabled attribute. This works like this with every other "form" primitive (radio group, switch, checkbox etc) so I'd also think it should be the same for Select.

Current Behavior

This works:

<Select.Root disabled>
  (...)
</Select.Root>

This doesn't:

<fieldset disabled>
  <Select.Root>
    (...)
  </Select.Root>
</fieldset>

Expected behavior

A select root to inherit disabled attribute from parent fieldset.

piotrkulpinski commented 9 months ago

I should also add, that the underlying element gets marked as disabled properly, but you still can open the dialog and select values.

javiaggomezz commented 9 months ago

You can use css to remove the pointer events when the object is disabled, im using tailwindcss but you can do it with vanilla as well

<RadixSelect.Trigger className='disabled:pointer-events-none'>

glocore commented 8 months ago

You can use css to remove the pointer events when the object is disabled, im using tailwindcss but you can do it with vanilla as well

<RadixSelect.Trigger className='disabled:pointer-events-none'>

BrendanC23 commented 3 months ago

I'm also running into this issue. I'm using Shadcn, which uses Radix's select implementation. One workaround is to keep track of whether the select is within a disabled fieldset or not. The disabled attribute can then be added to the button element, which will then behave as being properly disabled.

const ref = useRef<HTMLButtonElement>(null);
const isInDisabledFieldset = Boolean(ref.current?.closest("fieldset:disabled"));

return (
    <Select.Root>
        <Select.Trigger ref={ref} disabled={isInDisabledFieldset}>
        </Select.Trigger>
    </Select.Root>
);