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

Panic when autocomplete on input is triggered #94

Open
boyswan opened this issue Apr 12, 2024 · 1 comment
Open

Panic when autocomplete on input is triggered #94

boyswan opened this issue Apr 12, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@boyswan
Copy link

boyswan commented Apr 12, 2024

When triggering autocomplete of an input, onkeydown does not return a true leptos::ev::KeyboardEvent like it is typed in leptos. This causes a panic in leptos-hotkeys. Testing in latest chrome.

Uncaught TypeError: Cannot read properties of undefined (reading 'length')
    at passStringToWasm0 (leppy.js:100:31)
    at imports.wbg.__wbg_key_dccf9e8aa1315a8e (leppy.js:1445:14)
    at web_sys::features::gen_KeyboardEvent::KeyboardEvent::key::h05b0022609f7fd9a (leppy.wasm:0x1657789)
    at leptos_hotkeys::hotkeys_provider::provide_hotkeys_context::{{closure}}::{{closure}}::{{closure}}::hc8c6175319fb3a5f (leppy.wasm:0x150315d)

I have run into the same bug myself and have worked around it via:

  let on_keydown = move |e: leptos::ev::KeyboardEvent| {
    // The original event can sometimes actually be a regular Event
    // in the case of textfield autocomplete instead of keydown.
    // the leptos KeyboardEvent is wrong.
    let event: Option<&web_sys::Event> = e.dyn_ref();
    if let Some(event) = event.cloned() {
      if let Ok(e) = event.dyn_into::<KeyboardEvent>() {
        if let Some(target) = e.target() {
          if let Ok(input_element) = target.dyn_into::<HtmlInputElement>() {
             // .... we know e.keys() exists here
            }
          }
        }
      }
    }
  };

I'll open an issue in leptos and link this one!

@friendlymatthew
Copy link
Member

friendlymatthew commented May 1, 2024

@all-contributors add @boyswan for bug and ideas

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants