stimulus Blogs
Written by Kiprosh, team of passionate and disciplined craftsmen turning your ideas into reality.
Kiprosh is now part of LawLytics
Written by Kiprosh, team of passionate and disciplined craftsmen turning your ideas into reality.
It's very common in Stimulus.js to call the .preventDefault() or .stopPropagation() methods on an Event object immediately after a controller's action has been fired: import { Controller } from "@hotwired/stimulus"; export default class extends Controller { open(event) { event.preventDefault(); /* ... action logic ... */ } close(event) { event.stopPropagation(); /* ... action logic ... */ } } But it starts to feel repetitive after a while; which is why a PR introduced by yours truly to the hotwired/stimulus repo makes it so that you can do those things while defining the action descriptors themselves: <div data-controller="modal"> <a data-action="modal#open:prevent">Open</a&