Skip to content

Commit

Permalink
[Autocomplete] Fix dynamic changes of multiple={boolean} (#21194)
Browse files Browse the repository at this point in the history
  • Loading branch information
wesleyZeng committed May 26, 2020
1 parent 94bb438 commit 718a837
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/material-ui/src/utils/useControlled.js
Expand Up @@ -27,7 +27,7 @@ export default function useControlled({ controlled, default: defaultProp, name,
const { current: defaultValue } = React.useRef(defaultProp);

React.useEffect(() => {
if (defaultValue !== defaultProp) {
if (!isControlled && defaultValue !== defaultProp) {
console.error(
[
`Material-UI: A component is changing the default ${state} state of an uncontrolled ${name} after being initialized. ` +
Expand Down
11 changes: 11 additions & 0 deletions packages/material-ui/src/utils/useControlled.test.js
Expand Up @@ -83,4 +83,15 @@ describe('useControlled', () => {
'Material-UI: A component is changing the default value state of an uncontrolled TestComponent after being initialized.',
);
});

it('should not raise a warning if changing the defaultValue when controlled', () => {
const { setProps } = render(
<TestComponent value={1} defaultValue={0}>
{() => null}
</TestComponent>,
);
expect(consoleErrorMock.callCount()).to.equal(0);
setProps({ defaultValue: 1 });
expect(consoleErrorMock.callCount()).to.equal(0);
});
});

0 comments on commit 718a837

Please sign in to comment.