Skip to content

Commit

Permalink
chore(components): close header megadropdown onfocusout (#4324)
Browse files Browse the repository at this point in the history
Co-authored-by: Alizé Debray <[email protected]>
  • Loading branch information
myrta2302 and alizedebray authored Dec 19, 2024
1 parent 09afdbd commit 3ac91be
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/real-phones-scream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@swisspost/design-system-components': patch
---

Modified header megadropdown to close when focus is moved outside.
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<Host>
Expand All @@ -89,7 +97,7 @@ export class PostMegadropdown {
edge-gap="0"
ref={el => (this.popoverRef = el)}
>
<div class="megadropdown">
<div class="megadropdown" onFocusout={e => this.handleFocusout(e)}>
<div onClick={() => this.handleBackButtonClick()} class="back-button">
<slot name="back-button"></slot>
</div>
Expand Down

0 comments on commit 3ac91be

Please sign in to comment.