Fix modal positioning and improve Stimulus controller
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
@@ -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')
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user