Skip to content

fix(kraefte): keep keyboard focus on a clicked STATUS combo in the grid - #711

Merged
DeepDiver1975 merged 1 commit into
mainfrom
fix/536-status-combo-focus
Oct 21, 2026
Merged

DeepDiver1975 merged 1 commit into
mainfrom
fix/536-status-combo-focus

Conversation

@DeepDiver1975

@DeepDiver1975 DeepDiver1975 commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #536

Root cause

It is the DataGrid, as the issue suspected. In Avalonia.Controls.DataGrid 12.1.2, DataGridCell registers its PointerPressed handler as a class handler with handledEventsToo: true, and on a left press it calls OwningGrid.Focus() whenever the grid is a tab stop:

PointerPressedEvent.AddClassHandler<DataGridCell>((x, e) => x.DataGridCell_PointerPressed(e), handledEventsToo: true);
// DataGridCell_PointerPressed:
if (e.GetCurrentPoint(this).Properties.IsLeftButtonPressed)
{
    if (OwningGrid.IsTabStop) { OwningGrid.Focus(); }

So the click that focused the STATUS combo handed focus straight to the grid, before the list had even opened. Whatever happened next (pick, Escape) left focus on the grid, and Down moved its cell cursor. This is independent of saving and rebuilding, which matches the issue's Escape control. The Bemerkung TextBox beside it is not affected: a TextBox takes focus back after the cell has taken it.

The fix

A small view-only behavior, GridCellFocus, set on the Kräfte grid. It handles PointerPressed on the grid, bubbling with handledEventsToo, so it runs after the cell's handler. It puts focus back on the focusable control the press landed on. What stays the same:

  • The row is still selected; the cell did that first.
  • A press on a cell's text still focuses the grid, which arrow navigation between rows needs.
  • Buttons are left out: a row's buttons keep handing focus to the grid as before.

No DataGrid internals are touched.

Verification

  • ForcesStatusComboFocusTests (headless):
    • Click a middle row's STATUS combo, then Escape, then Down: the status steps and the next row is untouched. This fails on main with "Expected focus on ComboBox, but it is on DataGrid 'ForcesGrid'".
    • Guards: clicking the Bemerkung keeps it focused, and clicking a text cell still focuses the grid and selects the row.
  • Real app on a private Xvfb display (desktop build, real X11 popups, docs/samples/uebung.fwincident, demo Unit-Status). Results read back from the file with sqlite3:
    • Before: open row 2's STATUS, Escape, Down. The cursor moves to row 3 and row 2 stays "Im Einsatz".
    • After, same steps: row 2 becomes "Einsatzbereit über Funk", stays selected and keeps the focus ring.
    • After, probe 1 from the issue: pick "Auf Anfahrt" on row 3 with the mouse, then Down. The status becomes "Bereitstellungsraum".

Before: Escape then Down moves the grid cursor to row 3
After: Escape then Down steps row 2's status

make clean ci and make format-check pass locally.

The UI itself does not change; the screenshots above only show the focus ring and the stepped value.

No file-format or sync change.

🤖 Generated with Claude Code

DataGridCell handles PointerPressed with a class handler that runs even
for a press the control under the pointer already handled, and on a left
press it calls OwningGrid.Focus(). The click that focused a row's STATUS
combo therefore handed focus straight to the grid, and once its list
closed, Down moved the grid's cell cursor to the next row instead of
stepping the status. No save or rebuild is involved: open and Escape
showed the same.

GridCellFocus handles PointerPressed on the grid after the cell's handler
and puts focus back on the control the press landed on. The row is still
selected, a press on a cell's text still focuses the grid, and buttons
keep their old behaviour.

Fixes #536

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Thomas Müller <1005065+DeepDiver1975@users.noreply.github.com>
@DeepDiver1975
DeepDiver1975 merged commit 058273e into main Oct 21, 2026
11 checks passed
@DeepDiver1975
DeepDiver1975 deleted the fix/536-status-combo-focus branch October 21, 2026 07:13
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.

Kräfte: the STATUS combo in a grid row loses keyboard focus when its popup closes, so Down moves the grid cursor

1 participant