fix: users shouldn't have to press down arrow twice to select an option (#3809)

* fix: users shouldn't have to press down arrow twice to select an option

* add regression test for cmd bar arrow

* tweak
This commit is contained in:
Kurt Hutten
2024-09-10 12:10:14 +10:00
committed by GitHub
parent 25443eba31
commit dab96577a7
3 changed files with 73 additions and 0 deletions

View File

@ -71,6 +71,17 @@ function CommandArgOptionInput({
inputRef.current?.focus()
inputRef.current?.select()
}, [inputRef])
useEffect(() => {
// work around to make sure the user doesn't have to press the down arrow key to focus the first option
// instead this makes it move from the first hit
const downArrowEvent = new KeyboardEvent('keydown', {
key: 'ArrowDown',
keyCode: 40,
which: 40,
bubbles: true,
})
inputRef?.current?.dispatchEvent(downArrowEvent)
}, [])
// Filter the options based on the query,
// resetting the query when the options change

View File

@ -11,6 +11,7 @@ export function CommandBarOpenButton() {
<button
className="group rounded-full flex items-center justify-center gap-2 px-2 py-1 bg-primary/10 dark:bg-chalkboard-90 dark:backdrop-blur-sm border-primary hover:border-primary dark:border-chalkboard-50 dark:hover:border-inherit text-primary dark:text-inherit"
onClick={() => commandBarSend({ type: 'Open' })}
data-testid="command-bar-open-button"
>
<span>Commands</span>
<kbd className="bg-primary/10 dark:bg-chalkboard-80 dark:group-hover:bg-primary font-mono rounded-sm dark:text-inherit inline-block px-1 border-primary dark:border-chalkboard-90">