diff --git a/packages/material-ui-lab/src/Autocomplete/Autocomplete.test.js b/packages/material-ui-lab/src/Autocomplete/Autocomplete.test.js index b1bb46ccc4586a..4e1ec7fc71282f 100644 --- a/packages/material-ui-lab/src/Autocomplete/Autocomplete.test.js +++ b/packages/material-ui-lab/src/Autocomplete/Autocomplete.test.js @@ -456,6 +456,29 @@ describe('', () => { }); }); + describe('prop: clearOnEscape', () => { + it('should clear on escape', () => { + const handleChange = spy(); + render( + } + />, + ); + + fireEvent.keyDown(document.activeElement, { key: 'Escape' }); + fireEvent.keyDown(document.activeElement, { key: 'Escape' }); + + expect(handleChange.callCount).to.equal(1); + expect(handleChange.args[0][1]).to.deep.equal([]); + }); + }); + describe('when popup open', () => { it('closes the popup if Escape is pressed ', () => { const handleClose = spy(); diff --git a/packages/material-ui-lab/src/useAutocomplete/useAutocomplete.js b/packages/material-ui-lab/src/useAutocomplete/useAutocomplete.js index d98d1650945ef9..f5ece946397df5 100644 --- a/packages/material-ui-lab/src/useAutocomplete/useAutocomplete.js +++ b/packages/material-ui-lab/src/useAutocomplete/useAutocomplete.js @@ -649,7 +649,7 @@ export default function useAutocomplete(props) { // Avoid the Modal to handle the event. event.stopPropagation(); handleClose(event); - } else if (clearOnEscape && inputValue !== '') { + } else if (clearOnEscape && (inputValue !== '' || (multiple && value.length > 0))) { // Avoid Opera to exit fullscreen mode. event.preventDefault(); // Avoid the Modal to handle the event.