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

Support for some other Action Options and Key Modifiers would be great #530

Closed
radiantshaw opened this issue Mar 30, 2022 · 6 comments
Closed

Comments

@radiantshaw
Copy link
Contributor

This issue is inspired by #440, #442, and Vue's v-on directive. Out of the listed "Modifiers", Stimulus already has the following:

  • :capture
  • :once
  • :passive
  • :!passive

The .{keyAlias} Key Modifier is already being handled in #442 for keyboard events. We can have the equivalent .left, .right, and .middle Key Modifiers for mouse events as well.

On top of that, seems like having a :self Action Option would be great. Maybe an equivalent :!self as well?

And I know that the :stop and :prevent Action Options aren't necessary since the same can be done inside the handler itself, but it'd be nice to have those options as well to reduce event.stopPropagation() and event.preventDefault() inside most handlers.

Thoughts?

@dhh
Copy link
Member

dhh commented Mar 30, 2022

Yeah, I fundamentally like this syntax, and would happy to see it extended to mouse clicks as well. Do investigate.

@radiantshaw
Copy link
Contributor Author

@dhh Sure. I'll take this up and raise an appropriate PR for it. Thanks! 🤝

@adrienpoly
Copy link
Member

I like this idea for :stop :prevent

I suppose we would be able to chain them ?

<div data-action="click->controller#vote:once:prevent">

@dhh
Copy link
Member

dhh commented Mar 30, 2022

Ahh, I had thought of click.once->controller, but what you're proposing is even better, @adrienpoly. And yeah, the chaining seems very reasonable. Should still combine this with @NakajimaTakuya's work on the hotkeys and mouse modifiers, so we could have click.left->controller#vote:once.

@adrienpoly
Copy link
Member

adrienpoly commented Mar 30, 2022

yes click.once->controller was the initial syntax when we looked into this action options feature (#232) but we ended up with click->controller#action:once

So we would :

  • describe event options with trailing :option tokens
  • filter events with .variation token (probably only one in this case)

Examples

# mixing event variant and event options
<div data-action="click.left->controller#vote:once:prevent">

# with global listener
<div data-action="keydown.left@window->tabs#prevTab">

@radiantshaw
Copy link
Contributor Author

Just an update. I'm also implementing the :self functionality in a separate branch in my fork. But I'm waiting for #535 to get approved and merged first.

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

3 participants