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

fix(Checkbox): Set checked value correctly #1929

Merged
merged 1 commit into from
May 16, 2019
Merged

fix(Checkbox): Set checked value correctly #1929

merged 1 commit into from
May 16, 2019

Conversation

boaz0
Copy link
Member

@boaz0 boaz0 commented May 5, 2019

What:

closes #1959

I first realized that the controlled Checkbox example is wrong: event.target.name is not set and so the state can be {check1: false, check2: false, '': false} or {check1: false, check2: false, '': true}.

After fixing it by adding the name attribute to the Checkbox components the first time I checked one of the boxes I got the following error/warning message:

Warning: A component is changing an uncontrolled input of type checkbox to be controlled.
Input elements should not switch from uncontrolled to controlled (or vice versa).
Decide between using a controlled or uncontrolled input element for 
the lifetime of the component. More info: https://fb.me/react-controlled-components
    in input (created by Checkbox)
    in div (created by Checkbox)
    in Checkbox (created by ControlledCheckbox)
    in ControlledCheckbox (created by ErrorBoundary)
    in ErrorBoundary (created by Context.Consumer)

It looks like the expression isChecked || checked will return undefined if isChecked is false and so when checking the box that expression changed to true which causes the component to turn to be controlled.

//cc @dlabrecq
fixes https://github.com/project-koku/koku-ui/issues/841

Signed-off-by: Boaz Shuster <boaz.shuster.github@gmail.com>
@patternfly-build
Copy link
Contributor

PatternFly-React preview: https://1929-pr-patternfly-react-patternfly.surge.sh

@codecov-io
Copy link

codecov-io commented May 5, 2019

Codecov Report

Merging #1929 into master will increase coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1929      +/-   ##
==========================================
+ Coverage   82.63%   82.64%   +0.01%     
==========================================
  Files         624      624              
  Lines        6875     6879       +4     
  Branches       93       94       +1     
==========================================
+ Hits         5681     5685       +4     
  Misses       1154     1154              
  Partials       40       40
Flag Coverage Δ
#patternfly3 84.89% <ø> (ø) ⬆️
#patternfly4 79.39% <100%> (+0.02%) ⬆️
#patternflymisc 95.68% <ø> (ø) ⬆️
Impacted Files Coverage Δ
...-4/react-core/src/components/Checkbox/Checkbox.tsx 90.32% <100%> (+1.43%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6dedeee...3882833. Read the comment docs.

Copy link
Contributor

@tlabaj tlabaj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@boaz0 can you add issue number to the description

@tlabaj tlabaj added PF4 React issues for the PF4 core effort bug 🐛 labels May 8, 2019
@boaz0
Copy link
Member Author

boaz0 commented May 9, 2019

Done 👍

Copy link
Contributor

@tlabaj tlabaj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@tlabaj tlabaj merged commit 43d5283 into patternfly:master May 16, 2019
@boaz0
Copy link
Member Author

boaz0 commented May 17, 2019

Thanks @tlabaj & @dlabrecq

@boaz0 boaz0 deleted the fix_checkbox branch May 17, 2019 07:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PF4 React issues for the PF4 core effort
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Checkbox controlled failure Onboarding checkboxes generate warnings
5 participants