feat(base): make column headers keyboard-focusable as tab stops

This commit is contained in:
Philipinho
2026-06-15 03:13:27 +01:00
parent 16708cd7cc
commit 308079af8b
2 changed files with 17 additions and 0 deletions
@@ -60,6 +60,7 @@ export const GridHeaderCell = memo(function GridHeaderCell({
const { selectionCount } = useRowSelection(pageId);
const hasSelection = selectionCount > 0;
const editable = useBaseEditable();
const isHeaderInteractive = editable && !!property && !isRowNumber;
const [activePropertyMenu, setActivePropertyMenu] = useAtom(activePropertyMenuAtomFamily(pageId)) as unknown as [string | null, (val: string | null) => void];
const menuOpened = activePropertyMenu === header.column.id;
@@ -208,6 +209,9 @@ export const GridHeaderCell = memo(function GridHeaderCell({
return (
<div
ref={cellRef}
role={isRowNumber ? undefined : "columnheader"}
tabIndex={isHeaderInteractive ? 0 : undefined}
aria-haspopup={isHeaderInteractive ? "menu" : undefined}
className={`${classes.headerCell} ${isPinned ? classes.headerCellPinned : ""} ${hasSelection ? classes.hasSelection : ""}`}
style={{
...(isPinned
@@ -220,6 +224,12 @@ export const GridHeaderCell = memo(function GridHeaderCell({
resizeIntentRef.current = false;
}}
onClick={handleHeaderClick}
onKeyDown={(e) => {
if (e.key === "Enter" || e.key === " ") {
e.preventDefault();
handleHeaderClick();
}
}}
data-dragging={isDragging || undefined}
>
{isRowNumber ? (
@@ -269,6 +279,7 @@ export const GridHeaderCell = memo(function GridHeaderCell({
shadow="md"
width={260}
trapFocus
returnFocus
withinPortal
closeOnClickOutside
closeOnEscape
@@ -242,6 +242,12 @@
z-index: 1;
}
.headerCell:focus-visible {
outline: 2px solid var(--mantine-color-blue-5);
outline-offset: -2px;
z-index: 1;
}
.cellContent {
flex: 1;
min-width: 0;