Stimulus Controller to initialize Bootstrap Toast

Bootstrap Toasts are opt-in, so you must initialize them yourself. See https://getbootstrap.com/docs/5.1/components/toasts/#overview

The complete controller

app/javascript/controllers/toast_controller.js
import { Controller } from "@hotwired/stimulus"
import { Toast } from "bootstrap"

// Connects to data-controller="toast"
export default class extends Controller {
  connect() {
    console.log("toast#connect")
    this.toast = new bootstrap.Toast(this.element)
    this.toast.show()
  }
}
If you want to change the animation, set options in new bootstrap.Toast. Default is animation: true, autohide: true, delay: 5000.