Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Autocomplete] Fix dynamic changes of multiple={boolean} #21194

Merged
merged 4 commits into from May 26, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
7 changes: 7 additions & 0 deletions packages/material-ui/src/utils/useControlled.test.js
Expand Up @@ -83,4 +83,11 @@ 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={[]} defaultValue={[]}>{() => null}</TestComponent>);
expect(consoleErrorMock.callCount()).to.equal(0);
setProps({ value: null, defaultValue: null });
oliviertassinari marked this conversation as resolved.
Show resolved Hide resolved
oliviertassinari marked this conversation as resolved.
Show resolved Hide resolved
expect(consoleErrorMock.callCount()).to.equal(0);
});
});