adobe / react-spectrum

A collection of libraries and tools that help you build adaptive, accessible, and robust user experiences.
https://react-spectrum.adobe.com
Apache License 2.0
12.38k stars 1.08k forks source link

RAC ComboBox isReadOnly does not disallow selections when menuTrigger is set to focus #6679

Closed mwannewitz closed 1 month ago

mwannewitz commented 1 month ago

Provide a general summary of the issue here

The RAC ComboBox isReadOnly prop does not disallow selections from the combobox menu when menuTrigger is set to focus. With menuTrigger='input' the user cannot open the combobox menu and not select any of the options, nor can they change the input. With menuTrigger='focus' the input still cannot be changed, but the menu keeps opening on focus, and the user can select a different option.

๐Ÿค” Expected Behavior?

Even with menuTrigger='focus' the combobox menu should not open if isReadOnly is set OR the user should not be able to make a selection.

๐Ÿ˜ฏ Current Behavior

The combobox menu keeps opening on focus, the user can select a different option.

๐Ÿ’ Possible Solution

No response

๐Ÿ”ฆ Context

No response

๐Ÿ–ฅ๏ธ Steps to Reproduce

Sandbox: https://codesandbox.io/p/sandbox/gallant-wu-6xy5k2?file=%2Fsrc%2FApp.js Both comboboxes are set to isReadOnly. In the second one, you can still make a different selection.

Version

react-aria-components@1.2.1

What browsers are you seeing the problem on?

Firefox, Chrome, Safari, Microsoft Edge

If other, please specify.

No response

What operating system are you using?

macOS Sonoma 14.5

๐Ÿงข Your Company/Team

No response

๐Ÿ•ท Tracking Issue

No response

LFDanLu commented 1 month ago

Thanks for catching this! I think it makes sense to not open the menu on focus if isReadOnly is true even if menuTrigger="focus" is applied. https://github.com/adobe/react-spectrum/blob/81abb2185cb3a9c52a8feaf76a136c64852aea13/packages/%40react-stately/combobox/src/useComboBoxState.ts#L324 should probably be changed to if (menuTrigger === 'focus' && !props.isReadOnly) { to accomplish this