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(modal): fall back to modal id for dialog aria-labelledby attribute #1403

Merged
merged 1 commit into from
May 28, 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
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
2 changes: 1 addition & 1 deletion projects/angular/src/modal/modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class ClrModal implements OnChanges, OnDestroy {
@Input('clrModalPreventClose') stopClose = false;
@Output('clrModalAlternateClose') altClose = new EventEmitter<boolean>(false);

@Input('clrModalLabelledById') labelledBy = this.modalId;
@Input('clrModalLabelledById') labelledBy: string;

// presently this is only used by inline wizards
@Input('clrModalOverrideScrollService') bypassScrollService = false;
Expand Down
Loading