From 348f9d023b8d462930e51bd0c4422ae1f07d2215 Mon Sep 17 00:00:00 2001 From: oki07 Date: Sat, 23 Nov 2024 14:26:06 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=A1=E3=83=8B=E3=83=A5=E3=83=BC=E4=BB=A5?= =?UTF-8?q?=E5=A4=96=E3=81=AE=E5=A0=B4=E6=89=80=E3=82=92=E3=82=AF=E3=83=AA?= =?UTF-8?q?=E3=83=83=E3=82=AF=E3=81=97=E3=81=A6=E3=82=82=E9=96=89=E3=81=98?= =?UTF-8?q?=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/dropdownAction/sp-dropdown-action.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/components/dropdownAction/sp-dropdown-action.ts b/src/components/dropdownAction/sp-dropdown-action.ts index 0241343..3968024 100644 --- a/src/components/dropdownAction/sp-dropdown-action.ts +++ b/src/components/dropdownAction/sp-dropdown-action.ts @@ -104,6 +104,7 @@ export class SpDropdownAction extends HTMLElement { this.#menuElement.appendChild(this.#menuSlotElement); this.#menuSlotElement.addEventListener("click", this.#closeMenu.bind(this)); + window.addEventListener("click", this.#closeMenu.bind(this)); this.#baseElement.appendChild(this.#menuElement); this.#baseElement.classList.add("base"); @@ -116,6 +117,7 @@ export class SpDropdownAction extends HTMLElement { disconnectedCallback() { this.#menuSlotElement.removeEventListener("click", this.#closeMenu.bind(this)); + window.removeEventListener("click", this.#closeMenu.bind(this)); } attributeChangedCallback(name: string, oldValue: string, newValue: string) { @@ -140,12 +142,18 @@ export class SpDropdownAction extends HTMLElement { } } - #toggleMenuVisibility() { + #toggleMenuVisibility(event: MouseEvent) { + event.stopPropagation(); + this.open = !this.open; this.#updateAriaExpandedAttribute(); } #closeMenu() { + if (!this.open) { + return + }; + this.open = false; this.#updateAriaExpandedAttribute(); }