hotwired / stimulus

A modest JavaScript framework for the HTML you already have

Home Page:https://stimulus.hotwired.dev/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add support for `regex` key

seb-jean opened this issue · comments

Hi,

It would be interesting to add the possibility of putting a regex in the keyMappings.
For instance:

  • [:alpha:], to use any alphabetics character
  • [:digit:], to use any digits

Then we could use it like this:

<div data-controller="menu" data-action="keydown.[:alpha:]->menu#search">
    [...]
</div>

Tell me what you think about it.

Cheers 😁

Personally I don't think it's really worth to add this additional complexity and syntax to the data-action attribute. If you want a "match all characters" type of event listener you should just do data-action="keydown->menu#search" and filter the thing you are looking for in the search() method.

Using the keydown.[:alpha:] syntax you'd anyway need to handle and fetch the value from something like event.detail.alpha and do something with, which means you are writing custom logic anyway.

@marcoroth Yeah, I see what you mean.