From 3ac91be052e6f1799b188f2863fd181019f80076 Mon Sep 17 00:00:00 2001 From: Myrta Sakellariou <66249294+myrta2302@users.noreply.github.com> Date: Thu, 19 Dec 2024 12:50:11 +0200 Subject: [PATCH] chore(components): close header megadropdown onfocusout (#4324) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Alizé Debray <33580481+alizedebray@users.noreply.github.com> --- .changeset/real-phones-scream.md | 5 +++++ .../components/post-megadropdown/post-megadropdown.tsx | 10 +++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 .changeset/real-phones-scream.md diff --git a/.changeset/real-phones-scream.md b/.changeset/real-phones-scream.md new file mode 100644 index 0000000000..76b359853e --- /dev/null +++ b/.changeset/real-phones-scream.md @@ -0,0 +1,5 @@ +--- +'@swisspost/design-system-components': patch +--- + +Modified header megadropdown to close when focus is moved outside. diff --git a/packages/components/src/components/post-megadropdown/post-megadropdown.tsx b/packages/components/src/components/post-megadropdown/post-megadropdown.tsx index 03d0ff5db9..0ccbc975d6 100644 --- a/packages/components/src/components/post-megadropdown/post-megadropdown.tsx +++ b/packages/components/src/components/post-megadropdown/post-megadropdown.tsx @@ -80,6 +80,14 @@ export class PostMegadropdown { this.popoverRef.hide(); } + private handleFocusout(event: FocusEvent) { + const relatedTarget = event.relatedTarget as HTMLElement; + const megadropdown= this.popoverRef.querySelector('.megadropdown'); + if (!megadropdown.contains(relatedTarget)) { + this.hide(); + } + } + render() { return ( @@ -89,7 +97,7 @@ export class PostMegadropdown { edge-gap="0" ref={el => (this.popoverRef = el)} > -
+
this.handleFocusout(e)}>
this.handleBackButtonClick()} class="back-button">