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

Commit 39d9b98

Browse files
Mrmanwesleycho
authored andcommitted
feat(datepicker): add monthColumns
- Add `monthColumns` option Closes #5515 Closes #5935
1 parent 2d831bc commit 39d9b98

File tree

4 files changed

+28
-10
lines changed

4 files changed

+28
-10
lines changed

Diff for: src/datepicker/datepicker.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
1616
maxMode: 'year',
1717
minDate: null,
1818
minMode: 'day',
19+
monthColumns: 3,
1920
ngModelOptions: {},
2021
shortcutPropagation: false,
2122
showWeeks: true,
@@ -54,6 +55,7 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
5455
'maxMode',
5556
'minDate',
5657
'minMode',
58+
'monthColumns',
5759
'showWeeks',
5860
'shortcutPropagation',
5961
'startingDay',
@@ -79,6 +81,7 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
7981
$interpolate($scope.datepickerOptions[key])($scope.$parent) :
8082
datepickerConfig[key];
8183
break;
84+
case 'monthColumns':
8285
case 'showWeeks':
8386
case 'shortcutPropagation':
8487
case 'yearColumns':
@@ -488,7 +491,8 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
488491
}
489492

490493
scope.title = dateFilter(this.activeDate, this.formatMonthTitle);
491-
scope.rows = this.split(months, 3);
494+
scope.rows = this.split(months, this.monthColumns);
495+
scope.yearHeaderColspan = this.monthColumns > 3 ? this.monthColumns - 2 : 1;
492496
};
493497

494498
this.compare = function(date1, date2) {
@@ -505,11 +509,11 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
505509
if (key === 'left') {
506510
date = date - 1;
507511
} else if (key === 'up') {
508-
date = date - 3;
512+
date = date - this.monthColumns;
509513
} else if (key === 'right') {
510514
date = date + 1;
511515
} else if (key === 'down') {
512-
date = date + 3;
516+
date = date + this.monthColumns;
513517
} else if (key === 'pageup' || key === 'pagedown') {
514518
var year = this.activeDate.getFullYear() + (key === 'pageup' ? - 1 : 1);
515519
this.activeDate.setFullYear(year);

Diff for: src/datepicker/docs/readme.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ Apart from the previous settings, to configure the uib-datepicker you need to cr
104104
_(Default: `day`)_ -
105105
Sets a lower limit for mode.
106106

107+
* `monthColumns`
108+
<small class="badge">C</small>
109+
_(Default: `3`)_ -
110+
Number of columns displayed in month selection.
111+
107112
* `ngModelOptions`
108113
<small class="badge">C</small>
109114
_(Default: `null`)_ -
@@ -123,7 +128,7 @@ Apart from the previous settings, to configure the uib-datepicker you need to cr
123128
<small class="badge">C</small>
124129
*(Default: `$locale.DATETIME_FORMATS.FIRSTDAYOFWEEK`)* -
125130
Starting day of the week from 0-6 (0=Sunday, ..., 6=Saturday).
126-
131+
127132
* `yearRows`
128133
<small class="badge">C</small>
129134
_(Default: `4`)_ -

Diff for: src/datepicker/test/datepicker.spec.js

+14-5
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,12 @@ describe('datepicker', function() {
2626
});
2727
}));
2828

29+
function getTitleCell() {
30+
return element.find('th').eq(1);
31+
}
32+
2933
function getTitleButton() {
30-
return element.find('th').eq(1).find('button').first();
34+
return getTitleCell().find('button').first();
3135
}
3236

3337
function getTitle() {
@@ -1325,6 +1329,7 @@ describe('datepicker', function() {
13251329
uibDatepickerConfig.yearRows = 2;
13261330
uibDatepickerConfig.yearColumns = 5;
13271331
uibDatepickerConfig.startingDay = 6;
1332+
uibDatepickerConfig.monthColumns = 4;
13281333

13291334
element = $compile('<div uib-datepicker ng-model="date"></div>')($rootScope);
13301335
$rootScope.$digest();
@@ -1346,13 +1351,17 @@ describe('datepicker', function() {
13461351

13471352
expect(getTitle()).toBe('10');
13481353
expect(getOptions()).toEqual([
1349-
['Jan', 'Feb', 'Mar'],
1350-
['Apr', 'May', 'Jun'],
1351-
['Jul', 'Aug', 'Sep'],
1352-
['Oct', 'Nov', 'Dec']
1354+
['Jan', 'Feb', 'Mar', 'Apr'],
1355+
['May', 'Jun', 'Jul', 'Aug'],
1356+
['Sep', 'Oct', 'Nov', 'Dec']
13531357
]);
13541358
});
13551359

1360+
it('shows title year button to expand to fill width in `month` mode', function() {
1361+
clickTitleButton();
1362+
expect(getTitleCell().attr('colspan')).toBe('2');
1363+
});
1364+
13561365
it('changes the title, year format & range in `year` mode', function() {
13571366
clickTitleButton();
13581367
clickTitleButton();

Diff for: 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 uib-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 uib-title" ng-click="toggleMode()" ng-disabled="datepickerMode === maxMode" tabindex="-1"><strong>{{title}}</strong></button></th>
5+
<th colspan="{{::yearHeaderColspan}}"><button id="{{::uniqueId}}-title" role="heading" aria-live="assertive" aria-atomic="true" type="button" class="btn btn-default btn-sm uib-title" ng-click="toggleMode()" ng-disabled="datepickerMode === maxMode" tabindex="-1"><strong>{{title}}</strong></button></th>
66
<th><button type="button" class="btn btn-default btn-sm pull-right uib-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)