Skip to content

Commit ee1db39

Browse files
committed
feat(offline): a11y improvements to offline indicator and tooltip
1 parent b93fab5 commit ee1db39

2 files changed

Lines changed: 32 additions & 2 deletions

File tree

src/components/SaveButton/SaveButton.jsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,18 @@ const SaveButton = ({ className, type, fill = false }) => {
4444

4545
if (offlineEnabled && !isOnline && !user) {
4646
return (
47-
<div className={classNames(className, "offline-badge")}>
47+
<div
48+
className={classNames(className, "offline-badge")}
49+
tabIndex={0}
50+
aria-describedby="offline-badge-tooltip"
51+
>
4852
<OfflineIcon />
4953
<span>{t("header.offline")}</span>
50-
<div className="offline-badge__tooltip">
54+
<div
55+
id="offline-badge-tooltip"
56+
className="offline-badge__tooltip"
57+
role="tooltip"
58+
>
5159
<p>{t("header.offlineTooltipDevice")}</p>
5260
<p>{t("header.offlineTooltipContinue")}</p>
5361
</div>

src/components/SaveButton/SaveButton.test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,28 @@ describe("When project is loaded", () => {
272272
);
273273
expect(screen.queryByText("header.offline")).not.toBeInTheDocument();
274274
});
275+
276+
describe("accessibility", () => {
277+
beforeEach(() => {
278+
const store = configureStore([])(offlineState);
279+
render(
280+
<Provider store={store}>
281+
<SaveButton />
282+
</Provider>,
283+
);
284+
});
285+
286+
test("badge is keyboard focusable", () => {
287+
const badge = screen.getByText("header.offline").parentElement;
288+
expect(badge).toHaveAttribute("tabIndex", "0");
289+
});
290+
291+
test("badge tooltip is associated via aria-describedby", () => {
292+
const tooltip = screen.getByRole("tooltip");
293+
const badge = screen.getByText("header.offline").parentElement;
294+
expect(badge).toHaveAttribute("aria-describedby", tooltip.id);
295+
});
296+
});
275297
});
276298

277299
afterAll(() => {

0 commit comments

Comments
 (0)