Skip to content
This repository was archived by the owner on Aug 1, 2024. It is now read-only.

Commit f94055a

Browse files
Closure Teamcopybara-github
authored andcommitted
Currently, the user can navigate today's date using the HOME button even 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
1 parent 66d433d commit f94055a

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

closure/goog/ui/datepicker.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,10 @@ goog.ui.DatePicker.prototype.nextYear = function() {
739739
*/
740740
goog.ui.DatePicker.prototype.selectToday = function() {
741741
'use strict';
742-
this.setDate(new goog.date.Date());
742+
const today = new goog.date.Date();
743+
if (this.isUserSelectableDate_(today)) {
744+
this.setDate(today);
745+
}
743746
};
744747

745748

closure/goog/ui/datepicker_test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,27 @@ testSuite({
581581
assertEquals(picker.elTable_[2 + 1][3], document.activeElement);
582582
},
583583

584+
/** @suppress {visibility} suppression added to enable type checking */
585+
testKeyboardNavigationOnUnselectableRange_homeKey() {
586+
// This is a Sunday, so it's the first cell in the grid.
587+
picker = new DatePicker(new Date(2017, 9, 1));
588+
// Make the first column be Sunday, not week numbers
589+
picker.setShowWeekNum(false);
590+
picker.render(dom.getElement('sandbox'));
591+
const selectEvents = recordFunction();
592+
const changeEvents = recordFunction();
593+
events.listen(picker, DatePicker.Events.SELECT, selectEvents);
594+
events.listen(picker, DatePicker.Events.CHANGE, changeEvents);
595+
picker.setUserSelectableDateRange(
596+
new DateRange(new DateDate(200, 1, 1), new DateDate(300, 1, 1)));
597+
598+
testingEvents.fireNonAsciiKeySequence(
599+
picker.getElement(), KeyCodes.HOME, KeyCodes.HOME);
600+
601+
changeEvents.assertCallCount(0);
602+
selectEvents.assertCallCount(0);
603+
},
604+
584605
testDayGridHasNonEmptyAriaLabels() {
585606
picker = new DatePicker(new Date(2017, 8, 9));
586607
picker.render(dom.getElement('sandbox'));

0 commit comments

Comments
 (0)