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">