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
15.93k stars 833 forks source link

[Select] fix: disabled select when fieldset has `disabled` attr #3174

Open ojj1123 opened 1 month ago

ojj1123 commented 1 month ago

Description

close #2417

AS-IS

https://github.com/user-attachments/assets/eb77a71e-9848-4070-8e6f-5f6ba98d092b

TO-BE

https://github.com/user-attachments/assets/632ab57c-4b5c-44dd-9a9a-19eb693918c4

RndUsername commented 1 month ago

Will this react to changes? For example if the fieldset is dynamically disabled?

ojj1123 commented 1 month ago

Will this react to changes? For example if the fieldset is dynamically disabled?

@RndUsername Yeah, It works well. This is because disabled state of fieldset is checked whenever triggering onPointerDown handler. FYI, HTML select tag works as pointerdown event is triggered using mouse. [mdn] <select>

export const Styled = () => {
  const [disabled, setDisabled] = React.useState(false);

  return (
    <div>
      <button type="button" onClick={() => setDisabled((prev) => !prev)}>
        {disabled ? 'enabled' : 'disabled'}
      </button>
      <div>
        <p>Radix `Select` component</p>
        <fieldset disabled={disabled}>
          {POSITIONS.map((position) => (
            <Label key={position}>
              Choose a number:
              <Select.Root defaultValue="two">
                ...
              </Select.Root>
            </Label>
          ))}
        </fieldset>
      </div>
    </div>
  );
};

https://github.com/user-attachments/assets/87e54158-ec68-4cc8-98d7-a32881739b5a