From e0a1584762f0fa9ef1296d5e999bc3a69a118996 Mon Sep 17 00:00:00 2001 From: Cee Chen Date: Thu, 4 Jan 2024 15:24:30 -0800 Subject: [PATCH] Add screen reader text for Enter key behavior --- changelogs/upcoming/7448.md | 1 + .../__snapshots__/data_grid.test.tsx.snap | 48 +++++++++++++++++++ .../data_grid_body_custom.test.tsx.snap | 8 ++++ .../data_grid_body_virtualized.test.tsx.snap | 4 ++ .../data_grid_cell.test.tsx.snap | 2 + .../datagrid/body/cell/data_grid_cell.tsx | 9 ++++ .../datagrid/body/cell/focus_utils.test.tsx | 17 +++++++ .../datagrid/body/cell/focus_utils.tsx | 13 +++++ 8 files changed, 102 insertions(+) diff --git a/changelogs/upcoming/7448.md b/changelogs/upcoming/7448.md index bc8e1e3eecc7..ac918fe177bb 100644 --- a/changelogs/upcoming/7448.md +++ b/changelogs/upcoming/7448.md @@ -4,3 +4,4 @@ - Headers are now always navigable by arrow key, regardless of whether the header cells contain interactive content - Non-expandable cells containing any amount of interactive content now must be entered via Enter or F2 keypress - Expandable cells continue to be toggled via Enter or F2 keypress +- `EuiDataGrid` now provides a direct screen reader hint for Enter key behavior for expandable & interactive cells diff --git a/src/components/datagrid/__snapshots__/data_grid.test.tsx.snap b/src/components/datagrid/__snapshots__/data_grid.test.tsx.snap index 4327dfe50c4c..e0ec7f6aa4aa 100644 --- a/src/components/datagrid/__snapshots__/data_grid.test.tsx.snap +++ b/src/components/datagrid/__snapshots__/data_grid.test.tsx.snap @@ -725,6 +725,8 @@ exports[`EuiDataGrid rendering renders additional toolbar controls 1`] = ` > - A, column 1, row 1 + - + Press the Enter key to expand this cell.

- B, column 2, row 1 + - + Press the Enter key to expand this cell.

- A, column 1, row 2 + - + Press the Enter key to expand this cell.

- B, column 2, row 2 + - + Press the Enter key to expand this cell.

- A, column 1, row 3 + - + Press the Enter key to expand this cell.

- B, column 2, row 3 + - + Press the Enter key to expand this cell.

- A, column 2, row 1 + - + Press the Enter key to expand this cell.

- B, column 3, row 1 + - + Press the Enter key to expand this cell.

- A, column 2, row 2 + - + Press the Enter key to expand this cell.

- B, column 3, row 2 + - + Press the Enter key to expand this cell.

- A, column 2, row 3 + - + Press the Enter key to expand this cell.

- B, column 3, row 3 + - + Press the Enter key to expand this cell.

- A, column 1, row 1 + - + Press the Enter key to expand this cell.

- B, column 2, row 1 + - + Press the Enter key to expand this cell.

- A, column 1, row 2 + - + Press the Enter key to expand this cell.

- B, column 2, row 2 + - + Press the Enter key to expand this cell.

- A, column 1, row 3 + - + Press the Enter key to expand this cell.

- B, column 2, row 3 + - + Press the Enter key to expand this cell.

- A, column 1, row 1 + - + Press the Enter key to expand this cell.

- B, column 2, row 1 + - + Press the Enter key to expand this cell.

- A, column 1, row 2 + - + Press the Enter key to expand this cell.

- B, column 2, row 2 + - + Press the Enter key to expand this cell.

- A, column 1, row 3 + - + Press the Enter key to expand this cell.

- B, column 2, row 3 + - + Press the Enter key to expand this cell.

- columnA, column 1, row 1 + - + Press the Enter key to expand this cell.

- columnB, column 2, row 1 + - + Press the Enter key to expand this cell.

- columnA, column 1, row 2 + - + Press the Enter key to expand this cell.

- columnB, column 2, row 2 + - + Press the Enter key to expand this cell.

- columnA, column 1, row 1 + - + Press the Enter key to expand this cell.

- columnB, column 2, row 1 + - + Press the Enter key to expand this cell.

- someColumn, column 1, row 1 + - + Press the Enter key to expand this cell.

+ {cellActions && ( + <> + {' - '} + + + )}

); diff --git a/src/components/datagrid/body/cell/focus_utils.test.tsx b/src/components/datagrid/body/cell/focus_utils.test.tsx index 1dcbccacb071..a35407d00dce 100644 --- a/src/components/datagrid/body/cell/focus_utils.test.tsx +++ b/src/components/datagrid/body/cell/focus_utils.test.tsx @@ -124,6 +124,23 @@ describe('HandleInteractiveChildren', () => { }); describe('FocusTrappedChildren', () => { + it('renders a screen reader hint', () => { + const cell = getCellWithInteractiveChildren(); + const { container } = render(); + expect(container.childNodes[1]).toMatchInlineSnapshot(` +
+

+ - + Press the Enter key to interact with this cell's contents. +

+
+ `); + }); + describe('on enter', () => { it('enables the focus trap, all interactive children, and moves focus to the first focusable child', () => { const cell = getCellWithInteractiveChildren(); diff --git a/src/components/datagrid/body/cell/focus_utils.tsx b/src/components/datagrid/body/cell/focus_utils.tsx index 77b655eb6cb5..4d425244f839 100644 --- a/src/components/datagrid/body/cell/focus_utils.tsx +++ b/src/components/datagrid/body/cell/focus_utils.tsx @@ -17,6 +17,8 @@ import { tabbable } from 'tabbable'; import { keys } from '../../../../services'; import { EuiFocusTrap } from '../../../focus_trap'; +import { EuiScreenReaderOnly } from '../../../accessibility'; +import { EuiI18n } from '../../../i18n'; /** * This internal utility component is used by all cells, both header and body/footer cells. @@ -120,6 +122,17 @@ export const FocusTrappedChildren: FunctionComponent< clickOutsideDisables={true} > {children} + + +

+ {' - '} + +

+
); };