Skip to content

Commit

Permalink
[Autocomplete] Only trigger onInputChange when the value changes (#18571
Browse files Browse the repository at this point in the history
)
  • Loading branch information
sclavijo93 authored and oliviertassinari committed Nov 26, 2019
1 parent 4fc3f45 commit 73a599a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -650,11 +650,10 @@ describe('<Autocomplete />', () => {
const { getByRole } = render(<MyComponent />);

const textbox = getByRole('textbox');
expect(handleChange.callCount).to.equal(1);
expect(handleChange.args[0][0]).to.equal('');
expect(handleChange.callCount).to.equal(0);
fireEvent.change(textbox, { target: { value: 'a' } });
expect(handleChange.callCount).to.equal(2);
expect(handleChange.args[1][0]).to.equal('a');
expect(handleChange.callCount).to.equal(1);
expect(handleChange.args[0][0]).to.equal('a');
expect(textbox.value).to.equal('');
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ export default function useAutocomplete(props) {
newInputValue = typeof optionLabel === 'string' ? optionLabel : '';
}

if (inputValue === newInputValue) {
return;
}

setInputValue(newInputValue);

if (onInputChange) {
Expand Down Expand Up @@ -635,6 +639,10 @@ export default function useAutocomplete(props) {
handleOpen(event);
}

if (inputValue === newValue) {
return;
}

setInputValue(newValue);

if (onInputChange) {
Expand Down

0 comments on commit 73a599a

Please sign in to comment.