Skip to content

Commit 3aaf6f5

Browse files
committed
refactor(SelectView): enhance accessibility and update test roles
- Introduced a unique ID for the dropdown in SelectView to improve accessibility. - Updated aria attributes for better screen reader support, including aria-controls and aria-label. - Changed test role assertions from "combobox" to "button" for consistency with the updated component structure in TaskListHeader and TaskContextMenu tests. - Ensured all related tests reflect these changes, enhancing clarity and maintainability.
1 parent c38bec3 commit 3aaf6f5

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

packages/web/src/components/SelectView/SelectView.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ export const SelectView = ({
9696
{ route: ROOT_ROUTES.ROOT, label: "Week", view: "Week" as const },
9797
];
9898

99+
const dropdownId = "view-select-dropdown";
100+
99101
return (
100102
<div className="relative">
101103
<button
@@ -107,6 +109,8 @@ export const SelectView = ({
107109
}
108110
aria-expanded={isOpen}
109111
aria-haspopup="listbox"
112+
aria-controls={isOpen ? dropdownId : undefined}
113+
aria-label={`Select view, currently ${currentView}`}
110114
>
111115
<span>{buttonLabel}</span>
112116
<svg
@@ -141,6 +145,7 @@ export const SelectView = ({
141145
}
142146
},
143147
})}
148+
id={dropdownId}
144149
data-testid="view-select-dropdown"
145150
className="inset-inline-end-0 absolute top-full z-50 mt-1 min-w-[140px] rounded border border-gray-600 bg-gray-800 py-1 shadow-lg"
146151
role="listbox"

packages/web/src/views/Day/components/ContextMenu/TaskContextMenu.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ describe("TaskContextMenu", () => {
152152
});
153153

154154
// Click outside the menu (on the heading button)
155-
const headingButton = screen.getByRole("combobox");
155+
const headingButton = screen.getByRole("button", { name: /select view/i });
156156
await act(async () => {
157157
await user.click(headingButton);
158158
});

packages/web/src/views/Day/components/TaskList/TaskList.header.test.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ describe("TaskListHeader", () => {
3737
it("should render the today heading with current date", () => {
3838
renderTaskList();
3939

40-
const headingButton = screen.getByRole("combobox");
40+
const headingButton = screen.getByRole("button", { name: /select view/i });
4141
const subheading = screen.getByRole("heading", { level: 3 });
4242
expect(headingButton).toBeInTheDocument();
4343
expect(subheading).toBeInTheDocument();
@@ -51,7 +51,7 @@ describe("TaskListHeader", () => {
5151

5252
// Verify initial heading shows correct date
5353
const expectedInitialDate = format(testDate);
54-
const headingButton = screen.getByRole("combobox");
54+
const headingButton = screen.getByRole("button", { name: /select view/i });
5555
expect(headingButton).toHaveTextContent(expectedInitialDate);
5656

5757
// Click the next day button
@@ -73,7 +73,7 @@ describe("TaskListHeader", () => {
7373

7474
// Verify initial heading shows correct date
7575
const expectedInitialDate = format(testDate);
76-
const headingButton = screen.getByRole("combobox");
76+
const headingButton = screen.getByRole("button", { name: /select view/i });
7777
expect(headingButton).toHaveTextContent(expectedInitialDate);
7878

7979
// Click the previous day button
@@ -93,7 +93,7 @@ describe("TaskListHeader", () => {
9393
const testDate = createUtcDate("2025-01-15T12:00:00Z");
9494
const { user } = renderTaskList({}, testDate);
9595

96-
const headingButton = screen.getByRole("combobox");
96+
const headingButton = screen.getByRole("button", { name: /select view/i });
9797
const nextButton = screen.getByRole("button", { name: "Next day" });
9898
const prevButton = screen.getByRole("button", { name: "Previous day" });
9999

@@ -129,7 +129,7 @@ describe("TaskListHeader", () => {
129129
const { user } = renderTaskList({}, testDate);
130130

131131
const initialDate = format(testDate);
132-
const headingButton = screen.getByRole("combobox");
132+
const headingButton = screen.getByRole("button", { name: /select view/i });
133133
const nextButton = screen.getByRole("button", { name: "Next day" });
134134

135135
// Verify initial date is end of January
@@ -172,7 +172,7 @@ describe("TaskListHeader", () => {
172172
const { user } = renderTaskList({}, testDate);
173173

174174
const expectedInitialDate = format(testDate);
175-
const headingButton = screen.getByRole("combobox");
175+
const headingButton = screen.getByRole("button", { name: /select view/i });
176176
const goToTodayButton = screen.getByRole("button", { name: "Go to today" });
177177

178178
// Verify initial heading shows the test date
@@ -227,7 +227,7 @@ describe("TaskListHeader - Timezone Handling", () => {
227227
// Should show local date (Oct 19), not UTC date (Oct 20)
228228
const localDate = utcDayjs.local();
229229
const expectedHeading = localDate.format(DAY_HEADING_FORMAT);
230-
const headingButton = screen.getByRole("combobox");
230+
const headingButton = screen.getByRole("button", { name: /select view/i });
231231
const subheading = screen.getByRole("heading", { level: 3 });
232232

233233
expect(headingButton).toHaveTextContent(expectedHeading);

0 commit comments

Comments
 (0)