Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid KeyboardEvent type when triggering autocomplete #2519

Open
boyswan opened this issue Apr 12, 2024 · 3 comments
Open

Invalid KeyboardEvent type when triggering autocomplete #2519

boyswan opened this issue Apr 12, 2024 · 3 comments

Comments

@boyswan
Copy link
Contributor

boyswan commented Apr 12, 2024

When using on:keydown on a form element (or likely any input), the event is currently typed as leptos::ev::KeyboardEvent.

However, in the cause of input autocomplete (selecting a historic value from a browser suggestion), the event is actually a leptos::ev::Event, as there is no event.key(). This is a bit of an unfortunate browser quirk, at least in the latest chrome.

Reference issue:
gaucho-labs/leptos-hotkeys#94

@boyswan boyswan changed the title Invalid KeyboardEvent when triggering autocomplete Invalid KeyboardEvent type when triggering autocomplete Apr 12, 2024
@gbj gbj modified the milestone: 0.7 Apr 12, 2024
@gbj
Copy link
Collaborator

gbj commented Apr 12, 2024

Oof.

Is there a reason to think this might be a Chrome bug, or Chrome being spec-non-compliant? Comparison with other browsers would be good. The W3C UI Events spec is pretty explicit that keydown is a KeyboardEvent.

@boyswan
Copy link
Contributor Author

boyswan commented Apr 12, 2024

Hmm on closer inspection it looks like it's like a keydown event, but crucially missing the code/key fields.

On autocomplete:
Screenshot 2024-04-12 at 14 08 59

On "real" keydown:
Screenshot 2024-04-12 at 14 09 09

This is only happening on chrome, firefox works correctly

@gbj
Copy link
Collaborator

gbj commented Apr 19, 2024

Yeah I'll be honest I'm not sure the best way to deal with this. From looking around a little, my impression is that this is a long-standing Chrome thing that will probably not change. On the other hand, it seems pretty clear to me that it's not compliant with the spec.

I guess there are three options:

  1. In a future version, make keydown a KeyboardEvent, which will be a breaking change and be less useful for users in the default case (all other browsers, and all non-autocomplete keydown events)
  2. Add some kind of runtime check, which will have a cost for all binary sizes and a runtime performance cost for the default case
  3. Document "hey, this is broken in Chrome, here's the workaround if you encounter it"

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

No branches or pull requests

2 participants