You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm adding getOptionDisabled to useAutoComplete() hook but the disabled options are selectable. The only apparent change is the addition of aria-disabled="true" attribute to the option in the DOM.
it's either:
My misconfiguration
Documentation request to state that this behavior should be implemented by the user
An internal change to avoid triggering onChange for disabled options
Steps:
Create a custom autocomplete component using useAutocomplete hook
Set the property getOptionDisabled in the hooks options to a function that returns true for all options
Run the app and select an option
The custom autocomplete is being closed and the disabled option is selected
import{useAutocomplete}from'@mui/base/useAutocomplete';exportdefaultfunctionUseAutocomplete(){const{
getRootProps,
getInputLabelProps,
getInputProps,
getListboxProps,
getOptionProps,
groupedOptions,}=useAutocomplete({id: 'use-autocomplete-demo',options: top4Films,getOptionLabel: (option)=>option.title,getOptionDisabled: ()=>true,});return(<div><div{...getRootProps()}><label{...getInputLabelProps()}>useAutocomplete</label><input{...getInputProps()}/></div>{groupedOptions.length>0 ? (<ul{...getListboxProps()}>{(groupedOptionsastypeoftop4Films).map((option,index)=>{const{ key, ...optionProps}=getOptionProps({ option, index });return(<likey={key}{...optionProps}>{option.title}</li>);})}</ul>) : null}</div>);}consttop4Films=[{title: 'The Shawshank Redemption',year: 1994},{title: 'The Godfather',year: 1972},{title: 'The Godfather: Part II',year: 1974},{title: 'The Dark Knight',year: 2008,},];
Documentation request to state that this behavior should be implemented by the user.
Yes, you have to implement this yourself since you are using the headlessuseAutocomplete hook. The headless word is already mentioned in the documentation here.
This issue has been closed. If you have a similar problem but not exactly the same, please open a new issue.
Now, if you have additional information related to this issue or things that could help future readers, feel free to leave a comment.
Note
We value your feedback @yotam-faye! How was your experience with our support team?
If you could spare a moment, we'd love to hear your thoughts in this brief Support Satisfaction survey. Your insights help us improve!
Steps to reproduce
A reproducible demo (based on useAutocomplete section from the docs:
https://stackblitz.com/edit/react-yunupe?file=Demo.tsx
I'm adding
getOptionDisabled
touseAutoComplete()
hook but the disabled options are selectable. The only apparent change is the addition ofaria-disabled="true"
attribute to the option in the DOM.it's either:
onChange
for disabled optionsSteps:
useAutocomplete
hookgetOptionDisabled
in the hooks options to a function that returnstrue
for all optionsCurrent behavior
No response
Expected behavior
No response
Context
No response
Your environment
npx @mui/envinfo
Search keywords: useAutocomplete autocomplete
The text was updated successfully, but these errors were encountered: