Skip to content
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] Fix keep listbox open on left/right keys when inputValue is not empty #31407

Merged
merged 3 commits into from
May 9, 2022

Conversation

alisasanib
Copy link
Contributor

@alisasanib alisasanib commented Mar 10, 2022

Fixes: #31083

Code sandbox demo

Problem:
The list is closed upon clicking the ArrowLeft and ArrowRight key buttons if the user wants to move the cursor on the input value text.

Solution:
Adding a condition before closing the listbox, in order to check if the input value is not empty or not.

@mui-bot
Copy link

mui-bot commented Mar 10, 2022

Details of bundle changes

Generated by 🚫 dangerJS against 8ce483d

@danilo-leal danilo-leal added the component: autocomplete This is the name of the generic UI component, not the React module! label Mar 11, 2022
@@ -474,6 +474,28 @@ describe('<Autocomplete />', () => {
expect(textbox).toHaveFocus();
});

it('should keep listbox open on pressing left or right keys when inputValue is not empty', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also add test that will test that the listbox is closed if the input value is empty?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes sure!

@@ -682,7 +682,9 @@ export default function useAutocomplete(props) {
return;
}

handleClose(event, 'toggleInput');
if (inputValue === '') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes looks good 👍

Copy link
Member

@mnajdova mnajdova left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @alisasanib for the contribution. Sorry it took me some time to get to it :)

@michaldudak michaldudak merged commit 7bd7ac4 into mui:master May 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: autocomplete This is the name of the generic UI component, not the React module!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Autocomplete] Multiple options closes the listbox on key left/right
5 participants