OzzyCzech / cmd-dialog

Command dialog and keyboard shortcuts palette for web apps.

Home Page:https://cmd-dialog.vercel.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Hotkeys integration bug,

PhilETaylor opened this issue · comments

Assign the letter A to a menu item (Like "Your Account")

invoke cmd+k

note that Your Account has a [A] correctly - note you can arrow down and select it and it runs...

BUT note that if you type a in the search box the hotkey is invoked INCORRECTLY and navigates you away to the url of the action.

This is wrong, this should not happen.

I should be able to have hotkeys, but they should not invoke if I am in a search box, text box etc... (They dont invoke, correctly, when Im in a normal input box on my page - they do invoke when the dialog search box has focus - this is incorrect and needs a fix)

Without this fixed, it makes hotkeys unusable if they are single letters like a

This came to slap me in the face again today so I dug deeper and see that if hotkeys.filter is used it can be used to catch the keystroke (hotkey) and stop it being activated if the cmd-dialog is active

hotkeys.filter = function(event) {
    return !document.querySelector('cmd-dialog').dialog.open;
  }

I think this could be added easily into your code somewhere around here https://github.com/OzzyCzech/cmd-dialog/blob/213288020bf5177f96c863b954aa5bb7becdcd24/src/cmd-dialog.ts#L120C6-L120C6

If you could tag the release when you get a moment that would be grand - thank you.

Hi, there is a bug that prevents navigation inside the dialog, it seems that hotkeys.filter => false when the dialog is open, prevents the arrows to navigate the actions

but unfortunately event that is passed to the function return only parent cmd-dialog there fore there is no way how to detect that you are inside search input box. hotkeys should filter input boxes and text areas by default, but this is lit element and is more complicated then usual HTML

Ah sorry about that. I'm at the edge of my skill when it comes to lit and JavaScript/ts.

Driving at the moment and travelling tomorrow. Will try to pick this up again asap. Happy if you want to revert the change.

Does the event give details about the key pressed?

Alternative approach here seems to work #10

yeah I get that the Lit part of this might be the cause, and hotkeys.js should do a better job with that, but Ive no idea how to make their project work better with Lit elements and this approach here seems to be less work for us all.