Repository navigation
fix(kraefte): keep keyboard focus on a clicked STATUS combo in the grid - #711
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #536
Root cause
It is the DataGrid, as the issue suspected. In Avalonia.Controls.DataGrid 12.1.2,
DataGridCellregisters its PointerPressed handler as a class handler withhandledEventsToo: true, and on a left press it callsOwningGrid.Focus()whenever the grid is a tab stop: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 withhandledEventsToo, so it runs after the cell's handler. It puts focus back on the focusable control the press landed on. What stays the same:No DataGrid internals are touched.
Verification
ForcesStatusComboFocusTests(headless):mainwith "Expected focus on ComboBox, but it is on DataGrid 'ForcesGrid'".docs/samples/uebung.fwincident, demo Unit-Status). Results read back from the file withsqlite3:make clean ciandmake format-checkpass 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