Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit 2247248

Browse files
alopezsanchezkara
authored andcommitted
fix(dialog): generate aria-label with dialog title (if exists) when .ariaLabel() is not specified (#10735)
Fixes #10582
1 parent 9430a7c commit 2247248

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/components/dialog/dialog.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,9 +1083,15 @@ function MdDialogProvider($$interimElementProvider) {
10831083
}
10841084
else {
10851085
$mdAria.expectAsync(element, 'aria-label', function() {
1086-
var words = dialogContent.text().split(/\s+/);
1087-
if (words.length > 3) words = words.slice(0, 3).concat('...');
1088-
return words.join(' ');
1086+
// If dialog title is specified, set aria-label with it
1087+
// See https://github.com/angular/material/issues/10582
1088+
if (options.title) {
1089+
return options.title;
1090+
} else {
1091+
var words = dialogContent.text().split(/\s+/);
1092+
if (words.length > 3) words = words.slice(0, 3).concat('...');
1093+
return words.join(' ');
1094+
}
10891095
});
10901096
}
10911097

src/components/dialog/dialog.spec.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ describe('$mdDialog', function() {
114114
expect(css).toContain('someClass');
115115
expect(css).toContain('anotherClass');
116116
expect(mdDialog.attr('role')).toBe('alertdialog');
117+
expect(mdDialog.attr('aria-label')).toBe('Title');
117118

118119
buttons.eq(0).triggerHandler('click');
119120

@@ -374,6 +375,7 @@ describe('$mdDialog', function() {
374375
expect(buttons.length).toBe(2);
375376
expect(buttons.eq(0).text()).toBe('Next');
376377
expect(buttons.eq(1).text()).toBe('Forget it');
378+
expect(dialog.attr('aria-label')).toBe('Title');
377379

378380
buttons.eq(1).triggerHandler('click');
379381
runAnimation();
@@ -679,6 +681,7 @@ describe('$mdDialog', function() {
679681
expect(css).toContain('someClass');
680682
expect(css).toContain('anotherClass');
681683
expect(mdDialog.attr('role')).toBe('dialog');
684+
expect(mdDialog.attr('aria-label')).toBe('Title');
682685

683686
inputElement.eq(0).text('responsetext');
684687
inputElement.scope().$apply("dialog.result = 'responsetext'");
@@ -1622,7 +1625,7 @@ describe('$mdDialog', function() {
16221625
expect(childNodes.indexOf(contentElement[0])).toBe(0);
16231626

16241627
document.body.removeChild(contentParent[0]);
1625-
})
1628+
});
16261629

16271630
});
16281631

0 commit comments

Comments
 (0)