fix(base): select grid cell on mousedown to avoid stale focus ring flash

The focus ring is gated on the grid having DOM focus (.bodyGrid:focus .cellFocused), but the focusedCell atom is never cleared when the grid blurs. Clicking outside hides the ring via the :focus gate while the atom still points at the old cell.

Selection was committed on click (mouseup), while the grid receives focus on mousedown. Clicking a new cell re-focused the grid before the atom updated, briefly painting the ring on the previously selected cell. Commit selection on mousedown so the atom updates in the same event that grants focus, before the browser paints.
This commit is contained in:
Philipinho
2026-06-16 00:30:54 +01:00
parent 8cce2ffca0
commit dc63ed8dee
2 changed files with 18 additions and 0 deletions
@@ -91,6 +91,14 @@ export const GridCell = memo(function GridCell({
setEditingCell({ rowId, propertyId: property.id });
}, [property, isRowNumber, rowId, readOnly, setEditingCell, setActiveFormulaEditor]);
const handleMouseDown = useCallback(
(e: React.MouseEvent<HTMLDivElement>) => {
if (!property || e.button !== 0) return;
setFocusedCell({ rowId, propertyId: property.id });
},
[property, rowId, setFocusedCell],
);
const handleClick = useCallback(
(e: React.MouseEvent<HTMLDivElement>) => {
if (!property) return;
@@ -190,6 +198,7 @@ export const GridCell = memo(function GridCell({
: undefined
}
onClick={handleClick}
onMouseDown={handleMouseDown}
onDoubleClick={handleDoubleClick}
>
<CellComponent
@@ -44,6 +44,14 @@ export const RowNumberCell = memo(function RowNumberCell({
),
);
const handleCellMouseDown = useCallback(
(e: React.MouseEvent<HTMLDivElement>) => {
if (e.button !== 0) return;
setFocusedCell({ rowId, propertyId: "__row_number" });
},
[rowId, setFocusedCell],
);
const handleCellClick = useCallback(
(e: React.MouseEvent<HTMLDivElement>) => {
setFocusedCell({ rowId, propertyId: "__row_number" });
@@ -77,6 +85,7 @@ export const RowNumberCell = memo(function RowNumberCell({
: undefined
}
onClick={handleCellClick}
onMouseDown={handleCellMouseDown}
>
<div className={classes.rowNumberCellInner}>
{editable && (