From f33f981578310dda0bd9078d94964083d504d63d Mon Sep 17 00:00:00 2001 From: Cee Chen Date: Fri, 16 Aug 2024 23:34:35 -0700 Subject: [PATCH] Attempt to simplify/clean up screen reader announcements --- .../__snapshots__/data_grid.test.tsx.snap | 224 +++++------------- .../data_grid_body_custom.test.tsx.snap | 56 ++--- .../data_grid_body_virtualized.test.tsx.snap | 56 ++--- .../data_grid_header_cell.test.tsx.snap | 28 +-- .../body/header/data_grid_header_cell.tsx | 142 ++++++----- 5 files changed, 172 insertions(+), 334 deletions(-) diff --git a/packages/eui/src/components/datagrid/__snapshots__/data_grid.test.tsx.snap b/packages/eui/src/components/datagrid/__snapshots__/data_grid.test.tsx.snap index d113adf4852..ac334d5b716 100644 --- a/packages/eui/src/components/datagrid/__snapshots__/data_grid.test.tsx.snap +++ b/packages/eui/src/components/datagrid/__snapshots__/data_grid.test.tsx.snap @@ -596,7 +596,7 @@ exports[`EuiDataGrid rendering renders additional toolbar controls 1`] = ` >
+
- -
-
+
- -
-
+
- -
-
+
- -
-
+
- -
-
+
- -
-
+
- -
-
+
- -
-
+
- -
-
+
- -
-
+
- -
-
+
- -
-
+
- -
-
+
{children}
{arrow} @@ -76,6 +75,10 @@ export const EuiDataGridHeaderCell: FunctionComponent { + setIsPopoverOpen((isOpen) => !isOpen); + }, []); + const closePopover = useCallback(() => setIsPopoverOpen(false), []); const popoverArrowNavigationProps = usePopoverArrowNavigation(); const columnActions = useMemo(() => { @@ -111,8 +114,6 @@ export const EuiDataGridHeaderCell: FunctionComponent { actionsButtonRef.current?.click(); }, []); - const [isActionsButtonFocused, setIsActionsButtonFocused] = - useState(false); const { sortingArrow, ariaSort, sortingScreenReaderText } = useSortingUtils({ @@ -129,10 +130,6 @@ export const EuiDataGridHeaderCell: FunctionComponent setIsPopoverOpen((isPopoverOpen) => !isPopoverOpen)} - onFocus={() => setIsActionsButtonFocused(true)} - onBlur={() => setIsActionsButtonFocused(false)} - aria-labelledby={`${contentAriaId} ${actionsAriaId}`} - aria-hidden={isActionsButtonFocused ? 'false' : 'true'} // prevent button being read on header cell focus - data-test-subj={`dataGridHeaderCellActionButton-${id}`} - > -
- -
- - - + const actionsButtonAriaLabel = useEuiI18n( + 'euiDataGridHeaderCell.actionsButtonAriaLabel', + '{title}. Click to view column header actions.', + { title } + ); + const actionsEnterKeyInstructions = useEuiI18n( + 'euiDataGridHeaderCell.actionsEnterKeyInstructions', + "Press the Enter key to view this column's actions" ); return ( @@ -185,54 +165,68 @@ export const EuiDataGridHeaderCell: FunctionComponent - {column.isResizable !== false && width != null ? ( - - ) : null} - - {!showColumnActions ? ( - <> - - {children} - - {sortingScreenReaderText && ( - -

{sortingScreenReaderText}

-
- )} - - ) : ( + {(hasFocusTrap) => ( <> - + {column.isResizable !== false && width != null ? ( + + ) : null} + + {children} - setIsPopoverOpen(false)} - {...popoverArrowNavigationProps} - > - - + + {showColumnActions && ( + +
+ +
+ + } + isOpen={isPopoverOpen} + closePopover={closePopover} + {...popoverArrowNavigationProps} + > + +
+ )} )}