Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EuiDataGrid][CRA] Fix header cell focus when moving columns left/right #7701

Merged
merged 3 commits into from
Apr 25, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,26 @@ export const EuiDataGridHeaderCellWrapper: FunctionComponent<
}, [index, setFocusedCell]);

const [isFocused, setIsFocused] = useState(false);
useEffect(() => {
onFocusUpdate([index, -1], (isFocused: boolean) => {
setIsFocused(isFocused);
});
}, [index, onFocusUpdate]);

useEffect(() => {
const updateFocus = (isFocused: Boolean, headerEl: HTMLDivElement | null) => {
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]);
}

useEffect(() => {
onFocusUpdate([index, -1], (isFocused: boolean) => {
setIsFocused(isFocused);
updateFocus(isFocused, headerEl);
});
}, [index, onFocusUpdate]);

useEffect(() => {
updateFocus(isFocused, headerEl);
}, [headerEl]);
cee-chen marked this conversation as resolved.
Show resolved Hide resolved

// 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
Loading