-
Notifications
You must be signed in to change notification settings - Fork 196
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
chore[actionbutton, actiongroup]: fix application of aria-labels #3230
chore[actionbutton, actiongroup]: fix application of aria-labels #3230
Conversation
|
🚀 Deployed on https://pr-3230--spectrum-css.netlify.app |
File metricsSummaryTotal size: 4.31 MB* 🎉 No changes detected in any packages * Size determined by adding together the size of the main file for all packages in the library.* Results are not gzipped or minified. * An ASCII character in UTF-8 is 8 bits or 1 byte. |
@@ -69,7 +69,7 @@ export const Template = ({ | |||
const { updateArgs } = context; | |||
return html` | |||
<button | |||
aria-label=${ifDefined(label)} | |||
aria-label=${ifDefined(hideLabel ? label : undefined)} |
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 the same way Button
handles the aria-labels
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.
Is this preferable to wrapping the label and value in the condition and omitting altogether if the condition 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.
It is - this is the way lit-html manages attributes
iconOnly: true, | ||
content: [ | ||
{ | ||
iconName: "AlignTop", | ||
label: "", | ||
label: "Align top", |
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.
Instead of creating icon-only buttons by leaving label
as an empty string, I wanted to utilize the iconOnly
control for action group. I also think having the label for each action button here better aligns with the guidance that "action buttons should always have a label."
@@ -129,59 +130,24 @@ export const OverflowOption = (context) => Container({ | |||
` | |||
}, context ); | |||
|
|||
export const ActionButtonOptions = (args, context ) => Container({ |
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.
Correct me if I'm wrong, but I think this was basically recreating the Template with all of the same arg values as the default args. I ended up removing this template, in favor of just using the template itself, with the default args, in TreatmentTemplate
.
{ heading: "Default", }, | ||
{ iconOnly: true, heading: "Icon-only", }, | ||
{ iconOnly: true, areQuiet: true, heading: "Quiet, icon-only", }, | ||
].map(({ heading, areQuiet, iconOnly }) => Container({ | ||
withBorder: false, | ||
heading: heading, | ||
content: Template({ | ||
...args, | ||
areQuiet, | ||
iconOnly, | ||
}, context)} |
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.
Similar to the comment I made in the stories file- I opted for using the iconOnly
arg for action group, instead of hideLabel
from action button.
label: "Delete", | ||
}, | ||
{ | ||
iconName: "More", |
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.
In my screenreader testing, this button was just announced as "toggle button." Do we have a specific label for a button like this, that probably triggers a popover/menu?
}) | ||
} | ||
)} | ||
withBorder: 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.
These changes just fixed up some indentation, removed the border from around each container, and I think passed context to the templates, instead of the parent Container()
@@ -69,7 +69,7 @@ export const Template = ({ | |||
const { updateArgs } = context; | |||
return html` | |||
<button | |||
aria-label=${ifDefined(label)} | |||
aria-label=${ifDefined(hideLabel ? label : undefined)} |
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.
Is this preferable to wrapping the label and value in the condition and omitting altogether if the condition is false?
@cdransf Because the button behavior was called out in the issue, I went straight to the button template to see how it was working there. |
@@ -69,7 +69,7 @@ export const Template = ({ | |||
const { updateArgs } = context; | |||
return html` | |||
<button | |||
aria-label=${ifDefined(label)} | |||
aria-label=${ifDefined(hideLabel ? label : undefined)} |
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 is - this is the way lit-html manages attributes
- ensures that actiongroup arg types are used in some of the documentation template instead of actionbutton args - removes white space from stories file - corrects some sentence-case instances for story names
9a4f993
to
e3beebc
Compare
Description
All action buttons were, by default, receiving the
aria-label
attribute. When clickable elements have visible text, typically they should not receive anaria-label
because a screen reader will read the visible text aloud. The button component was applyingaria-label
s conditionally (when a button didn't have visible text/label), so the same approach was brought to action button. Now, any action button that has "regular" label text does not receive thearia-label
, and if an action button is icon-only, with itshideLabel: true
arg set, anaria-label
will be applied.Because action buttons are used in the action group component as well, some refactoring had to be done to make sure any arguments used to create icon-only action buttons were from the action group args, as opposed to the action button args. For instance, instead of the action buttons'
label
arg getting set to empty string to render an icon-only action button within an action group like so:...the code for action group now relies on its own
iconOnly
control to hide the action buttons' labels.This should ensure that the
label
for each action button withincontent
gets passed appropriately to the action button component, and set as the value for itsaria-label
.White space/empty lines in the story files were removed during this work, as well as some corrections made to the sentence-case of our story names on the documentation pages.
Jira/Specs
CSS-853
Github issue
Pending Questions
ActionButton
to make sure we're using label and hideLabel correctly? For instance, the breadcrumbs action button is icon-only, and has no label text or aria-label. Is that separate work from this PR? With just a quick search, card, contextual help, pagination may be other components to look into.How and where has this been tested?
Please tag yourself on the tests you've marked complete to confirm the tests have been run by someone other than the author.
Validation steps
aria-label
attribute.aria-label="Edit"
for the icon-only buttons.aria-label
for the icon-only action buttons.(I used "paradiddle" 🥁)
aria-label
announced by the screenreader. You should hear something like "Edit, toggle button." You should also hear "submenu" for the action buttons with the "hold icon."aria-label
s. The action button labels should be within<span>
s.aria-label
s set to their label text. You should see "Edit," "Copy," and "Delete."aria-label
attribute since they have visible text.Regression testing
Validate:
Screenshots
To-do list