fix(datagrid): keep keyboard focus across the grid filter flow (#1490)#1492
Merged
Conversation
This was referenced May 29, 2026
Merged
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.
Part of #1490 (keyboard, focus, and accessibility).
Makes the reported grid -> filter -> grid flow work without the mouse, the native way. From the audit, the breaks were all at the SwiftUI filter panel / AppKit grid boundary.
What changed
TableViewCoordinator.focusGrid()andMainContentCoordinator.focusActiveGrid()route through the existingdataGridAttach(tableViewCoordinator:)registration (no new references). Called after Apply, Unset, removing the last filter row, and Escape..keyboardShortcut(.defaultAction), and the panel is a.focusSection()so the default action and Tab grouping scope to the panel.FilterValueTextField,cancelOperationnow consumes the event only when the suggestion popover is open; otherwise it callsonCancel, which closes the panel and returns focus to the grid..onExitCommandcovers the case where focus is on a SwiftUI control in the panel.DispatchQueue.main.async { makeFirstResponder }plus a UUID nil-poke. It is now a proper AppKit first-responder bridge: synchronousmakeFirstResponderinupdateNSView/viewDidMoveToWindow, withbecomeFirstResponder/resignFirstResponderwriting the binding back so it always reflects the real first responder.accessibilityValueon the column and operator pickers, label + button/selected traits on suggestion-dropdown rows, and the status-bar Filters tooltip now reads the live shortcut instead of a hardcoded "⇧⌘F".Design notes
@FocusStatefor the value field (the audit suggested it) and chose a plainBinding<UUID?>bridge instead.@FocusStatebound to a value with no SwiftUI.focused()target (anNSViewRepresentabletext field is not one) gets reset to nil by SwiftUI's focus engine, which makes focus-into-field flaky. The manual first-responder bridge is the correct, reliable pattern for an AppKitNSTextField, and it still removes the async/nil-poke hacks..defaultAction,.cancelAction/onExitCommand,.focusSection, NSResponder first responder).Deferred (follow-up, on purpose)
SQLEditorCoordinatorre-focusing the editor ~50ms after a tab appears; a guarded grid auto-focus would either be a no-op or lose a focus race, which would be a timing hack. It should land with the SQL-editor focus guard (tracked in the audit's focus-infrastructure notes)..focusSection()keeps focus from leaking out; deeper Tab ordering is a separate pass.Out of scope here (separate surfaces in #1490): toolbar
.focusable(false), overlay-editor focus ring, menu-picker Tab reachability without Full Keyboard Access.Verify
Build the branch, then keyboard-only with a table open and focus in the grid:
Focus/responder behavior is not unit-testable here (consistent with the codebase); verification is manual.