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

va-checkbox: add indeterminate prop #1426

Merged
merged 11 commits into from
Dec 10, 2024
Merged

Conversation

jamigibbs
Copy link
Contributor

@jamigibbs jamigibbs commented Dec 5, 2024

Chromatic

https://2652-va-checkbox-indeterminate--65a6e2ed2314f7b8f98609d8.chromatic.com/?path=/docs/uswds-va-checkbox--docs#indeterminate

Description

This will add an indeterminate prop to va-checkbox. When active, the checkbox will display the "mixed" icon in the checkbox which indicates that it's neither checked nor unchecked.

Closes department-of-veterans-affairs/vets-design-system-documentation#2652

QA Checklist

  • Component maintains 1:1 parity with design mocks
  • Text is consistent with what's been provided in the mocks
  • Component behaves as expected across breakpoints
  • Accessibility expert has signed off on code changes (if applicable. If not applicable provide reason why)
  • Designer has signed off on changes (if applicable. If not applicable provide reason why)
  • Tab order and focus state work as expected
  • Changes have been tested against screen readers (if applicable. If not applicable provide reason why)
  • New components are covered by e2e tests; updates to existing components are covered by existing test suite
  • Changes have been tested in vets-website using Verdaccio (if applicable. If not applicable provide reason why)

Screenshots

Screenshot 2024-12-05 at 3 08 15 PM

Acceptance criteria

  • QA checklist has been completed
  • Screenshots have been attached that cover desktop and mobile screens

Definition of done

  • Documentation has been updated, if applicable
  • A link has been provided to the originating GitHub issue (or connected to it via ZenHub)

@jamigibbs jamigibbs added the minor For a minor Semantic Version change label Dec 5, 2024
private updateIndeterminateInput() {
const input = this.el.shadowRoot.querySelector('input');
if (this.indeterminate && !this.checked) {
input.indeterminate = true;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We are adding this indeterminate attribute manually with JavaScript based on Ryan's a11y findings here. When I tested with VO, I confirmed that this is what announces "mixed" as the checkbox state when it's active.

@@ -230,14 +256,15 @@ export class VaCheckbox {
aria-describedby={ariaDescribedbyIds}
aria-invalid={error ? 'true' : 'false'}
disabled={disabled}
data-indeterminate={indeterminate && !checked}
Copy link
Contributor Author

@jamigibbs jamigibbs Dec 6, 2024

Choose a reason for hiding this comment

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

The USWDS release notes say:

when you set input.indeterminate = true via JavaScript or add the data-indeterminate attribute

...but I couldn't get everything working for both the styles and screenreader without adding both indeterminate using JS and also adding this data-indeterminate attribute. Maybe this is a shadow dom limitation?

onChange={this.handleChange}
/>
<label
htmlFor="checkbox-element"
class="usa-checkbox__label"
part="label"
role="checkbox"
aria-checked={ariaChecked}
aria-checked={indeterminate && !checked ? 'mixed' : ariaChecked}
Copy link
Contributor Author

@jamigibbs jamigibbs Dec 6, 2024

Choose a reason for hiding this comment

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

I'm adding this because otherwise the aria-checked state would be either true or false but it also accepts "mixed" according to MDN.

Setting indeterminate on the input element though seems to be what is making the screenreader announcement. I'm not sure exactly what aria-checked is doing in this scenario if anything.

@@ -257,4 +257,39 @@ describe('va-checkbox', () => {
await checkboxLabelEl.click();
expect(await checkboxEl.getProperty('checked')).toBeTruthy();
});

it('sets the data-indeterminate attribute on the input element', async () => {
Copy link
Contributor Author

@jamigibbs jamigibbs Dec 6, 2024

Choose a reason for hiding this comment

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

I tried also to get a test working that checked if the input element was getting the .indeterminate property from being set in JS but I could not get it to work. :/

This is kind of a strange property though so either it's some kind of testing limitation with Stencil or I'm just not writing the test in a way that it can pick up that value.

@jamigibbs
Copy link
Contributor Author

jamigibbs commented Dec 6, 2024

For the Storybook example, I took inspiration from this resource but there are different ways to compose a scenario that uses this checkbox state. There are also different ways to style it (like indented options). Are design guidelines something we want to put more thought into? Or is this example going to be ok for now?

Screenshot 2024-12-06 at 2 20 44 PM

cc @department-of-veterans-affairs/platform-design-system-designers

@jamigibbs jamigibbs marked this pull request as ready for review December 6, 2024 20:42
@jamigibbs jamigibbs requested a review from a team as a code owner December 6, 2024 20:42
@jamigibbs jamigibbs requested review from rsmithadhoc and a team December 6, 2024 20:42
Copy link
Contributor

@rsmithadhoc rsmithadhoc left a comment

Choose a reason for hiding this comment

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

Everything looked good in my testing. I tested in all of our screen reader combos that I have access to (everything except iOS) and it worked as expected.

Something to consider in the example is updating it to better show a parent-child relationship by changing the label to "Select All Historical Figures". I think that would better indicate that it controls the child checkboxes.

Thanks!

Copy link
Contributor

@danbrady danbrady left a comment

Choose a reason for hiding this comment

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

I've determined this is awesome.

@jamigibbs jamigibbs changed the title va-checkbox: add indeterminate state va-checkbox: add indeterminate prop Dec 9, 2024
@jamigibbs jamigibbs merged commit 3cfc643 into main Dec 10, 2024
8 checks passed
@jamigibbs jamigibbs deleted the 2652-va-checkbox-indeterminate branch December 10, 2024 22:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
minor For a minor Semantic Version change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[va-checkbox] - Add Indeterminate State - Development
3 participants