-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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] freeSolo is not actually usable #18113
Comments
The onChange and value props for the freeSolo are meant to account for user confirmation (click / enter). The google place demo access the input value like this: We could add an
It's what the |
This demo is broken. Using onChange on the TextField is not sufficient to keep up with the current input of the field. I've modified that example with the debug output from my demo. You'll see that the clear button does not work correctly, it clears the field but the value the host gets from onChange is not cleared. It's hard to do in a demo because CodeSandbox doesn't have the right origin to make the demo work with the Google API. However using the DevTools on the demo page I can also confirm that clicking one of the autocomplete options also does not update inputValue. |
@dantman Interesting, it seems that the input onChange can be used to know when to query the API for a new value and that the Autocomplete onChange to know when the user selects a new value. What would you like to change and what problem would it solve? Thanks. |
Except that's not actually true, because pressing the clear button should have the same effect as "⌘+A, Delete", it's user input and should result in a new API value just like typing. You do make note of a valid use case. Wanting to re-fetch data/change value only for user input in the field (typing and clearing) but not when the field is updated via autoComplete or selection of auto-complete. Like with a location search where the full label and the text you'd search are completely disconnected and it would work strangely if you tried to search with the value you get back from autocomplete. However I believe this type of situation is the minority of How about this, we change onChange's behaviour in
Outside of
This will actually be an improvement for the use-case you describe because Alternatively since Then |
@dantman You are right, this even causes a bug where if you clear the input with the button and press the down arrow key, it shows the suggestions for the preview query:
Expected output: no popup, actual output: popup. We need to fix that. Regarding your suggestions:
However, to go back to the initial problem, what are you trying to implement that the current implement stops you from? I'm interested in this part:
Thank you! |
Honestly in another scenario I might agree, but IMHO that doesn't really fit with the scenario we have. For better or worse in React IMHO while Autocomplete with
Personally I have a video list page and I'm adding a tag filter input with autocomplete of popular tags to it. There are no other filters yet (or ever, not sure) and there is no "submit". Input is debounced and live-updates the video list. I don't want to wait for the input to be "committed" because typing a tag name without selecting from the list is a valid behaviour and there are no other fields that would encourage the user to blur the input triggering a "commit" of what they typed. If I waited for "commit" not only would it add an extra delay waiting for that user interaction, there's a fair chance a user may type out a tag and then sit there confused not realizing they need to click/tab out of the input before the video list will update. I'm currently working around the limitations by using the following, which IMHO I consider a really ugly hack. Personally I want to fix the issues in MUI Autocomplete so I can remove the hack, but I'm also thinking about the other use cases for Autocomplete that need fixing. <Autocomplete
freeSolo
options={tagsList}
loading={tagsLoading}
onChange={onTagInputChange}
value={tagInputValue}
renderInput={props => (
<TextField
{...props}
label="Tag (filter)"
variant="outlined"
fullWidth
inputProps={{
...props.inputProps,
onChange: e => {
onTagInputChange(e, e.target.value || null);
props.inputProps.onChange(e);
},
}}
/>
)}
/> |
@dantman Awesome, thank you for sharing the use case. It sounds like you implement a "search as you type" like experience. The @kennethmervin01 in #18169 raises a similar concern, he wants to be able to control the textbox value. In this context, what do you guys think if we add this API to the useAutocomplete.js (and Autocomplete.js). Would it solve your use cases? /**
* The input value.
*/
inputValue?: string;
/**
* Callback fired when the input value changes.
*/
onInputValueChange?: (event: React.ChangeEvent<{}>, value: any) => void; We might want to add a third reason argument in the future, but I think that we should wait to hear valid use cases for it. |
@oliviertassinari I am running into the same issue and that would solve it - thank you! Do you have any idea when this will be added? I am trying to avoid switching to a new library right now but we have tight deadlines coming up and this is required functionality, so I thought it was worth checking. :) |
@dallashuggins This issue is labeled "good first issue" as there is a clear resolution path. We tend not to work on such issues, for a matter of efficiency. What alternative did you consider? :) |
@oliviertassinari Super appreciate the quick response! Gotcha, understood. Originally I was going to use |
I solved this by using On Input seems to fire both after key press and after selecting an option from the List. const handleInputChange = (e: any, data: any) => { <Autocomplete |
I have an api but how can I use autocomplete with my api and the data changes every time I type something |
Current Behavior 😯
If you use an Autocomplete with
freeSolo
theonChange
is never fired, unless you click one one of the predefined autocomplete items or clear the field. So you can't actually use it like a search field, etc... because the component using it never gets the field's value.Additionally even if you type out one of the predefined items, onChange is not fired unless you actually click/select the autocomplete item. This is mildly strange for normal Autocomplete where it clears the text but feels completely broken when using
freeSolo
where the text is not cleared and you expect the value has changed.Expected Behavior 🤔
In
freeSolo
modeonChange
should fire on everyinput
key press like a normalTextField
does.Additionally, outside of
freeSolo
Autocomplete should probably fireonChange
when you type out one of the options and blur.Steps to Reproduce 🕹
Steps:
<Autocomplete freeSolo />
component like one of the demos in the documentationonChange
andvalue
connected to state to itContext 🔦
I wanted to use the Autocomplete to add a single tag filter to a videos list page. The tag can be arbitrary because I only plan to load the most common tags from the API.
Your Environment 🌎
The text was updated successfully, but these errors were encountered: