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(swatch): mixed-value state must be conveyed to screen readers using ARIA #3330

Merged
merged 15 commits into from Jun 27, 2023

Conversation

Rajdeepc
Copy link
Contributor

@Rajdeepc Rajdeepc commented Jun 20, 2023

Description

Added a logic to check for mixedValue property and add aria-checked="mixed"

Related issue(s)

Motivation and context

Currently, mixed state is not conveyed to screen reader users. Please use aria-checked="mixed" when mixed-value is used.

How has this been tested?

  • Test case 1
    1. Go here
    2. Do this
  • Test case 2
    1. Go here
    2. Do this

Screenshots (if appropriate)

Screenshot 2023-06-20 at 2 08 44 PM

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Chore (minor updates related to the tooling or maintenance of the repository, does not impact compiled assets)

Checklist

  • I have signed the Adobe Open Source CLA.
  • My code follows the code style of this project.
  • If my change required a change to the documentation, I have updated the documentation in this pull request.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • I have reviewed at the Accessibility Practices for this feature, see: Aria Practices

Best practices

This repository uses conventional commit syntax for each commit message; note that the GitHub UI does not use this by default so be cautious when accepting suggested changes. Avoid the "Update branch" button on the pull request and opt instead for rebasing your branch against main.

@@ -116,6 +118,7 @@ import { Swatch } from '@spectrum-web-components/swatch';
rounding="full"
shape="rectangle"
mixed-value
aria-checked="mixed"
Copy link
Collaborator

Choose a reason for hiding this comment

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

The internal logic should be enough to cover this delivery. Adding it manually here could confuse consumers as to their responsibilities with this pattern. If for some reason these are not getting the attribute at runtime after the below change, then that’s a sign there’s more work to do.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Make sense. Thank you

Copy link
Collaborator

@najikahalsema najikahalsema left a comment

Choose a reason for hiding this comment

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

Seconding what Westbrook said. I left a comment on your other PR about using the accessibility tab in Chrome's dev tools. Maybe it would be good for us to chat about how to test for accessibility at some point.

@github-actions
Copy link

github-actions bot commented Jun 21, 2023

Tachometer results

Chrome

swatch permalink

Version Bytes Avg Time vs remote vs branch
npm latest 384 kB 38.29ms - 38.76ms - unsure 🔍
-3% - +0%
-1.04ms - +0.02ms
branch 383 kB 38.55ms - 39.51ms unsure 🔍
-0% - +3%
-0.02ms - +1.04ms
-
Firefox

swatch permalink

Version Bytes Avg Time vs remote vs branch
npm latest 384 kB 198.01ms - 224.51ms - unsure 🔍
-7% - +11%
-14.46ms - +22.18ms
branch 383 kB 194.75ms - 220.05ms unsure 🔍
-10% - +7%
-22.18ms - +14.46ms
-

Copy link
Collaborator

@najikahalsema najikahalsema left a comment

Choose a reason for hiding this comment

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

Behold, the fruits of my labour!

if (this.mixedValue) {
this.setAttribute('aria-checked', 'mixed');
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hey Rajdeep! Just following up on our conversation earlier today.

To add a label to the Swatch that matches the color attribute, you can add the following in the Swatch code's willUpdate function:

if (changes.has('label')) {
            // if there is a colour set,
            if (this.color !== '') { 
                this.setAttribute('aria-label', this.color); // set the aria-label to be this.color
           // otherwise, if the label is different from the colour and is a length longer than 0,
            } else if (this.label !== this.color && this.label.length) { 
                // override the label with this.label
                this.setAttribute('aria-label', this.label); 
            }
             else {
                this.removeAttribute('aria-label');
            }
        }

This obviously doesn't handle situations where our value would be 'mixed' or 'nothing' (since color='' in that situation), but it's better than no label at all. Hopefully, we can get some guidance on @dineshy87 's side as to what kind of aria-label would be best for those situations, too. 😄 Depending on how many different types of labels we need, we may want to abstract this out of willUpdate().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@najikahalsema Thanks!!

Screenshot 2023-06-23 at 3 41 23 PM

Copy link
Collaborator

Choose a reason for hiding this comment

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

Just one thing--I'd remove the comments from the code!

@Rajdeepc Rajdeepc requested a review from Westbrook June 23, 2023 11:17
Copy link
Collaborator

@najikahalsema najikahalsema left a comment

Choose a reason for hiding this comment

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

Almost there!!!

if (this.mixedValue) {
this.setAttribute('aria-checked', 'mixed');
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just one thing--I'd remove the comments from the code!

<sp-swatch mixed-value></sp-swatch>
<sp-swatch mixed-value rounding="full"></sp-swatch>
<sp-swatch mixed-value shape="rectangle"></sp-swatch>
<sp-swatch mixed-value aria-checked="mixed"></sp-swatch>
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe that westbrook touched on this before, but you shouldn't need to add aria-checked="mixed" here since it's doing it now (you would have to add selects="multiple" to the swatch group, though)? Or maybe you could say something like "Please note that the aria-checked="mixed" value only applies when the swatch is in a group with selects="multiple".

I believe that even if you add it manually, like you have here, it still won't display on the screen reader because the role is still button.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks

@@ -223,12 +223,19 @@ export class Swatch extends SizedMixin(Focusable, {
);
}
if (changes.has('label')) {
if (this.label) {
if (this.color !== '') {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you placed this logic in the wrong order and it's what's causing the test failures in CI right now. Can you take a look at those?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should be good now except for the fact that few NumberFields tests are failing. Switching the order of if else did the trick!
Thanks

@Rajdeepc Rajdeepc requested a review from Westbrook June 26, 2023 16:26
@Rajdeepc
Copy link
Contributor Author

@Westbrook @najikahalsema Let me know if this PR looks good to merge?

@Westbrook Westbrook changed the title [Bug][a11y]: mixed-value state of swatches must be conveyed to screen readers using ARIA fix(swatch): mixed-value state must be conveyed to screen readers using ARIA Jun 27, 2023
Copy link
Collaborator

@najikahalsema najikahalsema left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you for your hard work 🙇

@najikahalsema najikahalsema merged commit 7711264 into main Jun 27, 2023
47 checks passed
@najikahalsema najikahalsema deleted the bug/aria-mixed-value branch June 27, 2023 17:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a11y Issues related to accessibility bug Something isn't working Component: Swatch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants