Skip to content

Commit

Permalink
[EuiDataGrid][CRA] Fix header cell focus when moving columns left/rig…
Browse files Browse the repository at this point in the history
…ht (elastic#7701)

Co-authored-by: Cee Chen <[email protected]>
  • Loading branch information
2 people authored and mgadewoll committed May 3, 2024
1 parent 106af4a commit b8813fb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
2 changes: 1 addition & 1 deletion changelogs/upcoming/7698.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
**Bug fixes**

- Fixed a focus bug with `EuiDataGrid`s with `leadingControlColumns` when moving columns to the left/right
- Fixed a focus bug with `EuiDataGrid`s with `leadingControlColumns` when moving columns to the left/right ([#7701](https://github.com/elastic/eui/pull/7701))
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,14 @@ export const EuiDataGridHeaderCellWrapper: FunctionComponent<
useEffect(() => {
onFocusUpdate([index, -1], (isFocused: boolean) => {
setIsFocused(isFocused);
});
}, [index, onFocusUpdate]);

useEffect(() => {
if (isFocused && headerEl) {
// Only focus the cell if not already focused on something in the cell
if (!headerEl.contains(document.activeElement)) {
headerEl.focus();
if (isFocused && headerEl) {
// Only focus the cell if not already focused on something in the cell
if (!headerEl.contains(document.activeElement)) {
headerEl.focus();
}
}
}
}, [isFocused, headerEl]);
});
}, [index, onFocusUpdate, headerEl]);

// For cell headers with actions, auto-focus into the button instead of the cell wrapper div
// The button text is significantly more useful to screen readers (e.g. contains sort order & hints)
Expand Down

0 comments on commit b8813fb

Please sign in to comment.