diff --git a/src/datepicker/datepicker.js b/src/datepicker/datepicker.js index cad3c5067a..0464a442b1 100644 --- a/src/datepicker/datepicker.js +++ b/src/datepicker/datepicker.js @@ -16,6 +16,7 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst maxMode: 'year', minDate: null, minMode: 'day', + monthColumns: 3, ngModelOptions: {}, shortcutPropagation: false, showWeeks: true, @@ -52,6 +53,7 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst 'maxMode', 'minDate', 'minMode', + 'monthColumns', 'showWeeks', 'shortcutPropagation', 'startingDay', @@ -77,6 +79,7 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst $interpolate($scope.datepickerOptions[key])($scope.$parent) : datepickerConfig[key]; break; + case 'monthColumns': case 'showWeeks': case 'shortcutPropagation': case 'yearColumns': @@ -480,7 +483,8 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst } scope.title = dateFilter(this.activeDate, this.formatMonthTitle); - scope.rows = this.split(months, 3); + scope.rows = this.split(months, this.monthColumns); + scope.yearHeaderColspan = this.monthColumns > 3 ? this.monthColumns - 2 : 1; }; this.compare = function(date1, date2) { @@ -497,11 +501,11 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst if (key === 'left') { date = date - 1; } else if (key === 'up') { - date = date - 3; + date = date - this.monthColumns; } else if (key === 'right') { date = date + 1; } else if (key === 'down') { - date = date + 3; + date = date + this.monthColumns; } else if (key === 'pageup' || key === 'pagedown') { var year = this.activeDate.getFullYear() + (key === 'pageup' ? - 1 : 1); this.activeDate.setFullYear(year); diff --git a/src/datepicker/docs/readme.md b/src/datepicker/docs/readme.md index e46d00f47b..d1928e272d 100644 --- a/src/datepicker/docs/readme.md +++ b/src/datepicker/docs/readme.md @@ -104,6 +104,11 @@ Apart from the previous settings, to configure the uib-datepicker you need to cr _(Default: `day`)_ - Sets a lower limit for mode. + * `monthColumns` + C + _(Default: `3`)_ - + Number of columns displayed in month selection. + * `ngModelOptions` C _(Default: `null`)_ - @@ -123,7 +128,7 @@ Apart from the previous settings, to configure the uib-datepicker you need to cr C *(Default: `$locale.DATETIME_FORMATS.FIRSTDAYOFWEEK`)* - Starting day of the week from 0-6 (0=Sunday, ..., 6=Saturday). - + * `yearRows` C _(Default: `4`)_ - diff --git a/src/datepicker/test/datepicker.spec.js b/src/datepicker/test/datepicker.spec.js index 1a1e06aa62..2f94a29e57 100644 --- a/src/datepicker/test/datepicker.spec.js +++ b/src/datepicker/test/datepicker.spec.js @@ -26,8 +26,12 @@ describe('datepicker', function() { }); })); + function getTitleCell() { + return element.find('th').eq(1); + } + function getTitleButton() { - return element.find('th').eq(1).find('button').first(); + return getTitleCell().find('button').first(); } function getTitle() { @@ -1325,6 +1329,7 @@ describe('datepicker', function() { uibDatepickerConfig.yearRows = 2; uibDatepickerConfig.yearColumns = 5; uibDatepickerConfig.startingDay = 6; + uibDatepickerConfig.monthColumns = 4; element = $compile('')($rootScope); $rootScope.$digest(); @@ -1346,13 +1351,17 @@ describe('datepicker', function() { expect(getTitle()).toBe('10'); expect(getOptions()).toEqual([ - ['Jan', 'Feb', 'Mar'], - ['Apr', 'May', 'Jun'], - ['Jul', 'Aug', 'Sep'], - ['Oct', 'Nov', 'Dec'] + ['Jan', 'Feb', 'Mar', 'Apr'], + ['May', 'Jun', 'Jul', 'Aug'], + ['Sep', 'Oct', 'Nov', 'Dec'] ]); }); + it('shows title year button to expand to fill width in `month` mode', function() { + clickTitleButton(); + expect(getTitleCell().attr('colspan')).toBe('2'); + }); + it('changes the title, year format & range in `year` mode', function() { clickTitleButton(); clickTitleButton(); diff --git a/template/datepicker/month.html b/template/datepicker/month.html index 1aff9c8f14..d9c979d188 100644 --- a/template/datepicker/month.html +++ b/template/datepicker/month.html @@ -2,7 +2,7 @@ - +