Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(components): add opening state to mega dropdown trigger + fix expanded detection #4299

Merged
merged 2 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/dry-trainers-stare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@swisspost/design-system-components': patch
---

Fixed opening state of megadropdown trigger and expanded detection.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ post-mainnavigation {
border-block-width: var(--post-core-dimension-2);
}

&.selected {
&.selected,
&[aria-expanded='true'] {
border-block-width: var(--post-core-dimension-4);
font-weight: var(--post-core-font-weight-700);
}
Expand All @@ -93,7 +94,8 @@ post-mainnavigation {
transition: transform animation.$transition-base-timing;
}

&.selected::after {
&.selected::after,
&[aria-expanded='true']::after {
transform: rotate(180deg);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ export class PostMegadropdownTrigger {
}

private handleToggle() {
if (this.megadropdown && this.slottedButton) {
this.ariaExpanded = !this.ariaExpanded;
this.slottedButton.setAttribute('aria-expanded', this.ariaExpanded.toString());
if (this.megadropdown) {
this.megadropdown.toggle(this.host);
} else {
console.warn(`No post-megadropdown found with ID: ${this.for}`);
Expand All @@ -55,6 +53,16 @@ export class PostMegadropdownTrigger {
componentDidLoad() {
this.validateControlFor();

// Check if the mega dropdown attached to the trigger is expanded or not
document.addEventListener('postToggleMegadropdown', (event: CustomEvent) => {
if ((event.target as HTMLPostMegadropdownElement).id === this.for) {
this.ariaExpanded = event.detail;
if (this.slottedButton) {
this.slottedButton.setAttribute('aria-expanded', this.ariaExpanded.toString());
}
}
});

this.slottedButton = this.host.querySelector('button');
if (this.slottedButton) {
this.slottedButton.setAttribute('aria-haspopup', 'menu');
Expand Down
Loading