-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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] Don't close the popup when Ctrl/Shift clicks #19654
Comments
I have seen a related request in select2/select2#5302 for range selection but there is low traction for it. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
It's useful to note that Select2 has implemented this many many years ago with the CTRL key (recently adding the meta key in select2/select2#5222). #19654 (comment) The ticket which was linked is for using SHIFT to select a range at once instead of a single one, which Select2 does not currently support. |
@kevin-brown Thanks for mentioning this! What do you think about this diff for the diff --git a/packages/material-ui-lab/src/useAutocomplete/useAutocomplete.js b/packages/material-ui-lab/src/useAutocomplete/useAutocomplete.js
index feea18c89f..a12ff69dc2 100644
--- a/packages/material-ui-lab/src/useAutocomplete/useAutocomplete.js
+++ b/packages/material-ui-lab/src/useAutocomplete/useAutocomplete.js
@@ -563,7 +563,7 @@ export default function useAutocomplete(props) {
resetInputValue(event, newValue);
handleValue(event, newValue, reason, { option });
- if (!disableCloseOnSelect) {
+ if (!disableCloseOnSelect && !event.ctrlKey && !event.metaKey) {
handleClose(event, reason);
} Do you want to work on a pull request? :) (we would also need new tests) Regarding the |
Hello! :) Can I work on a pull request for this? |
@montelius yes :) |
@oliviertassinari Nice, thanks! :) So this is the first time I'm working with Material-UI, and I'm a bit confused about how the unit tests are structured. What tests would be suitable to implement for this feature? Could you maybe refer me to unit tests of other components that are similar so that I could get an idea of what would be a good test case? Tried to find something myself but didn't manage, would be grateful for your help! |
@montelius You can find the tests in https://github.com/mui-org/material-ui/blob/next/packages/material-ui-lab/src/Autocomplete/Autocomplete.test.js. More details around tests in https://github.com/mui-org/material-ui/blob/next/CONTRIBUTING.md. |
@oliviertassinari Yes thanks, thought the tests should go in useAutocomplete.test.js but that makes sense, I'll create a PR soon! |
In an Autocomplete component that contains the
multiple
prop, it would be a great feature to have a ctrl click functionality. E.g. simply clicking with the mouse should select a single item. Only when ctrl+click is used the popup shouldn't close, allowing to select more options.The text was updated successfully, but these errors were encountered: