Skip to content

Commit

Permalink
fix(modal): use modal id for dialog aria-labelledby attribute by default
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinbuhmann committed May 28, 2024
1 parent ec04af7 commit 7d8c34b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion projects/angular/src/modal/modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
role="dialog"
aria-modal="true"
[attr.aria-hidden]="!_open"
[attr.aria-labelledby]="labelledBy"
[attr.aria-labelledby]="labelledBy || modalId"
>
<div class="clr-sr-only">{{commonStrings.keys.modalContentStart}}</div>
<div class="modal-content-wrapper">
Expand Down
23 changes: 21 additions & 2 deletions projects/angular/src/modal/modal.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,29 @@ describe('Modal', () => {
expect(compiled.querySelector('.close').getAttribute('aria-label')).toBe('custom close label');
});

it('should add expected aria-labelledby', () => {
// open modal
it('should use modal id for aria-labelledby by default', () => {
modal.open();
fixture.detectChanges();

expect(compiled.querySelector('.modal-dialog').getAttribute('aria-labelledby')).toBe(modal.modalId);
});

it('should allow a custom aria-labelledby attribute value', () => {
modal.labelledBy = 'custom-id';

modal.open();
fixture.detectChanges();

expect(compiled.querySelector('.modal-dialog').getAttribute('aria-labelledby')).toBe('custom-id');
});

it('should fall back to the modal id for the aria-labelledby attribute value', () => {
// set to a falsy value
modal.labelledBy = '';

modal.open();
fixture.detectChanges();

expect(compiled.querySelector('.modal-dialog').getAttribute('aria-labelledby')).toBe(modal.modalId);
});

Expand Down

0 comments on commit 7d8c34b

Please sign in to comment.