diff --git a/packages/material-ui-lab/src/Autocomplete/Autocomplete.test.js b/packages/material-ui-lab/src/Autocomplete/Autocomplete.test.js index b222c51665b0d6..a48b16f6e17c3f 100644 --- a/packages/material-ui-lab/src/Autocomplete/Autocomplete.test.js +++ b/packages/material-ui-lab/src/Autocomplete/Autocomplete.test.js @@ -1119,6 +1119,50 @@ describe('', () => { fireEvent.click(queryByTitle('Open')); expect(textbox).toHaveFocus(); }); + + it('should mantain list box open clicking on input when it is not empty', () => { + const handleChange = spy(); + const { getByRole, getAllByRole } = render( + } + />, + ); + const combobox = getByRole('combobox'); + const textbox = getByRole('textbox'); + + expect(combobox).to.have.attribute('aria-expanded', 'false'); + fireEvent.mouseDown(textbox); // Open listbox + expect(combobox).to.have.attribute('aria-expanded', 'true'); + const options = getAllByRole('option'); + fireEvent.click(options[0]); + expect(combobox).to.have.attribute('aria-expanded', 'false'); + fireEvent.mouseDown(textbox); // Open listbox + expect(combobox).to.have.attribute('aria-expanded', 'true'); + fireEvent.mouseDown(textbox); // Remain open listbox + expect(combobox).to.have.attribute('aria-expanded', 'true'); + }); + + it('should not toggle list box', () => { + const handleChange = spy(); + const { getByRole } = render( + } + />, + ); + const combobox = getByRole('combobox'); + const textbox = getByRole('textbox'); + + expect(combobox).to.have.attribute('aria-expanded', 'false'); + fireEvent.mouseDown(textbox); + expect(combobox).to.have.attribute('aria-expanded', 'true'); + fireEvent.mouseDown(textbox); + expect(combobox).to.have.attribute('aria-expanded', 'true'); + }); }); describe('controlled', () => { diff --git a/packages/material-ui-lab/src/useAutocomplete/useAutocomplete.js b/packages/material-ui-lab/src/useAutocomplete/useAutocomplete.js index 76a1fb32dc2a60..fdd530a7907cdf 100644 --- a/packages/material-ui-lab/src/useAutocomplete/useAutocomplete.js +++ b/packages/material-ui-lab/src/useAutocomplete/useAutocomplete.js @@ -860,7 +860,7 @@ export default function useAutocomplete(props) { }; const handleInputMouseDown = (event) => { - if (inputValue === '') { + if (inputValue === '' || !open) { handlePopupIndicator(event); } };