mirror of
https://github.com/karatektus/pl_mail.git
synced 2026-10-25 01:54:10 +00:00
26 lines
645 B
JavaScript
26 lines
645 B
JavaScript
import { Controller } from '@hotwired/stimulus';
|
|
|
|
export default class extends Controller {
|
|
static targets = ['menu'];
|
|
|
|
connect() {
|
|
this.onDocumentClick = this.onDocumentClick.bind(this);
|
|
document.addEventListener('click', this.onDocumentClick);
|
|
}
|
|
|
|
disconnect() {
|
|
document.removeEventListener('click', this.onDocumentClick);
|
|
}
|
|
|
|
toggle(event) {
|
|
event.stopPropagation();
|
|
this.menuTarget.classList.toggle('hidden');
|
|
}
|
|
|
|
onDocumentClick(event) {
|
|
if (false === this.element.contains(event.target)) {
|
|
this.menuTarget.classList.add('hidden');
|
|
}
|
|
}
|
|
}
|