Skip to content

Commit db78ca3

Browse files
Ensure tab links conform to WCAG 2.1 AA guidelines (PP-3575) (#192)
## Description <!--- Describe your changes --> Tab links throughout the app were provided href values of `javascript:void(0)` to prevent navigation. These void calls were replaced with identifiers that reference actual sections within the app. ## Motivation and Context <!--- Why is this change required? What problem does it solve? --> Using `javascript:void(0)` calls provide a poor experience for users as they provide no indication that a real destination exists for the link within the document. Ideally, we would make these elements buttons, but we are currently constrained by `react-bootstrap` and how it implements tabs. The alternatives: 1) remove the `event.preventDefault()` and the tabs will navigate appropriately, but this causes a full page reload every time by `react-router`, or 2) swap the links with buttons, but this would break much of the functionality and visual styling. <!--- If it fixes an open issue, please link to the issue here. --> [PP-3575](https://ebce-lyrasis.atlassian.net/browse/PP-3575) ## How Has This Been Tested? <!--- Please describe in detail how you tested your changes. --> Manually tested that the tabbing still works as intended. <!--- Include details of your testing environment, and the tests you ran to --> <!--- see how your change affects other areas of the code, etc. --> ## Checklist: <!--- Go over all the following points, and put an `x` in all the boxes that apply. --> <!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> - [ ] I have updated the documentation accordingly. - [x] All new and existing tests passed. [PP-3575]: https://ebce-lyrasis.atlassian.net/browse/PP-3575?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
1 parent 5002240 commit db78ca3

File tree

5 files changed

+10
-4
lines changed

5 files changed

+10
-4
lines changed

src/components/TabContainer.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,12 @@ export abstract class TabContainer<
4949
<ul className="nav nav-tabs">
5050
{Object.keys(this.tabs()).map((name) => (
5151
<li key={name} role="presentation" className={this.tabClass(name)}>
52-
{/* eslint-disable-next-line jsx-a11y/anchor-is-valid */}
5352
<a
54-
href="javascript:void(0)"
55-
onClick={this.handleSelect}
53+
href={`#${name}`}
54+
onClick={(event) => {
55+
event.preventDefault();
56+
this.handleSelect(event);
57+
}}
5658
data-tabkey={name}
5759
>
5860
{this.tabDisplayName(name)}
@@ -93,7 +95,7 @@ export abstract class TabContainer<
9395
renderTab(name, children) {
9496
const display = this.currentTab() === name ? "block" : "none";
9597
return (
96-
<div style={{ display }} key={name}>
98+
<div style={{ display }} key={name} id={name}>
9799
{children}
98100
</div>
99101
);

src/components/__tests__/DiagnosticsServiceTabs-test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ describe("DiagnosticsServiceTabs", () => {
132132

133133
const tab2 = wrapper.find(".nav-tabs").find("li").at(1);
134134
tab2.find("a").simulate("click", {
135+
preventDefault: stub(),
135136
currentTarget: { dataset: { tabkey: "test_service_2" } },
136137
});
137138

src/components/__tests__/DiagnosticsTabContainer-test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ describe("DiagnosticsTabContainer", () => {
136136
const tabs = wrapper.find("ul.nav-tabs").find("a");
137137
const monitorTab = tabs.at(1);
138138
monitorTab.simulate("click", {
139+
preventDefault: stub(),
139140
currentTarget: { dataset: { tabkey: "monitor" } },
140141
});
141142

src/components/__tests__/SelfTestsTabContainer-test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ describe("SelfTestsTabContainer", () => {
125125
const tabs = wrapper.find("ul.nav-tabs").find("a");
126126
const patronAuthTab = tabs.at(1);
127127
patronAuthTab.simulate("click", {
128+
preventDefault: stub(),
128129
currentTarget: { dataset: { tabkey: "patronAuthServices" } },
129130
});
130131

src/components/__tests__/TroubleshootingTabContainer-test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ describe("TroubleshootingTabContainer", () => {
3636
const tabs = wrapper.find("ul.nav-tabs").find("a");
3737
const selfTestsTab = tabs.at(1);
3838
selfTestsTab.simulate("click", {
39+
preventDefault: stub(),
3940
currentTarget: { dataset: { tabkey: "self-tests" } },
4041
});
4142

0 commit comments

Comments
 (0)