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:
- Click inside the input field and wait for the autocomplete list to appear.
- Pick a suggestion from the autocomplete list.
- ✅ 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)