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

Combining multiple key modifiers such as ctrl.shift+q #685

Open
nickjj opened this issue Jun 15, 2023 · 5 comments
Open

Combining multiple key modifiers such as ctrl.shift+q #685

nickjj opened this issue Jun 15, 2023 · 5 comments

Comments

@nickjj
Copy link

nickjj commented Jun 15, 2023

Hi,

The docs cover how to add something like keydown.ctrl+a or keydown.shift+a but there's no reference on how to combine multiple modifiers such as keydown.ctrl.shift+a. I also tried keydown.ctrl+shift+a. At a quick glance I didn't see any tests for this as well.

Is this feature not available? Are there any plans to support multiple modifiers?

@marcoroth
Copy link
Member

I think this is currently not supported. But maybe @NakajimaTakuya might have an idea how it could look like if we would support multiple modifiers.

@NakajimaTakuya
Copy link
Contributor

NakajimaTakuya commented Jun 16, 2023

@nickjj

Sorry I didn't mention it in the documentation. But that syntax is supported. (keydown.ctrl+shift+a)
It is working on my end, but not working?
https://codepen.io/Takuya-Nakajima/pen/wvQMZGz?editors=1010

And the test exists here.
https://github.com/hotwired/stimulus/blob/main/src/tests/modules/core/action_keyboard_filter_tests.ts#L180-L185

@nickjj
Copy link
Author

nickjj commented Jun 16, 2023

@NakajimaTakuya Thanks. When I looked at the tests I was only looking for an end-to-end syntax example in my search.

If I change your codepen to data-action="keydown.ctrl+shift+8->notifier#notify" then it doesn't trigger.

That was what I was running locally. Funny enough I also had a 2nd one of keydown.ctrl+shift+. which didn't work but now I see this one with the . probably won't work by default due to that key not being in the list of filters. But in theory 8 should match [0-9]? Does it not because shift really changes that to * which is also not included in the default filter list?

@NakajimaTakuya
Copy link
Contributor

NakajimaTakuya commented Jun 16, 2023

@nickjj

I thought there was some discrepancy, but it seems to be a problem created by the difference between JIS and US keyboards.
On a JIS keyboard Mac, ctrl+shift+8 event.key is 8, event.shiftKey is true, event.ctrlKey is true.
On a US keyboard Windows, ctrl+shift+8 event.key was *, event.shiftKey was true, event.ctrlKey was true.

Does it not because shift really changes that to * which is also not included in the default filter list?

Now maybe @nickjj is using a US keyboardWindows, so 8 is interpreted as *.
So it's probably that * is not in the support list and therefore not being handled.

I'll give it some thought.

@nickjj
Copy link
Author

nickjj commented Jun 16, 2023

Ah nice catch on thinking about different keyboard layouts. I'm using a standard layout US English keyboard on Windows.

@dhh dhh closed this as completed Jun 18, 2023
@dhh dhh reopened this Jun 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants