Skip to content

Commit

Permalink
[Autocomplete] Fix popup open logic when non empty (#20732)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosvega91 committed Apr 24, 2020
1 parent fce0c1c commit c5ec920
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
44 changes: 44 additions & 0 deletions packages/material-ui-lab/src/Autocomplete/Autocomplete.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1119,6 +1119,50 @@ describe('<Autocomplete />', () => {
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(
<Autocomplete
onHighlightChange={handleChange}
options={['one']}
renderInput={(params) => <TextField {...params} />}
/>,
);
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(
<Autocomplete
value="one"
onHighlightChange={handleChange}
options={['one']}
renderInput={(params) => <TextField {...params} />}
/>,
);
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', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,7 @@ export default function useAutocomplete(props) {
};

const handleInputMouseDown = (event) => {
if (inputValue === '') {
if (inputValue === '' || !open) {
handlePopupIndicator(event);
}
};
Expand Down

0 comments on commit c5ec920

Please sign in to comment.