Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions js/components/graph/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,25 @@ 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
}

export default function Button({
divId,
mouseDown,
onClick,
mouseUp,
onMouseEnter,
onMouseLeave,
disabled,
ariaLabel,
text,
children,
}: ButtonProps) {
Expand All @@ -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}
Expand Down
8 changes: 5 additions & 3 deletions js/components/graph/Graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -1164,14 +1164,16 @@ export class Graph extends React.Component {
<div className="graph-button-group">
<div className="button-group">
<Button
mouseDown={() => this.zoomViewbox(ZOOM_ENUM.ZOOM_IN)}
onClick={() => this.zoomViewbox(ZOOM_ENUM.ZOOM_IN)}
ariaLabel="Zoom in"
onMouseEnter={this.buttonMouseEnter}
onMouseLeave={this.buttonMouseLeave}
>
<FontAwesomeIcon icon={faMagnifyingGlassPlus} id="zoom-icon" />
</Button>
<Button
mouseDown={() => this.zoomViewbox(ZOOM_ENUM.ZOOM_OUT)}
onClick={() => this.zoomViewbox(ZOOM_ENUM.ZOOM_OUT)}
ariaLabel="Zoom out"
onMouseEnter={this.buttonMouseEnter}
onMouseLeave={this.buttonMouseLeave}
>
Expand All @@ -1181,7 +1183,7 @@ export class Graph extends React.Component {
<div className="button-group">
<Button
divId="reset-view-button"
mouseDown={this.resetZoomAndPan}
onClick={this.resetZoomAndPan}
onMouseEnter={this.buttonMouseEnter}
onMouseLeave={this.buttonMouseLeave}
disabled={resetDisabled}
Expand Down
16 changes: 12 additions & 4 deletions js/components/graph/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,11 @@ export default function Sidebar({
onWheel={e => e.stopPropagation()}
>
{renderFCE()}
<div className="sidebar-dropdown" data-testid="test-sidebar">
<div
id="sidebar-dropdown"
className="sidebar-dropdown"
data-testid="test-sidebar"
>
<div>
<label htmlFor="header-search">
{/* For text to speech purposes */}
Expand All @@ -176,13 +180,17 @@ export default function Sidebar({
Reset Selections
</button>
</div>
<div
<button
type="button"
className="sidebar-button"
onClick={() => toggleSidebar()}
aria-label="Course sidebar"
aria-expanded={!collapsed}
aria-controls="sidebar-dropdown"
data-testid="test-sidebar-button"
>
<img id="sidebar-icon" src="/static/res/ico/sidebar.png" />
</div>
<img id="sidebar-icon" src="/static/res/ico/sidebar.png" alt="" />
</button>
</div>
)
}
26 changes: 26 additions & 0 deletions js/components/graph/__tests__/Button.test.js
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand All @@ -14,4 +15,29 @@ describe("Button", () => {
const buttonElement = screen.getByText(buttonText)
expect(buttonElement).toMatchSnapshot()
})

it("uses ariaLabel as the button's accessible name", () => {
render(<Button ariaLabel="Zoom in" />)
expect(screen.getByRole("button", { name: "Zoom in" })).not.toBeNull()
})

it("calls onClick when clicked with the mouse", async () => {
const user = userEvent.setup()
const onClick = jest.fn()
render(<Button text="Go" onClick={onClick} />)
await user.click(screen.getByRole("button", { name: "Go" }))
expect(onClick).toHaveBeenCalledTimes(1)
})

it.each(["{Enter}", " "])(
"calls onClick when %s is pressed on the focused button",
async key => {
const user = userEvent.setup()
const onClick = jest.fn()
render(<Button text="Go" onClick={onClick} />)
screen.getByRole("button", { name: "Go" }).focus()
await user.keyboard(key)
expect(onClick).toHaveBeenCalledTimes(1)
}
)
})
35 changes: 35 additions & 0 deletions js/components/graph/__tests__/Graph.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,41 @@ import { ZOOM_INCREMENT, KEYBOARD_PANNING_INCREMENT } from "../Graph"
import { Graph } from "../Graph"
import userEvent from "@testing-library/user-event"

const getViewBox = () => document.querySelector("#main-graph").getAttribute("viewBox")

describe("Graph controls", () => {
it("gives the zoom and reset buttons accessible names", async () => {
await TestGraph.build()
expect(screen.getByRole("button", { name: "Zoom in" })).not.toBeNull()
expect(screen.getByRole("button", { name: "Zoom out" })).not.toBeNull()
expect(screen.getByRole("button", { name: "Reset View" })).not.toBeNull()
})

it.each(["Zoom in", "Zoom out"])(
"zooms when Enter is pressed on the focused %s button",
async name => {
const user = userEvent.setup()
await TestGraph.build()
const initialViewBox = getViewBox()
screen.getByRole("button", { name }).focus()
await user.keyboard("{Enter}")
expect(getViewBox()).not.toBe(initialViewBox)
}
)

it("resets the view when Enter is pressed on the focused Reset View button", async () => {
const user = userEvent.setup()
await TestGraph.build()
const initialViewBox = getViewBox()
await user.click(screen.getByRole("button", { name: "Zoom in" }))
expect(getViewBox()).not.toBe(initialViewBox)

screen.getByRole("button", { name: "Reset View" }).focus()
await user.keyboard("{Enter}")
expect(getViewBox()).toBe(initialViewBox)
})
})

describe("Graph Navigation", () => {
it("Should pan right when the right arrow key is pressed", async () => {
const user = userEvent.setup()
Expand Down
18 changes: 18 additions & 0 deletions js/components/graph/__tests__/Sidebar.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,24 @@ describe("Sidebar", () => {
expect(sidebar.getByTestId("test-toggle").classList.contains("expanded")).toBe(true)
})

it("exposes the sidebar button's name and expanded state", async () => {
const user = userEvent.setup()
const sidebar = await TestSidebar.build()
const button = sidebar.getByRole("button", { name: "Course sidebar" })
expect(button.getAttribute("aria-expanded")).toBe("false")
expect(button.getAttribute("aria-controls")).toBe("sidebar-dropdown")
await user.click(button)
expect(button.getAttribute("aria-expanded")).toBe("true")
})

it("opens the sidebar when Enter is pressed on the focused sidebar button", async () => {
const user = userEvent.setup()
const sidebar = await TestSidebar.build()
sidebar.getByRole("button", { name: "Course sidebar" }).focus()
await user.keyboard("{Enter}")
expect(sidebar.getByTestId("test-toggle").classList.contains("expanded")).toBe(true)
})

it("Clicking a graph button should increase the FCE Count", async () => {
const user = userEvent.setup()
const container = await TestContainer.build()
Expand Down
20 changes: 16 additions & 4 deletions js/components/graph/__tests__/__snapshots__/Sidebar.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ exports[`Sidebar should match shallow snapshot 1`] = `
<div
class="sidebar-dropdown"
data-testid="test-sidebar"
id="sidebar-dropdown"
>
<div>
<label
Expand Down Expand Up @@ -52,15 +53,20 @@ exports[`Sidebar should match shallow snapshot 1`] = `
Reset Selections
</button>
</div>
<div
<button
aria-controls="sidebar-dropdown"
aria-expanded="false"
aria-label="Course sidebar"
class="sidebar-button"
data-testid="test-sidebar-button"
type="button"
>
<img
alt=""
id="sidebar-icon"
src="/static/res/ico/sidebar.png"
/>
</div>
</button>
</div>
</div>
</body>,
Expand All @@ -78,6 +84,7 @@ exports[`Sidebar should match shallow snapshot 1`] = `
<div
class="sidebar-dropdown"
data-testid="test-sidebar"
id="sidebar-dropdown"
>
<div>
<label
Expand Down Expand Up @@ -112,15 +119,20 @@ exports[`Sidebar should match shallow snapshot 1`] = `
Reset Selections
</button>
</div>
<div
<button
aria-controls="sidebar-dropdown"
aria-expanded="false"
aria-label="Course sidebar"
class="sidebar-button"
data-testid="test-sidebar-button"
type="button"
>
<img
alt=""
id="sidebar-icon"
src="/static/res/ico/sidebar.png"
/>
</div>
</button>
</div>
</div>,
"debug": [Function],
Expand Down
14 changes: 13 additions & 1 deletion style/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -489,13 +489,18 @@ 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;
z-index: 1;
}

.graph-control-button:hover {
background-color: var(--light-hover-color);
color: var(--color-white);
Expand Down Expand Up @@ -563,7 +568,9 @@ div.sidebar.collapsed {
}

.sidebar-button {
align-items: center;
background-color: var(--primary-color);
border: 0;
border-radius: 10px;
cursor: pointer;
display: flex;
Expand All @@ -574,6 +581,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;
Expand Down