Skip to content

CommandPalette stationary mouse hover can override keyboard-first selection #1950

Description

@sbscan

Describe the bug

CommandPalette updates its active result on mouseenter. This means a stationary mouse cursor can override the expected keyboard-first selection when the palette opens or when the search results change.

If the cursor happens to be positioned over a result row after the palette renders, that row becomes selected even though the user has not moved the mouse and is interacting via keyboard. Pressing Enter then selects the hovered row instead of the first/top-ranked result.

Reproduction

  1. Render CommandPalette with several items.
  2. Leave the mouse cursor around the area where the result list will appear.
  3. Open the palette with the keyboard shortcut.
  4. Type a query that returns multiple results.
  5. If the stationary cursor is over the third result, that result becomes active.
  6. Press Enter.

Expected behavior

When the user opens the command palette and types from the keyboard, the first matching result should remain selected unless the user actively navigates with arrow keys or actually moves/clicks the mouse.

Current behavior

A result under the stationary cursor can become selected through mouseenter, so keyboard Enter may activate a non-first result.

Relevant code

In CommandPalette.svelte, list items currently do this:

onmouseenter={() => (selectedIndex = index)}

selectedIndex is private, so consumers cannot reliably reset or control this from outside.

Suggested fix

Consider using pointer/mouse movement rather than mouseenter for changing the active item, for example pointermove / mousemove, so a stationary cursor does not steal selection. It may also help to reset selectedIndex to 0 when the search query or filtered result set changes.

The key behavior would be:

  • Keyboard typing keeps the first matching result selected.
  • Arrow keys still change selection.
  • Mouse movement still changes selection.
  • Mouse click still selects the clicked item.

Version

Observed with flowbite-svelte@1.33.1.

Additional context

This is most visible when command results are sorted by recency/frequency/score: the top result is intentionally the best match, but a stationary mouse cursor can cause Enter to activate a lower-ranked row.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions