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

DropdownToggleCheckbox causes React controlled-state warning when moving in or out of indeterminate state #4213

Closed
mturley opened this issue May 7, 2020 · 5 comments
Labels

Comments

@mturley
Copy link
Collaborator

mturley commented May 7, 2020

Describe the issue. What is the expected and unexpected behavior?

Our Checkbox and DropdownToggleCheckbox components both support passing a null value for the isChecked prop to display an indeterminate state (line through the box, not checked or unchecked). For the DropdownToggleCheckbox (and not the Checkbox), when that prop changes from false to null, React throws this warning:

A component is changing a controlled input of type checkbox to be uncontrolled. Input elements should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled input element for the lifetime of the component.

Comparing the source for Checkbox and DropdownToggleCheckbox, the difference appears to be this line:

checkedProps.checked = checkedProps.checked === null ? false : checkedProps.checked;

So, we need the checked attribute on the underlying <input> to always be a boolean even when isChecked is null, since the null value just drives the indeterminate property via a ref callback.

I think the real fix for this is just to remove the native <input> from DropdownToggleCheckbox and instead reuse Checkbox in there (I think the dropdown one predated the generic one).

Please provide the steps to reproduce. Feel free to link CodeSandbox or another tool.

Use this CodeSandbox (thanks @redallen): https://codesandbox.io/s/dazzling-hill-wzf1j
If you uncheck all the child checkboxes, you'll see the parent checkbox switch from indeterminate to unchecked, and the error will appear in the console.

Is this a bug or enhancement? If this issue is a bug, is this issue blocking you or is there a work-around?
Bug. It causes a silent warning, but as long as the behavior still works as intended it's not a blocker.

What is your product and what release version are you targeting?
This is for @AjayJagan in Kogito. This is the PR where he is seeing the issue: https://github.com/kiegroup/kogito-apps/pull/209. Not sure what release version he is targeting.

@cristianonicolai
Copy link

@mturley Kogito currently uses this set of versions: https://github.com/kiegroup/kogito-apps/blob/master/packages/management-console/package.json#L39 from 2020.04 release. Thanks

@AjayJagan
Copy link

AjayJagan commented May 8, 2020 via email

@tlabaj tlabaj added this to the Prioritized Backlog milestone May 13, 2020
@stale
Copy link

stale bot commented Jul 20, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@stale stale bot added the wontfix label Jul 20, 2020
@mturley mturley removed the wontfix label Jul 20, 2020
@stale
Copy link

stale bot commented Sep 20, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@stale stale bot added the wontfix label Sep 20, 2020
@mturley
Copy link
Collaborator Author

mturley commented Sep 21, 2020

This was fixed by #4844

@mturley mturley closed this as completed Sep 21, 2020
@tlabaj tlabaj removed this from the Prioritized Backlog milestone Nov 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants