This repository has been archived by the owner on Apr 13, 2022. It is now read-only.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
We need the ability to persist the state of the datepicker across page loads. This presents a major UX problem related to presets: if the user selects a
Today
preset and then reloads the page on the next day, what’s the expected behavior?I don’t think there’s a single ‘right’ answer, but we decided that we wanted to go with ‘constantly updating’ presets.
Current behavior
The current behavior of datepicker is that any preset the user selects is immediately turned into a fixed daterange. So if the user selects
This month
on Jan 31, this is converted into the intervalJan 1 - Jan 31
and the component immediately forgets that the prefix was ever chosen. If the user reloads the “this month” view on Feb 1, they will again see theJan 1 - Jan 31
interval.Intended behavior
What we wanted to do is two-fold: First, we wanted to have the ability to actually keep the preset around and show it to the user after they’ve selected it. And second, we wanted to be able to read from the component when the user has chosen a preset as opposed to a date range, so that we can persist the specific user choice.
To continue the aforementioned example: has the user selected
This month
from the presets, or have they selected the interval fromJan 1
toJan 31
?Implementation
We introduce a new element with class
dr-date-preset
, which is by default hidden, and shown instead of the threedr-date-start
,dr-dates-dash
anddr-date-end
elements if a preset is currently selected.When a preset is selected, this element is shown and shows the title of the current preset. When that preset title is clicked, the title turns into the current date interval and the dropdown to choose another start and end date appears.
This new functionality has to be enabled by setting the new configuration flag
sticky_presets
totrue
, Theoretically, if you don’t set this new configuration option, the behavior of the component should be unchanged. But I leave it to the reviewers to confirm that.The change events (
callback
), now contain a new fieldpreset_label
which is set to the title of the preset if a preset was chosen, andnull
if a date interval was selected.A new component with this configuration has been added to the test page.
Credit
This feature branch was developed in pair programming by @SergLo and @hheimbuerger. Equal credit should be given, I just happen to be the messenger.
Preview