Skip to content

[EuiDataGrid] On pagination, focus is not properly restored to a valid data grid cell #5577

Closed

Description

@cee-chen

Caught by @miukimiu in #5561 (review):

When clicking a pagination number the .euiDataGridBody outline appears and we see a black border on top of the pagination.
Screenshot 2022-01-28 at 12 55 00

This is occuring in Chrome, Firefox, and Safari - Safari just makes it more obvious because of its black outline.

Repro steps

Problem

This issue occurs due to the aria-controls property on our pagination component:

<div className="euiDataGrid__pagination">
<EuiTablePagination
aria-controls={controls}

Which, in our pagination component, we have some extra code that attempts to focus back onto the passed element, in this case our data grid:

if (ariaControls) {
const controlledElement = document.getElementById(ariaControls);
if (controlledElement) {
controlledElement.focus();
}
}

However, our data grid body has conditional tabIndex/onFocus logic which pagination does not know about:

const focusProps = useMemo<FocusProps>(
() =>
isFocusedCellInView
? {
// FireFox allows tabbing to a div that is scrollable, while Chrome does not
tabIndex: -1,
}
: {
tabIndex: 0,
onFocus: (e) => {

Solution

The solution here is to fire a manual setFocusedCell() API call onChangePage (which incidentally now also takes care of scrolling back upwards in the grid) instead of relying on aria-controls to focus onto the grid, due to our grid's complex focus behaivor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions