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

Commit

Permalink
fix(datepicker): disable title button when in max mode
Browse files Browse the repository at this point in the history
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
  • Loading branch information
kevinoid authored and wesleycho committed Mar 25, 2015
1 parent 8e89440 commit 35b8512
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/datepicker/datepicker.js
Expand Up @@ -44,6 +44,7 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
});

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

if(angular.isDefined($attrs.initDate)) {
Expand Down
16 changes: 14 additions & 2 deletions src/datepicker/test/datepicker.spec.js
Expand Up @@ -32,12 +32,16 @@ describe('datepicker directive', function () {
$rootScope.date = new Date('September 30, 2010 15:30:00');
}));

function getTitleButton() {
return element.find('th').eq(1).find('button').first();
}

function getTitle() {
return element.find('th').eq(1).find('button').first().text();
return getTitleButton().text();
}

function clickTitleButton() {
element.find('th').eq(1).find('button').first().click();
getTitleButton().click();
}

function clickPreviousButton(times) {
Expand Down Expand Up @@ -1905,6 +1909,14 @@ describe('datepicker directive', function () {
clickTitleButton();
expect(getTitle()).toBe('2013');
});

it('disables the title button at it', function() {
expect(getTitleButton().prop('disabled')).toBe(false);
clickTitleButton();
expect(getTitleButton().prop('disabled')).toBe(true);
clickTitleButton();
expect(getTitleButton().prop('disabled')).toBe(true);
});
});

describe('with an ngModelController having formatters and parsers', function() {
Expand Down
2 changes: 1 addition & 1 deletion template/datepicker/day.html
Expand Up @@ -2,7 +2,7 @@
<thead>
<tr>
<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>
<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>
<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>
<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>
</tr>
<tr>
Expand Down
2 changes: 1 addition & 1 deletion template/datepicker/month.html
Expand Up @@ -2,7 +2,7 @@
<thead>
<tr>
<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>
<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>
<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>
<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>
</tr>
</thead>
Expand Down
2 changes: 1 addition & 1 deletion template/datepicker/year.html
Expand Up @@ -2,7 +2,7 @@
<thead>
<tr>
<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>
<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>
<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>
<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>
</tr>
</thead>
Expand Down

0 comments on commit 35b8512

Please sign in to comment.