Skip to content

Commit 9271263

Browse files
committed
fix: don't change active command on hover
1 parent 642d277 commit 9271263

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

app/components/CommandPalette.client.vue

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,6 @@ useEventListener(document, 'keydown', handleGlobalKeydown)
390390
:aria-current="command.active ? 'true' : undefined"
391391
@click="handleCommandClick(command)"
392392
@focus="activeIndex = commandIndexMap.get(command.id) ?? -1"
393-
@mouseenter="activeIndex = commandIndexMap.get(command.id) ?? -1"
394393
>
395394
<span class="flex items-center gap-3">
396395
<span
@@ -452,7 +451,6 @@ useEventListener(document, 'keydown', handleGlobalKeydown)
452451
:aria-current="command.active ? 'true' : undefined"
453452
@click="handleCommandClick(command)"
454453
@focus="activeIndex = commandIndexMap.get(command.id) ?? -1"
455-
@mouseenter="activeIndex = commandIndexMap.get(command.id) ?? -1"
456454
>
457455
<span class="flex items-center gap-3">
458456
<span

test/nuxt/components/CommandPalette.spec.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,27 @@ describe('CommandPalette', () => {
235235
expect(document.activeElement).toBe(input)
236236
})
237237

238+
it('does not change the active command when another item is hovered', async () => {
239+
await mountPalette()
240+
241+
const commands = Array.from(
242+
document.querySelectorAll<HTMLElement>('[data-command-item="true"]'),
243+
)
244+
245+
document.dispatchEvent(new KeyboardEvent('keydown', { bubbles: true, key: 'ArrowDown' }))
246+
await nextTick()
247+
248+
expect(document.activeElement).toBe(commands[0])
249+
expect(commands[0]?.classList.contains('border-border/80')).toBe(true)
250+
251+
commands[1]?.dispatchEvent(new MouseEvent('mouseenter', { bubbles: true }))
252+
await nextTick()
253+
254+
expect(document.activeElement).toBe(commands[0])
255+
expect(commands[0]?.classList.contains('border-border/80')).toBe(true)
256+
expect(commands[1]?.classList.contains('border-border/80')).toBe(false)
257+
})
258+
238259
it('returns to the root view with ArrowLeft only when the input is empty', async () => {
239260
await mountPalette()
240261

0 commit comments

Comments
 (0)