Calendar: Fix view when moving between multiple months with keyboard

Make sure numberOfMonths is taken into account while navigating with keyboard
when rendering multiple calendar grids (numberOfMonths > 1).
This commit is contained in:
Felix Nagel 2015-08-25 22:40:54 +02:00
parent 38101a478b
commit 09be7b328e
2 changed files with 18 additions and 3 deletions

View File

@ -257,9 +257,17 @@ test( "numberOfMonths", function() {
);
// Test for jumping in weekday rendering after click on last day of last grid
equal( container.find( "thead:last th:last" ).text(), "Sa", "Before click: Last day is saturday" );
container.find( "tbody:last td[id]:last button" ).trigger( "mousedown" );
equal( container.find( "thead:last th:last" ).text(), "Sa", "After click: Last day is saturday" );
equal( container.find( "thead:last th:last" ).text(), "Sa",
"After mousedown last month: Last day is Saturday"
);
// Test if using cursor down to go to the next month advances three month
container.find( "tbody:first td[id]:first button" ).trigger( "mousedown" );
$( document.activeElement ).simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } );
equal( container.find( ".ui-calendar-month:first" ).text(), "May",
"After move to previous month: First month is May"
);
});
/*

View File

@ -150,7 +150,14 @@ return $.widget( "ui.calendar", {
}
if ( this._needsRefresh() ) {
this._refresh();
if ( this.options.numberOfMonths > 1 && this.date.year() === this.viewDate.year() ) {
this.viewDate.adjust( "M", this.options.numberOfMonths *
( this.date.month() > this.viewDate.month() ? 1 : -1 )
);
this.refresh();
} else {
this._refresh();
}
this.grid.focus();
}