Skip to content

Chrome autocomplete incorrectly triggers actions with keydown events (regardless of KeyboardEvent filters) #852

@MatheusRich

Description

@MatheusRich

When using a Stimulus action like:

<button data-action="keydown.meta+k@window->search#open">

In Google Chrome, clicking an input’s autocomplete suggestion unexpectedly triggers the controller action even though no key is pressed.

It seems that Chrome dispatches an Event with type === "keydown", but it is not an instance of KeyboardEvent. This happens regardless of the key filter (and using @window or not).

Reproduction

Use this CodePen: https://codepen.io/matheusrich/pen/xbwOOqm

Steps:

  1. Click inside the input field and wait for the autocomplete list to appear.
  2. Pick a suggestion from the autocomplete list.
  3. ✅ Stimulus incorrectly triggers the action

Workaround

On my controller, I'm using this to prevent this behavior for now

if (event.type == "keydown" && !(event instanceof KeyboardEvent)) return

I'll submit a fix to for this on Stimulus.

Chrome Version 138.0.7204.169 (Official Build) (x86_64)

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