table, menu: Show keyboard focus on DataTable and keep menu highlights on key presses - #3307
Merged
Merged
Conversation
…hts on key presses - `DataTable` is a Tab stop but drew nothing when focused. It now calls `focus_ring_style` on keyboard focus only (`last_input_was_keyboard`), since clicking a row focuses it too. - `MenuItemElement` styled hover with `group_hover` on its own group. GPUI computes an element's style before it registers the element's group, so that fallback ignores keyboard modality: after hovering an item and pressing `down`, both items were lit. Use `hover` instead. - `PopupMenu` cleared its highlight when a key press ended hover under a still pointer, so the next arrow key restarted from the top. Keep it. - Main-thread pixel tests for a menu, a list and a table. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.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.
Follow-up to #3299 / #3300, which noted that List / ListItem, Table and the menus are focusable or keyboard-navigable but don't go through
focus_style. This PR checks each one and fixes the two that were actually broken.Audit
With
focus_ring = falseandfocus_ring = true(same result in both unless stated):TableState)tab_stop(true))table_hoverrow bg, hidden while typing (GPUI)accent/table_activerow or cellaccenthighlight is the cursor. Bug 1: hover item A, pressdown→ A and B both lit. Bug 2: hover A, press a key with no binding → highlight goes out, nextdownrestarts at the top.Buttons, so Tab stops with the #3299 edge lineopenbg, and the popup is aPopupMenu(above)Button+ the PopupMenu fixListState's handle isn't a tab stop. A searchable list focuses its queryInput.list_active/accent) is the cursor, and it looks different from hoverlist_hover, hidden while typing (GPUI)Not changed, worth a separate decision: a List's selected row looks the same whether or not the list has focus, and
ListStateisn't a Tab stop. Native table views grey out the selection when unfocused. Doing that would change selection styling, which is out of scope here.Changes
DataTable: callsfocus_ring_stylewhen its handle is focused andwindow.last_input_was_keyboard(). That is GPUI'sfocus_visiblerule; it matters here because clicking a row also focuses the table.ring, plus the outer ring whenfocus_ring = true.bordered(false): the button: Show keyboard focus on borderless variants whenfocus_ringis off #3299 1px edge line.MenuItemElement:group_hoveron its own group →hover.group_hoveron the element's own group therefore takes thehover_state.groupfallback, which ignores keyboard modality, so the pointer's item stayed lit next to the keyboard cursor.hoveruses the hitbox, which GPUI already suppresses after a key press. Mouse-hover look is unchanged.group_nameis removed.PopupMenu: theon_hover(false)that clears the highlight is skipped when the last input was a key press. GPUI ends hover under a still pointer on any key press, so the highlight used to vanish and the next arrow key restarted from the top. A real pointer exit still clears it.Tests
crates/kit/tests/rendering.rs(main thread,harness = false, Metal).Capturenow takes its scale from the window, so it works for any window size.menu_highlight_is_the_keyboard_cursor: exactly one highlighted row after each step.Beta→[1].down→[2]. Fails with[1, 2]whengroup_hoveris restored.Betaagain →[1].x→[1]. Fails with[]without theon_hoverguard.down→[2].list_selection_is_the_keyboard_cursor:down→ only row 0 is lit, and its fill differs from the hover fill.[]when the selection isn't forwarded to the item. Nothing needed fixing for List, so this one locks existing behaviour.table_shows_keyboard_focus_only, forfocus_ring = falseandtrue:ringpixels on its top border. Withtrue, the outer band changes too.Note:
last_input_was_keyboardflips back when the mouse moves, so the table's ring disappears on mouse movement, the same as GPUI's ownfocus_visiblestyle. Switching modality already triggers a singlewindow.refresh()in GPUI, so this adds no idle redraws.