-
Notifications
You must be signed in to change notification settings - Fork 4
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
feat!: split apart checkbox checked and indeterminate props #1520
Conversation
@@ -137,8 +137,6 @@ exports[`<Checkbox /> Disabled story renders snapshot 1`] = ` | |||
class="checkbox" | |||
> | |||
<input | |||
aria-checked="mixed" |
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.
Don't need aria-checked
when we set indeterminate
on the DOM node.
const checkedProps = | ||
checked === 'indeterminate' | ||
? { | ||
'aria-checked': 'mixed' as const, |
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.
Previously we set aria-checked
so screen readers knew about it, but the DOM itself didn't consider the checkbox to be indeterminate.
Here we fix that (which unfortunately requires JS and jumping through a hoop).
>(({ checked, className, disabled, indeterminate, ...other }, ref) => { | ||
const forwardedRef = useForwardedRef(ref); | ||
|
||
// Make this checkbox indeterminate. Can only be done with JS for some reason. |
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.
See facebook/react#1798 for why React hasn't added an indeterminate
prop to input checkboxes
TL;DR: Browsers don't have an indeterminate
attribute.
d5410d0
to
ce46a2f
Compare
Codecov Report
@@ Coverage Diff @@
## next #1520 +/- ##
=======================================
Coverage 91.86% 91.86%
=======================================
Files 284 284
Lines 4280 4280
Branches 790 790
=======================================
Hits 3932 3932
Misses 323 323
Partials 25 25 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
500e095
to
9e8c01f
Compare
How test coverage decrease when I added tests? 🤔 |
I think coverage is calculated by Hits / Lines and your new tests covered 11 / 12 new lines (91.66%) which technically brought the average down LOL |
…hecked` https://html.spec.whatwg.org/multipage/input.html#checkbox-state-(type=checkbox) considers indeterminate to be a separate thing from a checkbox's checked state. In fact, it calls out that "The indeterminate IDL attribute only gives the appearance of a third state." Basically you can end up with all 4 combinatinos of checked and indeterminate, although visually there are only 3 states (both indeterminate states look the same). We can also see clearly at https://codepen.io/ahuth/pen/MWqmwyv that browsers behave this way.
9e8c01f
to
0826bfe
Compare
size-limit report 📦
|
@chanzuckerberg/edu-frontend-infra |
@ahuth can you update the PR title to be semver? looks like github made the checkbox PR commit non-compliant on merge It's annoying that it defaults to the title if there are multiple commits on a PR branch... |
Oh, the PR title needs to adhere to conventional-commits? Of course! Guess I assumed that the defaults for merges were fine. Maybe that's why we used to only allow rebase merges (since commit messages are enforced) 🤔 |
I might be missing what thing(s) break with this change? is it the place where we try and handle |
Yah, probably. It's a REALLY annoying "feature" in GitHub where it does the Right Thing (tm) if the branch has one commit to squash and merge, but this behavior when it has multiple ones. I'd honestly prefer if it left the title field blank when ambiguous but 🤷. That code is good, so we can update changelog manually if we want; no biggie |
Updated the title.
The |
@chanzuckerberg/edu-frontend-infra please take a look when you get a chance 🙏 |
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.
Thanks for patching this up! I think this PR will have enough details for anyone to sort out what changes they should make in the off chance they were trying to use indeterminate directly.
*/ | ||
checked?: boolean | 'indeterminate'; | ||
checked?: boolean; |
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.
The breaking change => reducing the available options
<Checkbox {...args} disabled /> | ||
<Checkbox {...args} checked disabled /> | ||
<Checkbox {...args} checked="indeterminate" disabled /> | ||
<Checkbox {...args} disabled indeterminate /> |
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.
I like how simple this looks
render(<CheckboxInput id="test" />); | ||
const checkbox = screen.getByRole<HTMLInputElement>('checkbox'); | ||
expect(checkbox.indeterminate).toEqual(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.
Just also manually tested <Checkbox indeterminate>
and then checking it to true and seeing that the input.indeterminate === 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.
Sweet, thanks!
/** | ||
* Safely access a forwarded ref, which may or may not be present. | ||
*/ |
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! |
## [11.0.0](v10.0.0...v11.0.0) (2023-03-17) ### ⚠ BREAKING CHANGES * add `indeterminate` prop to <Checkbox> that's separate from `checked` (#1520) ### Features * add `indeterminate` prop to <Checkbox> that's separate from `checked` ([#1520](#1520)) ([d8e2cc4](d8e2cc4)) * **LoadingIndicator:** extract and use SVG animation directly ([#1540](#1540)) ([6e315ea](6e315ea)) * **menu:** add Menu.PlainButton as a minimally styled Menu button ([#1516](#1516)) ([8268d8e](8268d8e)) ### Bug Fixes * actually use our shared prettier config ([c98ea51](c98ea51)) * **Avatar:** loosen props for avatar aria-label component ([#1544](#1544)) ([4ab9183](4ab9183)) * markdown story styling ([#1536](#1536)) ([89eba6b](89eba6b))
EFI-949
Summary:
Breaking change! (although I'm not aware of any consumers affected by it)
checked
andindeterminate
props.indeterminate
checkboxes officially indeterminate in the DOM.Why:
Thought about this while working on #1511.
https://html.spec.whatwg.org/multipage/input.html#checkbox-state-(type=checkbox) calls out
indeterminate
as a separate piece of state thanchecked
.Practically this means a checkbox can be in all 4 combinations of
checked
andindeterminate
(although there are only 3 visual states, because both indeterminates look the same).Verified this is how browsers behave with https://codepen.io/ahuth/pen/MWqmwyv.
Test Plan: