-
Notifications
You must be signed in to change notification settings - Fork 54
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 nav header accessibility issues #6538
Merged
+385
−14
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ export interface Option { | |
interface Props { | ||
options: Option[]; | ||
label?: string | React.ReactNode; | ||
ariaLabel?: string; | ||
name?: string; | ||
onChange?: (e: React.ChangeEvent<HTMLSelectElement>) => void; | ||
selectedValue: string; | ||
|
@@ -36,6 +37,7 @@ type SelectProps = JSX.IntrinsicElements["select"]; | |
const Dropdown: React.FC<Props & SelectProps> = ({ | ||
options, | ||
label, | ||
ariaLabel, | ||
name, | ||
onChange, | ||
disabled, | ||
|
@@ -91,6 +93,7 @@ const Dropdown: React.FC<Props & SelectProps> = ({ | |
)} | ||
name={name} | ||
id={id} | ||
aria-label={ariaLabel} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
aria-required={required || "false"} | ||
onChange={onChange} | ||
value={selectedValue || defaultOption || ""} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { render } from "@testing-library/react"; | ||
import "../../i18n"; | ||
import { Provider } from "react-redux"; | ||
import { MemoryRouter } from "react-router-dom"; | ||
import { MockedProvider } from "@apollo/client/testing"; | ||
import configureStore from "redux-mock-store"; | ||
import { configureAxe } from "jest-axe"; | ||
|
||
import Header from "./Header"; | ||
|
||
const axe = configureAxe({ | ||
rules: { | ||
// disable landmark rules when testing isolated components. | ||
region: { enabled: false }, | ||
}, | ||
}); | ||
const mockStore = configureStore([]); | ||
const store = mockStore({ | ||
organization: { | ||
name: "Organization Name", | ||
}, | ||
user: { | ||
firstName: "Kim", | ||
lastName: "Mendoza", | ||
roleDescription: "Admin user", | ||
}, | ||
facilities: [ | ||
{ id: "1", name: "Facility One" }, | ||
{ id: "2", name: "Facility Two" }, | ||
], | ||
}); | ||
|
||
const mockNavigate = jest.fn(); | ||
jest.mock("react-router-dom", () => { | ||
const original = jest.requireActual("react-router-dom"); | ||
return { | ||
...original, | ||
useNavigate: () => mockNavigate, | ||
}; | ||
}); | ||
|
||
describe("Header", () => { | ||
it("displays correctly", async () => { | ||
render( | ||
<Provider store={store}> | ||
<MockedProvider> | ||
<MemoryRouter> | ||
<Header /> | ||
</MemoryRouter> | ||
</MockedProvider> | ||
</Provider> | ||
); | ||
expect(document.body).toMatchSnapshot(); | ||
expect(await axe(document.body)).toHaveNoViolations(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -230,7 +230,6 @@ const Header: React.FC<{}> = () => { | |
<li className="usa-sidenav__item role-tag"> | ||
{formatRole(user.roleDescription)} | ||
</li> | ||
<hr /> | ||
<li className="usa-sidenav__item navlink__support"> | ||
<div className="header-link-icon sparkle-icon-mask"></div> | ||
<a | ||
|
@@ -281,15 +280,23 @@ const Header: React.FC<{}> = () => { | |
className={item.className} | ||
data-testid={`${deviceType}-${item.dataTestId}`} | ||
id={`${deviceType}-${item.dataTestId}`} | ||
role={item.hasSubmenu ? "button" : "link"} | ||
aria-expanded={item.hasSubmenu ? staffDetailsVisible : undefined} | ||
aria-controls={ | ||
item.hasSubmenu | ||
? `${deviceType}-${item.dataTestId}-submenu` | ||
: undefined | ||
} | ||
> | ||
{deviceType === "desktop" ? item.icon : item.mobileDisplayText} | ||
</LinkWithQuery> | ||
{item.hasSubmenu && | ||
staffDetailsVisible && | ||
deviceType === "desktop" ? ( | ||
<div | ||
id={`${deviceType}-${item.dataTestId}-submenu`} | ||
ref={staffDefailsRef} | ||
aria-label="Primary navigation" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
aria-label="Account navigation" | ||
className={classNames("prime-staff-infobox", { | ||
"is-prime-staff-infobox-visible": staffDetailsVisible, | ||
})} | ||
|
@@ -326,7 +333,7 @@ const Header: React.FC<{}> = () => { | |
</button> | ||
|
||
<nav | ||
aria-label="Primary navigation" | ||
aria-label="Primary mobile navigation" | ||
className={classNames( | ||
"usa-nav", | ||
"prime-nav", | ||
|
@@ -350,13 +357,12 @@ const Header: React.FC<{}> = () => { | |
</ul> | ||
<div className="usa-nav__primary mobile-sublist-container"> | ||
{secondaryNavSublist("mobile")} | ||
<hr /> | ||
|
||
<label id="mobile-facility-label" className="usa-label "> | ||
Facility | ||
</label> | ||
<div className="prime-facility-select facility-select-mobile-container"> | ||
<Dropdown | ||
ariaLabel="Select testing facility" | ||
selectedValue={facility.id} | ||
onChange={onFacilitySelect} | ||
className={"mobile-facility-select"} | ||
|
@@ -373,14 +379,14 @@ const Header: React.FC<{}> = () => { | |
</div> | ||
|
||
<nav | ||
aria-label="Primary navigation" | ||
aria-label="Primary desktop navigation" | ||
className="usa-nav prime-nav desktop-nav" | ||
> | ||
{mainNavList("desktop")} | ||
{facilities && facilities.length > 0 ? ( | ||
<div className="prime-facility-select"> | ||
<Dropdown | ||
aria-label={"Select facility"} | ||
ariaLabel="Select testing facility" | ||
selectedValue={facility.id} | ||
onChange={onFacilitySelect} | ||
options={facilities.map(({ name, id }) => ({ | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
<li>
element within<ul>
parent elementThere 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 to clarify, did you mean that we can't have a
<a>
element within a<ul>
? wanted to make sure I understood for future reference!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.
ooo sorry I missed this comment. I think there were only three elements that could be direct children of the
<ul>
element... let me try to see if I can get that error again.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.
@fzhao99 it was this error! https://dequeuniversity.com/rules/axe/4.7/list?application=AxeChrome