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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .yarn/versions/a4fe86bf.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
releases:
"@radix-ui/react-select": patch

declined:
- primitives
10 changes: 9 additions & 1 deletion packages/react/select/src/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,18 @@ const SelectTrigger = React.forwardRef<SelectTriggerElement, SelectTriggerProps>
target.releasePointerCapture(event.pointerId);
}

const fieldset = target.closest('fieldset');
const fieldsetDisabled = fieldset ? fieldset.disabled : false;

// only call handler if it's the left button (mousedown gets triggered by all mouse buttons)
// but not when the control key is pressed (avoiding MacOS right click); also not for touch
// devices because that would open the menu on scroll. (pen devices behave as touch on iOS).
if (event.button === 0 && event.ctrlKey === false && event.pointerType === 'mouse') {
if (
event.button === 0 &&
event.ctrlKey === false &&
event.pointerType === 'mouse' &&
!fieldsetDisabled
) {
handleOpen(event);
// prevent trigger from stealing focus from the active item after opening.
event.preventDefault();
Expand Down