Skip to content

Commit

Permalink
Merge branch 'main' into feature/1537-add-no-items-found-message
Browse files Browse the repository at this point in the history
  • Loading branch information
jpzwarte committed Sep 23, 2024
2 parents 444fa36 + d52af39 commit ade8983
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/ninety-comics-poke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sl-design-system/menu': patch
---

Set initial aria-details and aria-expanded on the menu button
14 changes: 14 additions & 0 deletions packages/components/menu/src/menu-button.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,20 @@ describe('sl-menu-button', () => {
expect(button).to.exist;
});

it('should not be expanded', () => {
expect(button).to.have.attribute('aria-expanded', 'false');
});

it('should be expanded when the menu is open', () => {
button.click();

expect(button).to.have.attribute('aria-expanded', 'true');
});

it('should be linked to the menu', () => {
expect(button.getAttribute('aria-details')).to.equal(menu.id);
});

it('should not have a disabled button', () => {
expect(button).not.to.have.attribute('disabled');
expect(button.disabled).not.to.be.true;
Expand Down
2 changes: 2 additions & 0 deletions packages/components/menu/src/menu-button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export class MenuButton extends ScopedElementsMixin(LitElement) {
override firstUpdated(changes: PropertyValues<this>): void {
super.firstUpdated(changes);

this.button.setAttribute('aria-details', this.menu.id);
this.menu.anchorElement = this.button;
}

Expand All @@ -80,6 +81,7 @@ export class MenuButton extends ScopedElementsMixin(LitElement) {
@click=${this.#onClick}
@keydown=${this.#onKeydown}
?disabled=${this.disabled}
aria-expanded="false"
fill=${ifDefined(this.fill)}
part="button"
size=${ifDefined(this.size)}
Expand Down

0 comments on commit ade8983

Please sign in to comment.