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

fix(datepicker): forward aria-label to generated input #9364

Merged
merged 1 commit into from
Aug 23, 2016
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
17 changes: 10 additions & 7 deletions src/components/datepicker/js/datepickerDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
// interaction on the text input, and multiple tab stops for one component (picker)
// may be confusing.
var hiddenIcons = tAttrs.mdHideIcons;
var ariaLabelValue = tAttrs.ariaLabel || tAttrs.mdPlaceholder;

var calendarButton = (hiddenIcons === 'all' || hiddenIcons === 'calendar') ? '' :
'<md-button class="md-datepicker-button md-icon-button" type="button" ' +
Expand All @@ -81,13 +82,15 @@
'<div class="md-datepicker-expand-triangle"></div>' +
'</md-button>';

return '' +
calendarButton +
'<div class="md-datepicker-input-container" ' +
'ng-class="{\'md-datepicker-focused\': ctrl.isFocused}">' +
'<input class="md-datepicker-input" aria-haspopup="true" ' +
'ng-focus="ctrl.setFocused(true)" ng-blur="ctrl.setFocused(false)">' +
triangleButton +
return calendarButton +
'<div class="md-datepicker-input-container" ng-class="{\'md-datepicker-focused\': ctrl.isFocused}">' +
'<input ' +
(ariaLabelValue ? 'aria-label="' + ariaLabelValue + '" ' : '') +
'class="md-datepicker-input" ' +
'aria-haspopup="true" ' +
'ng-focus="ctrl.setFocused(true)" ' +
'ng-blur="ctrl.setFocused(false)"> ' +
triangleButton +
'</div>' +

// This pane will be detached from here and re-attached to the document body.
Expand Down
5 changes: 5 additions & 0 deletions src/components/datepicker/js/datepickerDirective.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ describe('md-datepicker', function() {
expect(controller.inputElement.placeholder).toBe('Fancy new placeholder');
});

it('should forward the aria-label to the generated input', function() {
createDatepickerInstance('<md-datepicker ng-model="myDate" aria-label="Enter a date"></md-datepicker>');
expect(controller.ngInputElement.attr('aria-label')).toBe('Enter a date');
});

it('should throw an error when the model is not a date', function() {
expect(function() {
pageScope.myDate = '2015-01-01';
Expand Down