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

Commit 600ba73

Browse files
author
Marcy Sutton
committed
fix(select): expose and preserve aria-label
Closes #1893
1 parent 544cb27 commit 600ba73

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

src/components/select/select.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ function SelectDirective($mdSelect, $mdUtil, $mdTheming, $interpolate, $compile,
162162
ngModel.$render = function() {
163163
originalRender();
164164
syncLabelText();
165+
setAriaLabel();
165166
};
166167

167168
var lineHeight;
@@ -199,6 +200,10 @@ function SelectDirective($mdSelect, $mdUtil, $mdTheming, $interpolate, $compile,
199200

200201
scope.$$postDigest(syncLabelText);
201202

203+
function setAriaLabel() {
204+
element.attr('aria-label', labelEl.text());
205+
}
206+
202207
function syncLabelText() {
203208
if (selectContainer) {
204209
selectMenuCtrl = selectMenuCtrl || selectContainer.find('md-select-menu').controller('mdSelectMenu');
@@ -258,8 +263,7 @@ function SelectDirective($mdSelect, $mdUtil, $mdTheming, $interpolate, $compile,
258263
element.attr({
259264
'role': 'combobox',
260265
'id': 'select_' + $mdUtil.nextUid(),
261-
'aria-expanded': 'false',
262-
'aria-labelledby': labelEl.attr('id')
266+
'aria-expanded': 'false'
263267
});
264268

265269
scope.$on('$destroy', function() {
@@ -760,7 +764,6 @@ function SelectProvider($$interimElementProvider) {
760764
return $mdUtil.transitionEndPromise(opts.selectEl, {timeout: 350});
761765

762766
function configureAria() {
763-
opts.selectEl.attr('aria-labelledby', opts.target.attr('id'));
764767
opts.target.attr('aria-expanded', 'true');
765768
}
766769

src/components/select/select.spec.js

+22-6
Original file line numberDiff line numberDiff line change
@@ -586,13 +586,29 @@ describe('<md-select-menu>', function() {
586586
selectMenus.remove();
587587
}));
588588

589-
it('sets up the aria-labeledby attribute', inject(function($document) {
590-
openSelect(el);
591-
var selectId = el.attr('id');
592-
var selectMenu = $document.find('md-select-menu');
593-
expect(selectId.length).toBeTruthy();
594-
expect(selectMenu.attr('aria-labelledby')).toBe(selectId);
589+
it('adds an aria-label from placeholder', function() {
590+
var select = setupSelect('ng-model="someVal", placeholder="Hello world"');
591+
expect(select.attr('aria-label')).toBe('Hello world');
592+
});
593+
594+
it('adds an aria-label from label element', inject(function($rootScope, $compile) {
595+
var select = $compile('<md-select ng-model="val">' +
596+
'<md-select-label>Pick</md-select-label>' +
597+
'<md-option value="1">One</md-option>' +
598+
'<md-option value="2">Two</md-option>' +
599+
'<md-option value="3">Three</md-option>' +
600+
'</md-select>')($rootScope);
601+
$rootScope.$digest();
602+
expect(select.attr('aria-label')).toBe('Pick');
595603
}));
604+
605+
it('preserves aria-label on value change', inject(function($rootScope) {
606+
$rootScope.$apply('model = "b"');
607+
608+
var select = setupSelect('placeholder="Pick" ng-model="$root.model"', ['a','b','c']);
609+
expect(select.attr('aria-label')).toBe('Pick');
610+
}));
611+
596612
it('sets up the aria-expanded attribute', inject(function($document) {
597613
expect(el.attr('aria-expanded')).toBe('false');
598614
openSelect(el);

0 commit comments

Comments
 (0)