Skip to content

Commit e67ef5d

Browse files
authored
[EuiDataGrid] Simplify & DRY out cell/header focus (#7448)
1 parent 7f161ae commit e67ef5d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1802
-1307
lines changed

changelogs/upcoming/7448.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
**Accessibility**
2+
3+
- `EuiDataGrid`'s keyboard/screenreader experience has been tweaked to be more consistent for varying complex data:
4+
- Headers are now always navigable by arrow key, regardless of whether the header cells contain interactive content
5+
- Non-expandable cells containing any amount of interactive content now must be entered via Enter or F2 keypress
6+
- Expandable cells continue to be toggled via Enter or F2 keypress
7+
- `EuiDataGrid` now provides a direct screen reader hint for Enter key behavior for expandable & interactive cells

src-docs/src/views/datagrid/cells_popovers/datagrid_cells_example.js

Lines changed: 29 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
import React, { Fragment } from 'react';
1+
import React from 'react';
22
import { Link } from 'react-router-dom';
33

44
import { GuideSectionTypes } from '../../../components';
55
import {
66
EuiDataGrid,
77
EuiCode,
88
EuiCallOut,
9-
EuiBasicTable,
10-
EuiSpacer,
119
EuiText,
1210
EuiListGroupItem,
1311
} from '../../../../../src';
@@ -64,7 +62,7 @@ export const DataGridCellsExample = {
6462
],
6563
title: 'Cell actions',
6664
text: (
67-
<Fragment>
65+
<>
6866
<p>
6967
In addition to making a cell expandable, you can add more custom
7068
actions by setting <EuiCode>columns.cellActions</EuiCode>. These
@@ -97,7 +95,7 @@ export const DataGridCellsExample = {
9795
<EuiCode>cellAction</EuiCode> each, while the country column
9896
provides 2 <EuiCode>cellAction</EuiCode>s.
9997
</p>
100-
</Fragment>
98+
</>
10199
),
102100
props: {
103101
EuiDataGrid,
@@ -157,7 +155,7 @@ export const DataGridCellsExample = {
157155
},
158156
],
159157
text: (
160-
<Fragment>
158+
<>
161159
<p>
162160
<strong>EuiDataGrid</strong> tracks and manages complicated focus
163161
state management based upon the content of the individual inner
@@ -166,93 +164,44 @@ export const DataGridCellsExample = {
166164
<h3>Initial focus</h3>
167165
<ul>
168166
<li>
169-
When tabbing to the grid before it has received focus, the first
170-
cell of either the header (if it is interaction) or first content
167+
When tabbing to the grid before it has received focus, the header
171168
cell is focused.
172169
</li>
173-
<li>Datagrid does not auto-focus on mount / page load</li>
174170
<li>
175-
When removing focus from the grid and then returning, the last
176-
focused cell remains focused.
171+
When tabbing away from the grid and then returning, the last
172+
focused cell will regain focus.
173+
</li>
174+
<li>
175+
If the last focused cell has been scrolled out of view, the first
176+
header cell receives focus instead.
177177
</li>
178178
</ul>
179179
<h3>Click and key events</h3>
180180
<ul>
181181
<li>
182-
Clicking on an interactive cell (not its content) should focus on
183-
the cell, or if it has only one interactive element the focus
184-
should shift to the element.
182+
Clicking on an interactive cell or its content should focus on the
183+
cell.
184+
</li>
185+
<li>
186+
The up, down, left, and right arrow keys can be pressed to
187+
navigate between cells.
188+
</li>
189+
<li>
190+
For expandable cells, either the Enter or F2 keys can be pressed
191+
interchangeably to toggle the cell popover. The Escape key will
192+
close the popover.
185193
</li>
186194
<li>
187-
Clicking on an interactive element within a cell the focus should
188-
always remain on that element, not shift to the cell or another
189-
element unless a subsequent user action changes it.
195+
For non-expandable cells with interactive content, either the
196+
Enter or F2 keys can be pressed to enter a focus trap, allowing
197+
users to Tab between the cell's content. The Escape key will exit
198+
the cell trap.
190199
</li>
191200
<li>
192-
Enter or F2 can be used interchangeably to enter inner cell focus
193-
if the logic below allows it.
201+
For non-expandable cells with no interactive content, the cell
202+
alone will receive focus, with no inner content action.
194203
</li>
195204
</ul>
196-
<h3>
197-
The content and expandability of the cells dictate the focus target
198-
of the cell
199-
</h3>
200-
<p>
201-
The following combinations of focus are maintained to provide for a
202-
good balance between accessibility and ease of use while navigating
203-
the grid with your keyboard.
204-
</p>
205-
<EuiBasicTable
206-
columns={[
207-
{
208-
field: 'expandable',
209-
name: 'Expandablity',
210-
},
211-
{
212-
field: 'contents',
213-
name: 'Cell contains',
214-
},
215-
{
216-
field: 'result',
217-
name: 'Resulting focus',
218-
width: '50%',
219-
mobileOptions: {
220-
width: '100%',
221-
},
222-
},
223-
]}
224-
items={[
225-
{
226-
id: '1',
227-
expandable: 'Not expandable',
228-
contents: 'No interactive elements',
229-
result:
230-
'Cell alone receives the focus, with no possible inner focus action',
231-
},
232-
{
233-
id: '2',
234-
expandable: 'Not expandable',
235-
contents: 'Single interactive element',
236-
result:
237-
'The single inner element within the cell receives focus',
238-
},
239-
{
240-
id: '3',
241-
expandable: 'Not expandable',
242-
contents: 'Multiple interactive elements',
243-
result:
244-
'The cell will allow a non-expanding focus trap on Enter keyDown',
245-
},
246-
{
247-
id: '4',
248-
expandable: 'Is expandable',
249-
contents:
250-
'Any combination of interactive / non-interactive elements',
251-
result: 'The cell will focus on the expansion action',
252-
},
253-
]}
254-
/>
255-
<EuiSpacer />
256205
<EuiCallOut
257206
color="warning"
258207
title="Don't turn off cell expansion when the width of the column is unknown"
@@ -265,7 +214,7 @@ export const DataGridCellsExample = {
265214
when you cannot control the width can lead to hidden focus because
266215
the content is truncated.
267216
</EuiCallOut>
268-
</Fragment>
217+
</>
269218
),
270219
demo: <DataGridFocus />,
271220
},

src-docs/src/views/datagrid/cells_popovers/focus.js

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,7 @@ export default () => {
5656
const columns = [
5757
{
5858
id: 'no-interactives not expandable',
59-
display: (
60-
<EuiFlexGroup alignItems="center" gutterSize="xs" responsive={false}>
61-
<EuiFlexItem grow={false}>
62-
<EuiButtonIcon
63-
aria-label="column settings"
64-
iconType="gear"
65-
onClick={() => {}}
66-
/>
67-
</EuiFlexItem>
68-
<EuiFlexItem grow={false}>
69-
<EuiBadge>0 interactive</EuiBadge>
70-
</EuiFlexItem>
71-
</EuiFlexGroup>
72-
),
59+
display: <EuiBadge>0 interactive</EuiBadge>,
7360
isExpandable: false,
7461
actions: false,
7562
},
@@ -95,21 +82,23 @@ export default () => {
9582
},
9683
{
9784
id: 'one-interactive not expandable',
98-
display: <EuiBadge>1 interactive</EuiBadge>,
85+
display: (
86+
<EuiFlexGroup alignItems="center" gutterSize="xs" responsive={false}>
87+
<EuiButtonIcon
88+
aria-label="column settings"
89+
iconType="gear"
90+
onClick={() => {}}
91+
/>
92+
<EuiBadge>1 interactive</EuiBadge>
93+
</EuiFlexGroup>
94+
),
9995
isExpandable: false,
10096
actions: false,
10197
},
10298
{
10399
id: 'one-interactives is expandable',
104100
display: (
105101
<EuiFlexGroup alignItems="center" gutterSize="xs" responsive={false}>
106-
<EuiFlexItem grow={false}>
107-
<EuiButtonIcon
108-
aria-label="column settings"
109-
iconType="gear"
110-
onClick={() => {}}
111-
/>
112-
</EuiFlexItem>
113102
<EuiFlexItem grow={false}>
114103
<EuiToken
115104
iconType="expandMini"
@@ -128,7 +117,21 @@ export default () => {
128117
},
129118
{
130119
id: 'two-interactives not expandable',
131-
display: <EuiBadge>2 interactive</EuiBadge>,
120+
display: (
121+
<EuiFlexGroup alignItems="center" gutterSize="xs" responsive={false}>
122+
<EuiButtonIcon
123+
aria-label="column settings"
124+
iconType="gear"
125+
onClick={() => {}}
126+
/>
127+
<EuiButtonIcon
128+
aria-label="column settings"
129+
iconType="gear"
130+
onClick={() => {}}
131+
/>
132+
<EuiBadge>2 interactive</EuiBadge>
133+
</EuiFlexGroup>
134+
),
132135
isExpandable: false,
133136
actions: false,
134137
},

0 commit comments

Comments
 (0)