-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
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 (tags) does not not allow enter the same value more then once #18976
Comments
@adica What's your use case? |
not sure if I need the double tag, but definitely it should not delete the previous one.. |
Ok, it should probably clear the input and keep the existing values. |
@oliviertassinari I'm in doubt if this should happen only with custom values or also when the user clicks in an option which matches its search but already added. |
@oliviertassinari yep, this behaviour would be nice to have, I guess. Any updates regarding this issue? |
@adica What do you think of this patch? Do you want to submit a pull request :)? diff --git a/packages/material-ui-lab/src/useAutocomplete/useAutocomplete.js b/packages/material-ui-lab/src/useAutocomplete/useAutocomplete.js
index de0bfd292..7eabcb117 100644
--- a/packages/material-ui-lab/src/useAutocomplete/useAutocomplete.js
+++ b/packages/material-ui-lab/src/useAutocomplete/useAutocomplete.js
@@ -430,7 +430,7 @@ export default function useAutocomplete(props) {
setValue(newValue);
};
- const selectNewValue = (event, newValue) => {
+ const selectNewValue = (event, newValue, origin = 'option') => {
if (multiple) {
const item = newValue;
newValue = Array.isArray(value) ? [...value] : [];
@@ -439,7 +439,7 @@ export default function useAutocomplete(props) {
if (itemIndex === -1) {
newValue.push(item);
- } else {
+ } else if (origin !== 'freeSolo') {
newValue.splice(itemIndex, 1);
}
}
@@ -597,7 +597,7 @@ export default function useAutocomplete(props) {
// Allow people to add new values before they submit the form.
event.preventDefault();
}
- selectNewValue(event, inputValue);
+ selectNewValue(event, inputValue, 'freeSolo');
}
break;
case 'Escape':
@m4theushw I would rather encourage the
@gmltA could you be more specific? |
@oliviertassinari I meant this one for
|
@gmltA Cool, so we have found a consensus. |
@oliviertassinari pushing #19064 will give more flexibility. |
@m4theushw I agree. Still, shouldn't we implement both? |
@oliviertassinari Yes, I'll give some time and see if any author wants to contribute. If not I can help. |
@m4theushw Awesome. Thank you for the help on this component :). |
In autocomplete with multiple values (tags), on the
feeSolo
version, if you try to insert the same value twice, the first value is deleted.Current Behavior 😯
If I add tag and try to add it again it deletes the first one.
Expected Behavior 🤔
It should allow insert the same value many times.
Steps to Reproduce 🕹
https://material-ui.com/components/autocomplete/#multiple-values
in the
freeSolo
version:aa
aa
againaa
tagThe text was updated successfully, but these errors were encountered: