feat(model-picker): arrow-key navigation and Enter-to-select#2952
feat(model-picker): arrow-key navigation and Enter-to-select#2952Sanjays2402 wants to merge 2 commits into
Conversation
The model picker has a search input but no keyboard navigation. After typing a filter you still have to take your hand off the keyboard to click the row you want. Adds ArrowDown/ArrowUp to move a highlight through the visible rows and Enter to pick the highlighted (or first) row. Escape still closes the dropdown. The matcher keeps the existing String.includes behavior — fuzzy matching and match highlighting are separate follow-ups suggested in nesquena#2791. Closes nesquena#2791
Heads up: duplicate of #2953You opened #2953 54 seconds after this one with the same scope (closes #2791, same
Both work against the rendered DOM at row.onclick=()=>selectModelFromDropdown(m.value);I'll do the substantive review on this one since it landed first; please consider closing #2953 (or rebasing #2953 onto whichever variant you prefer and closing this one). Code referenceThe added handler at _si.addEventListener('keydown',e=>{
if(e.key==='Escape'){closeModelDropdown();return;}
if(e.key==='ArrowDown'||e.key==='ArrowUp'||e.key==='Enter'){
const rows=_visibleModelRows();
if(!rows.length){if(e.key==='Enter') e.preventDefault();return;}
const cur=_activeRowIndex(rows);
if(e.key==='ArrowDown'){e.preventDefault();_highlightRow(rows,cur<0?0:Math.min(rows.length-1,cur+1));return;}
...
}
});And the supporting style rule at .model-opt.is-highlighted{background:rgba(255,255,255,.1);outline:1px solid var(--border2);outline-offset:-1px;}Diagnosis1.
|
…ed row (review feedback from @nesquena-hermes)
|
Fixed the cascade collision in 7bb7e30: added |
The model picker has a working search input but no keyboard navigation. After you type a filter you still have to take your hand off the keyboard to click the row you want, which is the part of #2791 that bites the most in day-to-day use.
This wires three handlers onto the existing search input:
ArrowDown/ArrowUpmove a.is-highlightedclass through the visible (and filter-narrowed).model-optrows, with wraparound at the ends.Enterclicks the highlighted row (or the first row if nothing is highlighted yet, so typing a filter and immediately hitting Enter just picks the top match).Escapekeeps its existing close-dropdown behavior.Highlight gets a small CSS rule that reuses the existing border-color and brightens the row a bit more than
:hoverso the selection is obvious without redoing the dropdown styling.The maintainer's review on #2791 already broke the issue into three slices (fuzzy scorer, match highlighting, keyboard nav) and called this one out as the clean keyboard-only change. Fuzzy matching and
<mark>highlighting are intentionally left for follow-ups — this PR is just the nav.Verified
python -m pytest tests/test_2791_model_picker_keyboard_nav.py— 4 passed.node --check static/ui.js— clean.Closes #2791
Sanity check: not inside a
<form>Confirmed in source:
static/index.htmlcontains no<form>element at all (grep returns no matches).#composerModelDropdownlives under#composeras a plain<div>with no form ancestor, so thepreventDefault()on empty-list Enter is defensive only and won't be exercised in practice.Review-feedback fixes (7bb7e30)
.model-opt.active.is-highlightedrule added so the selection accent (--accent-bg) survives when the keyboard cursor lands on the currently-selected row, withoutline: 1px solid var(--accent)doing the cursor indication on its own.