Stimulus Controller to close the alert
The complete controller
It’s very simple: call the action remove()
after the animation event is completed via data-action
:
<div ... data-action="animationend->remove#remove">
app/javascript/controllers/remove_controller.js
import { Controller } from "@hotwired/stimulus"
// Connects to data-controller="remove"
export default class extends Controller {
remove() {
console.log("remove#remove")
this.element.remove()
}
}
Yes, it’s that simple 🙂