-
Notifications
You must be signed in to change notification settings - Fork 122
FE-1559: Adopt the worksheet focus layer in the Simulate view tables #9446
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kube
wants to merge
1
commit into
claude/fe-1545-sidebar-focus-layer
from
claude/simulate-tables-focus-layer
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@hashintel/petrinaut": patch | ||
| --- | ||
|
|
||
| The Simulate-mode lists (scenarios, experiments, optimizations, metrics) follow the worksheet keyboard flow: each table is one Tab stop, ArrowUp/ArrowDown walk the rows, and opening a drawer is select-first β the first click selects a row, a click on the selected row (or Enter/Space) opens it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
libs/@hashintel/petrinaut/src/ui/components/table.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| /** | ||
| * @vitest-environment jsdom | ||
| */ | ||
| import { | ||
| act, | ||
| cleanup, | ||
| fireEvent, | ||
| render, | ||
| screen, | ||
| } from "@testing-library/react"; | ||
| import { afterEach, describe, expect, it, vi } from "vitest"; | ||
|
|
||
| import { Table } from "./table"; | ||
|
|
||
| import type { TableColumn } from "./table"; | ||
|
|
||
| afterEach(cleanup); | ||
|
|
||
| interface Row { | ||
| id: string; | ||
| name: string; | ||
| } | ||
|
|
||
| const COLUMNS: TableColumn<Row>[] = [ | ||
| { id: "name", header: "Name", render: (row) => row.name }, | ||
| ]; | ||
|
|
||
| const ROWS: Row[] = [ | ||
| { id: "one", name: "First" }, | ||
| { id: "two", name: "Second" }, | ||
| { id: "three", name: "Third" }, | ||
| ]; | ||
|
|
||
| const rowShowing = (text: string): HTMLElement => { | ||
| const target = screen.getByText(text).closest("[role='row']"); | ||
| if (!(target instanceof HTMLElement)) { | ||
| throw new Error(`no row for ${text}`); | ||
| } | ||
| return target; | ||
| }; | ||
|
|
||
| const focusRow = (text: string): HTMLElement => { | ||
| const target = rowShowing(text); | ||
| act(() => { | ||
| target.focus(); | ||
| }); | ||
| expect(document.activeElement).toBe(target); | ||
| return target; | ||
| }; | ||
|
|
||
| describe("Table keyboard flow", () => { | ||
| it("is one tab stop whose rows the arrows walk", () => { | ||
| const { container } = render( | ||
| <Table | ||
| columns={COLUMNS} | ||
| rows={ROWS} | ||
| getRowId={(row) => row.id} | ||
| emptyLabel="Empty" | ||
| onRowSelect={() => {}} | ||
| />, | ||
| ); | ||
|
|
||
| expect(container.querySelectorAll("[tabindex='0']")).toHaveLength(1); | ||
|
|
||
| focusRow("First"); | ||
| fireEvent.keyDown(document.activeElement!, { key: "ArrowDown" }); | ||
| expect(document.activeElement).toBe(rowShowing("Second")); | ||
| fireEvent.keyDown(document.activeElement!, { key: "ArrowDown" }); | ||
| expect(document.activeElement).toBe(rowShowing("Third")); | ||
| fireEvent.keyDown(document.activeElement!, { key: "ArrowUp" }); | ||
| expect(document.activeElement).toBe(rowShowing("Second")); | ||
|
|
||
| expect(container.querySelectorAll("[tabindex='0']")).toHaveLength(1); | ||
| }); | ||
|
|
||
| it("activates select-first: the first click selects, the second opens", () => { | ||
| const onRowSelect = vi.fn(); | ||
| render( | ||
| <Table | ||
| columns={COLUMNS} | ||
| rows={ROWS} | ||
| getRowId={(row) => row.id} | ||
| emptyLabel="Empty" | ||
| onRowSelect={onRowSelect} | ||
| />, | ||
| ); | ||
|
|
||
| const row = rowShowing("Second"); | ||
| fireEvent.pointerDown(row); | ||
| focusRow("Second"); | ||
| fireEvent.click(row, { detail: 1 }); | ||
| expect(onRowSelect).not.toHaveBeenCalled(); | ||
|
|
||
| fireEvent.pointerDown(row); | ||
| fireEvent.click(row, { detail: 1 }); | ||
| expect(onRowSelect).toHaveBeenCalledWith(ROWS[1]); | ||
| }); | ||
|
|
||
| it("activates on Enter and Space", () => { | ||
| const onRowSelect = vi.fn(); | ||
| render( | ||
| <Table | ||
| columns={COLUMNS} | ||
| rows={ROWS} | ||
| getRowId={(row) => row.id} | ||
| emptyLabel="Empty" | ||
| onRowSelect={onRowSelect} | ||
| />, | ||
| ); | ||
|
|
||
| focusRow("First"); | ||
| fireEvent.keyDown(document.activeElement!, { key: "Enter" }); | ||
| expect(onRowSelect).toHaveBeenLastCalledWith(ROWS[0]); | ||
| fireEvent.keyDown(document.activeElement!, { key: " " }); | ||
| expect(onRowSelect).toHaveBeenCalledTimes(2); | ||
| }); | ||
|
|
||
| it("renders inert rows without onRowSelect", () => { | ||
| const { container } = render( | ||
| <Table | ||
| columns={COLUMNS} | ||
| rows={ROWS} | ||
| getRowId={(row) => row.id} | ||
| emptyLabel="Empty" | ||
| />, | ||
| ); | ||
|
|
||
| expect(container.querySelectorAll("[tabindex]")).toHaveLength(0); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interactive table keeps static table role
Medium Severity
Rows are now a single Tab stop with
ArrowUp/ArrowDownas the only way to reach the others, but the widget still usesrole="table"androle="cell". Screen readers treat that as a static table and intercept arrow keys, so assistive-tech users can land on the first row and cannot walk or activate the rest. The sibling spreadsheet that uses the same focus hooks exposesrole="grid"androle="gridcell"for this reason.Additional Locations (2)
libs/@hashintel/petrinaut/src/ui/components/table.tsx#L261-L266libs/@hashintel/petrinaut/src/ui/components/table.tsx#L231-L233Reviewed by Cursor Bugbot for commit 182e002. Configure here.