Skip to content

Commit 73a599a

Browse files
sclavijo93oliviertassinari
authored andcommitted
[Autocomplete] Only trigger onInputChange when the value changes (#18571)
1 parent 4fc3f45 commit 73a599a

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

packages/material-ui-lab/src/Autocomplete/Autocomplete.test.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -650,11 +650,10 @@ describe('<Autocomplete />', () => {
650650
const { getByRole } = render(<MyComponent />);
651651

652652
const textbox = getByRole('textbox');
653-
expect(handleChange.callCount).to.equal(1);
654-
expect(handleChange.args[0][0]).to.equal('');
653+
expect(handleChange.callCount).to.equal(0);
655654
fireEvent.change(textbox, { target: { value: 'a' } });
656-
expect(handleChange.callCount).to.equal(2);
657-
expect(handleChange.args[1][0]).to.equal('a');
655+
expect(handleChange.callCount).to.equal(1);
656+
expect(handleChange.args[0][0]).to.equal('a');
658657
expect(textbox.value).to.equal('');
659658
});
660659
});

packages/material-ui-lab/src/useAutocomplete/useAutocomplete.js

+8
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,10 @@ export default function useAutocomplete(props) {
210210
newInputValue = typeof optionLabel === 'string' ? optionLabel : '';
211211
}
212212

213+
if (inputValue === newInputValue) {
214+
return;
215+
}
216+
213217
setInputValue(newInputValue);
214218

215219
if (onInputChange) {
@@ -635,6 +639,10 @@ export default function useAutocomplete(props) {
635639
handleOpen(event);
636640
}
637641

642+
if (inputValue === newValue) {
643+
return;
644+
}
645+
638646
setInputValue(newValue);
639647

640648
if (onInputChange) {

0 commit comments

Comments
 (0)