-
Notifications
You must be signed in to change notification settings - Fork 115
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): hide icon when not checked #2167
Conversation
🦋 Changeset detectedLatest commit: 408fb00 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
✔️ Deploy Preview for paste-theme-designer ready! 🔨 Explore the source changes: 408fb00 🔍 Inspect the deploy log: https://app.netlify.com/sites/paste-theme-designer/deploys/6201b182c873a08ea9438ed6 😎 Browse the preview: https://deploy-preview-2167--paste-theme-designer.netlify.app |
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 408fb00:
|
✔️ Deploy Preview for paste-docs ready! 🔨 Explore the source changes: 408fb00 🔍 Inspect the deploy log: https://app.netlify.com/sites/paste-docs/deploys/6201b189df6685949dc8dc1c 😎 Browse the preview: https://deploy-preview-2167--paste-docs.netlify.app |
Size Change: +62 B (0%) Total Size: 459 kB
ℹ️ View Unchanged
|
packages/paste-core/components/checkbox/stories/checkbox.stories.tsx
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Thanks for sprucing this up.
Test summaryRun details
View run in Cypress Dashboard ➡️ This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard |
252351a
to
1ef56cd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally LGTM! When we confirm that the checkbox icon renders correctly for uncontrolled components too, I'll go ahead and apporove. 🥳
packages/paste-core/components/checkbox/stories/checkbox.stories.tsx
Outdated
Show resolved
Hide resolved
const handleChange = props.onChange != null ? props.onChange : checkboxGroupContext.onChange; | ||
|
||
// Manages what the value of checked is depending on if it is controlled or uncontrolled | ||
const [checkedState, setCheckedState] = React.useState(!!defaultChecked); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a simplified version of what Chakra does (see their useCheckbox hook)
If the user passes checked & onChange it is a controlled component, if they don't pass them it is uncontrolled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because defaultChecked
is a boolean, what's the difference between using the double bang operator and just saying useState(defaultChecked)
? wouldn't that still give you either true
or false
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It forces the value to always be a T/F. So, if defaultChecked is undefined then !!defaultChecked is false.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
noice🥇 left a few questions but nothing blocking
packages/paste-core/components/checkbox/__tests__/checkbox.test.tsx
Outdated
Show resolved
Hide resolved
The checkbox can either be controlled, meaning there is an external state that determines if the checkbox is checked or not, or uncontrolled, meaning the checkbox manages its own state. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Super helpful to have this context in the docs, might be worth adding a sentence about why one would want an uncontrolled vs controlled checkbox
const handleChange = props.onChange != null ? props.onChange : checkboxGroupContext.onChange; | ||
|
||
// Manages what the value of checked is depending on if it is controlled or uncontrolled | ||
const [checkedState, setCheckedState] = React.useState(!!defaultChecked); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because defaultChecked
is a boolean, what's the difference between using the double bang operator and just saying useState(defaultChecked)
? wouldn't that still give you either true
or false
?
Fixes a bug found in: #2165
Contributing to Twilio