Skip to content

Commit

Permalink
[Autocomplete] Should not fire change until IME is confirmed (mui#19499)
Browse files Browse the repository at this point in the history
  • Loading branch information
teramotodaiki authored and EsoterikStare committed Feb 13, 2020
1 parent 84951e9 commit 3211168
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
18 changes: 18 additions & 0 deletions packages/material-ui-lab/src/Autocomplete/Autocomplete.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,24 @@ describe('<Autocomplete />', () => {
fireEvent.keyDown(document.activeElement, { key: 'Enter' });
expect(container.querySelectorAll('[class*="MuiChip-root"]')).to.have.length(3);
});

it('should not fire change event until the IME is confirmed', () => {
const handleChange = spy();
render(
<Autocomplete
freeSolo
onChange={handleChange}
renderInput={params => <TextField {...params} autoFocus />}
/>,
);
// Actual behavior when "あ" (Japanese) is entered on macOS/Safari with IME
fireEvent.change(document.activeElement, { target: { value: 'あ' } });
fireEvent.keyDown(document.activeElement, { key: 'Enter', keyCode: 229 });
expect(handleChange.callCount).to.equal(0);
fireEvent.keyDown(document.activeElement, { key: 'Enter', keyCode: 13 });
expect(handleChange.callCount).to.equal(1);
expect(handleChange.args[0][1]).to.equal('あ');
});
});

describe('prop: onInputChange', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,10 @@ export default function useAutocomplete(props) {
handleFocusTag(event, 'next');
break;
case 'Enter':
// Wait until IME is settled.
if (event.which === 229) {
break;
}
if (highlightedIndexRef.current !== -1 && popupOpen) {
// We don't want to validate the form.
event.preventDefault();
Expand Down

0 comments on commit 3211168

Please sign in to comment.