Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DatePicker: Date selection/highlighting fixes #44

Merged
merged 3 commits into from
Sep 11, 2020

Conversation

mattheyan
Copy link

@mattheyan mattheyan commented Sep 11, 2020

This PR addresses inconsistencies in the way that "selected" dates are highlighted in the date picker calendar. The component's internal date property is used to drive a lot of behavior, but it doesn't always correspond to the component's "persisted" value (i.e. the value prop), and this can lead to some misleading styling. For example, when the picker is opened with no value, the default (ex: current date) is flagged as "selected", even though it isn't actually the current value, and if the picker is closed it won't be persisted. Also, in that case, when navigating to previous/next months and years, another date is marked as "selected", which is also not the persisted value. To address this, don't take into account the date data property when adding the class for the selected date.

Related: Don't select a date and emit the event when Enter key is pressed. This behavior was added when arrow key controls were implemented, however, since then it has been changed such that arrow keys immediately emit the new value. So, the enter key behavior only has the effect of choosing the non-persisted date in other, unexpected scenarios, ex: after navigating to prev/next months or years.

This is now redundant, since arrow keys immediately emit the selected
date. The effect is that in other contexts (ex: when navigating using
the prev/next links), when enter is pressed it selects the highlighted
date in addition to any other action that it would normally do.
@mattheyan mattheyan changed the title Date picker highlight DatePicker: Date selection/highlighting fixes Sep 11, 2020
@@ -267,7 +267,7 @@
classes.push('default');
}

if (selectionMode === 'day' && (cell.type === 'normal' || cell.type === 'today') && this.cellMatchesDate(cell, this.date || this.value)) {
if (selectionMode === 'day' && (cell.type === 'normal' || cell.type === 'today') && this.cellMatchesDate(cell, this.value)) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this.date so that the "is-selected" class is only determined by the persisted value of the component.

@@ -462,9 +462,6 @@
event.stopPropagation();
event.preventDefault();
}
if (keyCode === 13 && this.userInputDate === null && this.userInputTime === null) { // Enter
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this old, obsolete Enter key behavior.

@mattheyan mattheyan marked this pull request as ready for review September 11, 2020 18:01
@mattheyan mattheyan merged commit c933a5a into cognito Sep 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants