Fix modal positioning and improve Stimulus controller

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
kbe
2025-09-16 08:43:00 +02:00
parent 28eddb22ab
commit 4e06f91acb
2 changed files with 54 additions and 51 deletions

View File

@@ -1,27 +1,30 @@
import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
static targets = ["modal", "cloneTicketTypes"]
static targets = ["cloneTicketTypes"]
static values = {
duplicateUrl: String
}
connect() {
// Get modal element from the document
this.modalElement = document.querySelector('[data-event-duplication-target="modal"]')
// Close modal when clicking outside
this.modalTarget.addEventListener('click', (event) => {
if (event.target === this.modalTarget) {
this.modalElement.addEventListener('click', (event) => {
if (event.target === this.modalElement) {
this.close()
}
})
}
open() {
this.modalTarget.classList.remove('hidden')
this.modalElement.classList.remove('hidden')
document.body.classList.add('overflow-hidden')
}
close() {
this.modalTarget.classList.add('hidden')
this.modalElement.classList.add('hidden')
document.body.classList.remove('overflow-hidden')
}