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

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ojj1123
Copy link

@ojj1123 ojj1123 commented Oct 10, 2024

Description

close #2417

  • When there is disabled fieldset, Select component does not be disabled.
  • This is because Select.Trigger has onPointerDown handler and even if button is disabled, that handler can be triggered.
  • So I added the code that check if there is fieldset disabled.

AS-IS

2024-10-10.14.42.50.mov

TO-BE

2024-10-10.14.42.00.mov

@RndUsername
Copy link

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

@ojj1123
Copy link
Author

ojj1123 commented Oct 15, 2024

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>
  );
};
2024-10-15.22.16.05.mov

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.

[Select] Not inheriting disabled from parent fieldset
2 participants