-
-
Notifications
You must be signed in to change notification settings - Fork 45
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
[Autocomplete] useAutocomplete hook disabled option can be clicked #44
Comments
@phiter Thanks for reporting this ~ I agree it's a little unintuitive 😅 When we use this hook to make the Material UI and Joy UI autocomplete components, we use Here's an example with just Base UI: https://codesandbox.io/s/https-github-com-mui-material-ui-issues-38620-77j4gk?file=/Demo.tsx @michaldudak Do you think preventing selecting a disabled option could be provided out of the box? |
@mj12albert I tried I ended up having to do this in my code 😬 {(groupedOptions as T[]).map((option, index) => {
const optionProps = getOptionProps({ option, index });
// Workaround until https://github.com/mui/base-ui/issues/44 is fixed
const isDisabled = autoCompleteOptions.getOptionDisabled(option);
return (
<AutocompleteOption
key={index}
{...optionProps}
onClick={isDisabled ? undefined : optionProps.onClick}
>
{option.name}
</AutocompleteOption>
);
})} I suppose it could be an option for the hook, like There is no handling in the code: |
Same |
Yes, I think it should work similarly to how Base UI's Select works (likely using the same primitives). |
Duplicates
Latest version
Steps to reproduce 🕹
Link to live example: https://codesandbox.io/s/compassionate-chatelet-qz92q4?file=/Demo.tsx
Steps:
Current behavior 😯
The disabled option can be clicked, even though if inspected, it has
aria-disabled="true"
attribute.Expected behavior 🤔
The option should not be clickable.
Context 🔦
I'm creating a custom Autocomplete input with the useAutocomplete hook, but this is failing on my tests.
Your environment 🌎
npx @mui/envinfo
The text was updated successfully, but these errors were encountered: