FSElias's avatar

Laracasts.com search and the letter "k"

Hello @JeffreyWay, I am unable to type the letter "k" in the search field of laracasts.com, tested on multiple browsers.

0 likes
4 replies
jlrdw's avatar

Same, can't even type it in a word.

martinbean's avatar

Seems the letter “k” is used as a hotkey to focus the search box.

@jeffreyway You should combine hotkeys like this with a modifier (usually Ctrl/Cmd).

JeffreyWay's avatar

@fselias Thanks! This is fixed now.

Very strange. I had this code for the "Cmd+K" search input listener.

// Toggle focus for the search input with CMD+K.
onKeyStroke(
  "k",
  (e) => {
    input.value[input.value === document.activeElement ? 'blur' : 'focus']();

    e.preventDefault();
  },
  { eventName: "keydown", ctrl: true, meta: true }
);

But it seems like the listener was firing even if you just press "K" alone (without the cmd or ctrl keys). I changed it to:

onKeyStroke(
  "k",
  (e) => {
    if (!(e.ctrlKey || e.metaKey)) return;

    input.value[input.value === document.activeElement ? 'blur' : 'focus']();

    e.preventDefault();
  },
  { eventName: "keydown" }
);

...And that seems to have fixed the issue.

2 likes

Please or to participate in this conversation.