Skip to content

Stop inline grid editing when clicking empty grid space#4450

Merged
lbwexler merged 6 commits into
developfrom
grid-stop-editing-empty-click
Jun 24, 2026
Merged

Stop inline grid editing when clicking empty grid space#4450
lbwexler merged 6 commits into
developfrom
grid-stop-editing-empty-click

Conversation

@lbwexler

Copy link
Copy Markdown
Member

Fixes #4215.

Clicking empty grid space - to the right of the last column or below the last row - did not end an active inline edit. ag-Grid's stopEditingWhenCellsLoseFocus only fires when focus moves to another focusable element, and these clicks keep focus within the grid.

The grid container now handles onMouseDown and commits the active edit when the click lands directly on a structural "empty" element (.ag-body-viewport, .ag-center-cols-viewport, .ag-center-cols-container, .ag-row). Matching the target element itself - not its ancestors - ensures cells and editor popovers portaled into the grid viewport (e.g. the DateEditor calendar) are never treated as outside clicks.

Verified in Toolbox's inline-editing grid:

  • Clicking right of the last column commits the edit.
  • Clicking below the last row commits the edit.
  • The DateEditor calendar and SelectEditor dropdown continue to work normally.

lbwexler added 5 commits June 23, 2026 20:11
ag-Grid's stopEditingWhenCellsLoseFocus only commits an active cell edit when focus moves to another focusable element. Clicking empty grid space (to the right of the last column or below the last row) keeps focus within the grid, so the editor stayed open.

GridLocalModel now attaches a capture-phase mousedown listener to the grid view and commits any active edit when the click lands directly on a structural viewport/container background. It deliberately matches only the background element itself, not descendants, so editor popovers portaled into the grid viewport (e.g. DateEditor's calendar) are not treated as outside clicks.
Browser testing in Toolbox revealed the original selector missed the reported case: when a grid's last column flexes to fill, the row element spans the full viewport width, so the empty area to the right of the last cell is the .ag-row element itself (not the viewport). Added .ag-row to the selector.

Verified in Toolbox's inline-editing grid: clicking right of the last column and below the last row both commit the active edit, while the portaled DateEditor calendar and SelectEditor dropdown continue to work (their content is always a descendant, never a direct selector match).
The grid container is our own React element and already takes an onKeyDown prop, so the empty-space mousedown handler can ride the same path - dropping the viewRef-tracking reaction and manual add/removeEventListener. Uses bubble phase (the default React prop), which is sufficient: the handler only needs to act on clicks that reach the container, never to preempt ag-Grid.
@lbwexler lbwexler requested a review from saba-mo June 24, 2026 00:51
@lbwexler lbwexler merged commit 134c072 into develop Jun 24, 2026
2 checks passed
@lbwexler lbwexler deleted the grid-stop-editing-empty-click branch June 24, 2026 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Editing does not stop when clicking in empty grid space to the right of last column

1 participant