-
Notifications
You must be signed in to change notification settings - Fork 1.1k
USWDS - Header: Secondary nav a11y improvements #4963
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
Conversation
- Use code for pipe character - Add empty alt text for pseudoelement to prevent character being read on screenreaders Based on guidance https://www.w3.org/TR/css-content-3/#alt
Caniuse indicates this this feature doesn't have great support yet — perhaps since it's still functionality that's only in a draft spec? That said, it this issue in the JAWS repo makes it look like JAWS does support it? |
@thisisdano we were able to test in JAWS thanks to @amycole501. She confirmed this fixes the issue. I'm happy to change it to border if we want to avoid introducing features that are still in draft. |
Firefox doesn't render correctly, so this solution won't work. From @nick-mon1:
|
& + .usa-nav__secondary-item { | ||
border-left: 1px solid color("base-lighter"); | ||
margin-left: px-to-rem(5px); | ||
padding-left: units(1); |
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.
Alternative
Alternate solution keeps the pseudo element, but creates the shape. I liked that it's similar to the current, but it's more CSS.
& + .usa-nav__secondary-item::before {
background-color: color("base-lighter");
display: inline-block;
width: units("1px");
height: units(2);
content: "";
margin-right: units(0.5);
vertical-align: middle;
}
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 noticed that this solution causes some slight content shift brought on by the height
setting. Here's a video of me clicking back and forth between the development build and local
Screen.Recording.2023-02-03.at.1.18.03.PM.mov
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 think either solution would work! I like trying to keep the original border height but the benefit of less css and not having the content shift slightly might be the better move forward.
& + .usa-nav__secondary-item { | ||
border-left: 1px solid color("base-lighter"); | ||
margin-left: px-to-rem(5px); | ||
padding-left: units(1); |
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 noticed that this solution causes some slight content shift brought on by the height
setting. Here's a video of me clicking back and forth between the development build and local
Screen.Recording.2023-02-03.at.1.18.03.PM.mov
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 the border solution. I think it is a nice, simple way to approach it. I had one question about some CSS. Let me know what you think.
padding-right: units(0.5); | ||
& + .usa-nav__secondary-item { | ||
border-left: 1px solid color("base-lighter"); | ||
margin-left: px-to-rem(5px); |
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.
@mejiaj
I am curious about why the value is 5px
here instead of matching the padding-left
value of units(1)
. I did a little digging, and when I set the margin-left
to units(1)
, I saw that the horizontal alignment between the elements was a bit off. Is this the reason for the 5px
? If so, the misalignment seemed to resolve itself when I replaced float:right
with display:flex
on .usa-nav__secondary-links
. Doing so also had the added benefit of making the border height a little smaller. What do you think? Am I making too many assumptions here?
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.
@amyleadem this is to make up for the lost whitespace from initial styling. I wasn't completely satisfied with the 5px
, but it seemed like the most straightforward based on alternatives.
I'd prefer to avoid floats and messing with the layout too much, but I can see if there are any flexbox properties that could help.
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.
Using JAWS, I didn't hear any indication of the pipe being read aloud. I tried in Chrome, Firefox and Edge. It does, though, say "Blank" instead. Not ideal but it is better than describing the pipe as a vertical line.
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.
Approved!
Tested on:
- Safari
- Firefox
- Chrome
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.
What a smart solution!
Description
Secondary nav separator is no longer read on screenreaders. The
|
pseudoelement is no longer read on screen readers. Closes #4944.Preview link
Additional information
This solution converts the separator from a pseudoelement to a border. This simplifies styles and prevents the screenreaders from reading this element.
Old
Header extended in Chrome.

New
Chrome

Firefox

Safari

Previous solution
Firefox

The separator uses an empty string for the pseudoelement's alt text.
Based on W3 Guidance
Before you hit Submit, make sure you’ve done whichever of these applies to you:
npm test
and make sure the tests for the files you have changed have passed.