Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

Commit 35b8512

Browse files
kevinoidwesleycho
authored andcommitted
fix(datepicker): disable title button when in max mode
When the calendar is in the maximum configured mode, clicking the title button has no effect. To convey this to users, make the non-functional button non-clickable, and take the button out of focus order, disable the button when in the maximum mode. Closes #3012
1 parent 8e89440 commit 35b8512

File tree

5 files changed

+18
-5
lines changed

5 files changed

+18
-5
lines changed

src/datepicker/datepicker.js

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
4444
});
4545

4646
$scope.datepickerMode = $scope.datepickerMode || datepickerConfig.datepickerMode;
47+
$scope.maxMode = self.maxMode;
4748
$scope.uniqueId = 'datepicker-' + $scope.$id + '-' + Math.floor(Math.random() * 10000);
4849

4950
if(angular.isDefined($attrs.initDate)) {

src/datepicker/test/datepicker.spec.js

+14-2
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,16 @@ describe('datepicker directive', function () {
3232
$rootScope.date = new Date('September 30, 2010 15:30:00');
3333
}));
3434

35+
function getTitleButton() {
36+
return element.find('th').eq(1).find('button').first();
37+
}
38+
3539
function getTitle() {
36-
return element.find('th').eq(1).find('button').first().text();
40+
return getTitleButton().text();
3741
}
3842

3943
function clickTitleButton() {
40-
element.find('th').eq(1).find('button').first().click();
44+
getTitleButton().click();
4145
}
4246

4347
function clickPreviousButton(times) {
@@ -1905,6 +1909,14 @@ describe('datepicker directive', function () {
19051909
clickTitleButton();
19061910
expect(getTitle()).toBe('2013');
19071911
});
1912+
1913+
it('disables the title button at it', function() {
1914+
expect(getTitleButton().prop('disabled')).toBe(false);
1915+
clickTitleButton();
1916+
expect(getTitleButton().prop('disabled')).toBe(true);
1917+
clickTitleButton();
1918+
expect(getTitleButton().prop('disabled')).toBe(true);
1919+
});
19081920
});
19091921

19101922
describe('with an ngModelController having formatters and parsers', function() {

template/datepicker/day.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<thead>
33
<tr>
44
<th><button type="button" class="btn btn-default btn-sm pull-left" ng-click="move(-1)" tabindex="-1"><i class="glyphicon glyphicon-chevron-left"></i></button></th>
5-
<th colspan="{{5 + showWeeks}}"><button id="{{uniqueId}}-title" role="heading" aria-live="assertive" aria-atomic="true" type="button" class="btn btn-default btn-sm" ng-click="toggleMode()" tabindex="-1" style="width:100%;"><strong>{{title}}</strong></button></th>
5+
<th colspan="{{5 + showWeeks}}"><button id="{{uniqueId}}-title" role="heading" aria-live="assertive" aria-atomic="true" type="button" class="btn btn-default btn-sm" ng-click="toggleMode()" ng-disabled="datepickerMode === maxMode" tabindex="-1" style="width:100%;"><strong>{{title}}</strong></button></th>
66
<th><button type="button" class="btn btn-default btn-sm pull-right" ng-click="move(1)" tabindex="-1"><i class="glyphicon glyphicon-chevron-right"></i></button></th>
77
</tr>
88
<tr>

template/datepicker/month.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<thead>
33
<tr>
44
<th><button type="button" class="btn btn-default btn-sm pull-left" ng-click="move(-1)" tabindex="-1"><i class="glyphicon glyphicon-chevron-left"></i></button></th>
5-
<th><button id="{{uniqueId}}-title" role="heading" aria-live="assertive" aria-atomic="true" type="button" class="btn btn-default btn-sm" ng-click="toggleMode()" tabindex="-1" style="width:100%;"><strong>{{title}}</strong></button></th>
5+
<th><button id="{{uniqueId}}-title" role="heading" aria-live="assertive" aria-atomic="true" type="button" class="btn btn-default btn-sm" ng-click="toggleMode()" ng-disabled="datepickerMode === maxMode" tabindex="-1" style="width:100%;"><strong>{{title}}</strong></button></th>
66
<th><button type="button" class="btn btn-default btn-sm pull-right" ng-click="move(1)" tabindex="-1"><i class="glyphicon glyphicon-chevron-right"></i></button></th>
77
</tr>
88
</thead>

template/datepicker/year.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<thead>
33
<tr>
44
<th><button type="button" class="btn btn-default btn-sm pull-left" ng-click="move(-1)" tabindex="-1"><i class="glyphicon glyphicon-chevron-left"></i></button></th>
5-
<th colspan="3"><button id="{{uniqueId}}-title" role="heading" aria-live="assertive" aria-atomic="true" type="button" class="btn btn-default btn-sm" ng-click="toggleMode()" tabindex="-1" style="width:100%;"><strong>{{title}}</strong></button></th>
5+
<th colspan="3"><button id="{{uniqueId}}-title" role="heading" aria-live="assertive" aria-atomic="true" type="button" class="btn btn-default btn-sm" ng-click="toggleMode()" ng-disabled="datepickerMode === maxMode" tabindex="-1" style="width:100%;"><strong>{{title}}</strong></button></th>
66
<th><button type="button" class="btn btn-default btn-sm pull-right" ng-click="move(1)" tabindex="-1"><i class="glyphicon glyphicon-chevron-right"></i></button></th>
77
</tr>
88
</thead>

0 commit comments

Comments
 (0)