Skip to content

Commit

Permalink
Currently, the user can navigate today's date using the HOME button e…
Browse files Browse the repository at this point in the history
…ven though it's not in the user selectable range. This change restricts the user from doing so and aligns keyboard navigation behavior on unselectable date range with arrows keys and Page Up/Down key. See bug b/293322186 for more information.

RELNOTES: Restrict the user from navigating to unselectable dates using the HOME button.
PiperOrigin-RevId: 551619364
Change-Id: I5924d32fca81b4a1b4b700399371ee03a4b5225f
  • Loading branch information
Closure Team authored and Copybara-Service committed Jul 27, 2023
1 parent 66d433d commit f94055a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
5 changes: 4 additions & 1 deletion closure/goog/ui/datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,10 @@ goog.ui.DatePicker.prototype.nextYear = function() {
*/
goog.ui.DatePicker.prototype.selectToday = function() {
'use strict';
this.setDate(new goog.date.Date());
const today = new goog.date.Date();
if (this.isUserSelectableDate_(today)) {
this.setDate(today);
}
};


Expand Down
21 changes: 21 additions & 0 deletions closure/goog/ui/datepicker_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,27 @@ testSuite({
assertEquals(picker.elTable_[2 + 1][3], document.activeElement);
},

/** @suppress {visibility} suppression added to enable type checking */
testKeyboardNavigationOnUnselectableRange_homeKey() {
// This is a Sunday, so it's the first cell in the grid.
picker = new DatePicker(new Date(2017, 9, 1));
// Make the first column be Sunday, not week numbers
picker.setShowWeekNum(false);
picker.render(dom.getElement('sandbox'));
const selectEvents = recordFunction();
const changeEvents = recordFunction();
events.listen(picker, DatePicker.Events.SELECT, selectEvents);
events.listen(picker, DatePicker.Events.CHANGE, changeEvents);
picker.setUserSelectableDateRange(
new DateRange(new DateDate(200, 1, 1), new DateDate(300, 1, 1)));

testingEvents.fireNonAsciiKeySequence(
picker.getElement(), KeyCodes.HOME, KeyCodes.HOME);

changeEvents.assertCallCount(0);
selectEvents.assertCallCount(0);
},

testDayGridHasNonEmptyAriaLabels() {
picker = new DatePicker(new Date(2017, 8, 9));
picker.render(dom.getElement('sandbox'));
Expand Down

0 comments on commit f94055a

Please sign in to comment.