Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions packages/material-ui-lab/src/Autocomplete/Autocomplete.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -720,4 +720,26 @@ describe('<Autocomplete />', () => {
expect(options.length).to.equal(1);
});
});

describe('prop: freeSolo', () => {
it('pressing twice enter should not call onChange listener twice', () => {
const handleChange = spy();
const options = [{ name: 'foo' }];
render(
<Autocomplete
freeSolo
onChange={handleChange}
options={options}
getOptionLabel={option => option.name}
renderInput={params => <TextField {...params} autoFocus />}
/>,
);
fireEvent.keyDown(document.activeElement, { key: 'ArrowDown' });
fireEvent.keyDown(document.activeElement, { key: 'Enter' });
expect(handleChange.callCount).to.equal(1);
expect(handleChange.args[0][1]).to.deep.equal(options[0]);
fireEvent.keyDown(document.activeElement, { key: 'Enter' });
expect(handleChange.callCount).to.equal(1);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ export default function useAutocomplete(props) {
inputRef.current.value.length,
);
}
} else if (freeSolo && inputValue !== '') {
} else if (freeSolo && inputValueFilter !== '') {
selectNewValue(event, inputValue);
}
break;
Expand Down