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

Ability to use action options without controller? #727

Open
mockdeep opened this issue Oct 11, 2023 · 1 comment
Open

Ability to use action options without controller? #727

mockdeep opened this issue Oct 11, 2023 · 1 comment

Comments

@mockdeep
Copy link

We have situations where we might need to capture an event and stop propagation. Is there any way to use an action option without needing to add a controller? For example, I'm imagining being able to do something like:

<div data-action="click->:stop"></div>

Is this possible?

@lb-
Copy link
Contributor

lb- commented Oct 17, 2023

I don't think this would be possible without a large change the the codebase. Actions are very much tied into the controller instance.

Maybe you could just make a simple controller to help for this case.

class UtilController extends Controller {
  x() {
    // does nothing 
  }
}

Stimulus.register('x', UtilController);
<div data-controller="x" data-action="click->x#x:stop"></div>

A reminder that elements can support multiple controllers by space seperated identifiers.

<input data-controller="x my-widget" data-action="click->x#x:stop focus->my-widget#expand" />

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

2 participants