From 8cc027ed752eaf44d2a33d9744d490664886c828 Mon Sep 17 00:00:00 2001 From: Daniel Rafailov Date: Sun, 29 Nov 2026 17:36:51 -0500 Subject: [PATCH 1/2] Made the graph controls and sidebar toggle keyboard and screen reader accessible --- CHANGELOG.md | 1 + js/components/graph/Button.tsx | 6 ++++ js/components/graph/Graph.js | 8 +++-- js/components/graph/Sidebar.tsx | 16 ++++++--- js/components/graph/__tests__/Button.test.js | 26 ++++++++++++++ js/components/graph/__tests__/Graph.test.js | 35 +++++++++++++++++++ js/components/graph/__tests__/Sidebar.test.js | 18 ++++++++++ .../__snapshots__/Sidebar.test.js.snap | 20 ++++++++--- style/app.scss | 13 ++++++- 9 files changed, 131 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b3d6bb32..d44b6b8a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ ### ✨ New features/enhancements +- Made the graph's zoom, reset view and sidebar buttons keyboard and screen reader accessible (accessible names, visible focus outlines, and activation with Enter/Space) - Changed the colour of hybrid nodes to avoid a visual clash with the darkened background when selecting a focus - Updated section codes on the grid page to match the official timetable builder (listed as LEC/TUT/PRA instead of L/T/P) - Updated text on the course panel of the grid page to better communicate the panel's behaviour diff --git a/js/components/graph/Button.tsx b/js/components/graph/Button.tsx index 722df1678..d3426a0d7 100644 --- a/js/components/graph/Button.tsx +++ b/js/components/graph/Button.tsx @@ -3,10 +3,12 @@ import React from "react" interface ButtonProps { divId?: string mouseDown?: () => void + onClick?: () => void mouseUp?: () => void onMouseEnter?: () => void onMouseLeave?: () => void disabled?: boolean + ariaLabel?: string text?: string children?: React.ReactNode } @@ -14,10 +16,12 @@ interface ButtonProps { export default function Button({ divId, mouseDown, + onClick, mouseUp, onMouseEnter, onMouseLeave, disabled, + ariaLabel, text, children, }: ButtonProps) { @@ -26,10 +30,12 @@ export default function Button({ id={divId} className="graph-control-button" onMouseDown={mouseDown} + onClick={onClick} onMouseUp={mouseUp} onMouseEnter={onMouseEnter} onMouseLeave={onMouseLeave} disabled={disabled} + aria-label={ariaLabel} > {text} {children} diff --git a/js/components/graph/Graph.js b/js/components/graph/Graph.js index 9a1a8ce39..022a7ef03 100644 --- a/js/components/graph/Graph.js +++ b/js/components/graph/Graph.js @@ -1164,14 +1164,16 @@ export class Graph extends React.Component {
-
toggleSidebar()} + aria-label="Course sidebar" + aria-expanded={!collapsed} + aria-controls="sidebar-dropdown" data-testid="test-sidebar-button" > - -
+ +
) } diff --git a/js/components/graph/__tests__/Button.test.js b/js/components/graph/__tests__/Button.test.js index dffe64aa4..5277302cb 100644 --- a/js/components/graph/__tests__/Button.test.js +++ b/js/components/graph/__tests__/Button.test.js @@ -1,6 +1,7 @@ import React from "react" import Button from "../Button" import { render, screen, act } from "@testing-library/react" +import userEvent from "@testing-library/user-event" describe("Button", () => { it("should match snapshot", async () => { @@ -14,4 +15,29 @@ describe("Button", () => { const buttonElement = screen.getByText(buttonText) expect(buttonElement).toMatchSnapshot() }) + + it("uses ariaLabel as the button's accessible name", () => { + render( , @@ -78,6 +84,7 @@ exports[`Sidebar should match shallow snapshot 1`] = ` , "debug": [Function], diff --git a/style/app.scss b/style/app.scss index a520b3b45..2f6ca9087 100644 --- a/style/app.scss +++ b/style/app.scss @@ -489,13 +489,17 @@ ol { font-weight: bold; height: 30px; line-height: 20px; - outline: none; padding: 5px; position: relative; text-align: center; width: 30px; } +.graph-control-button:focus-visible { + outline: 2px solid var(--primary-color); + outline-offset: 2px; +} + .graph-control-button:hover { background-color: var(--light-hover-color); color: var(--color-white); @@ -563,7 +567,9 @@ div.sidebar.collapsed { } .sidebar-button { + align-items: center; background-color: var(--primary-color); + border: 0; border-radius: 10px; cursor: pointer; display: flex; @@ -574,6 +580,11 @@ div.sidebar.collapsed { width: 30px; } +.sidebar-button:focus-visible { + outline: 2px solid var(--primary-color); + outline-offset: 2px; +} + .selected-courses { color: var(--primary-color); font-size: 14px; From 712a8d0a447610c1d7b9fdefec481dc1f9db1d2f Mon Sep 17 00:00:00 2001 From: Daniel Rafailov Date: Sun, 29 Nov 2026 17:52:41 -0500 Subject: [PATCH 2/2] Kept the graph control focus outline above neighbouring buttons --- style/app.scss | 1 + 1 file changed, 1 insertion(+) diff --git a/style/app.scss b/style/app.scss index 2f6ca9087..30a6e7226 100644 --- a/style/app.scss +++ b/style/app.scss @@ -498,6 +498,7 @@ ol { .graph-control-button:focus-visible { outline: 2px solid var(--primary-color); outline-offset: 2px; + z-index: 1; } .graph-control-button:hover {