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

fix(datepicker): allow same start and end dates for range #19098

Merged
merged 1 commit into from Apr 17, 2020

Conversation

crisbeto
Copy link
Member

Allows for a range to have the same start and end dates.

Allows for a range to have the same start and end dates.
@crisbeto crisbeto added P2 The issue is important to a large percentage of users, with a workaround merge safe labels Apr 17, 2020
@crisbeto crisbeto requested a review from mmalerba as a code owner April 17, 2020 18:04
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Apr 17, 2020
Copy link
Contributor

@mmalerba mmalerba left a comment

Choose a reason for hiding this comment

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

LGTM

@mmalerba mmalerba added lgtm action: merge The PR is ready for merge by the caretaker labels Apr 17, 2020
@crisbeto crisbeto merged commit 6481164 into angular:date-range Apr 17, 2020
crisbeto added a commit that referenced this pull request Apr 20, 2020
Allows for a range to have the same start and end dates.
andrewseguin pushed a commit that referenced this pull request May 5, 2020
* refactor(datepicker): implement date selection model provider  (#18090)

* Adds a date selection model (#17363)

* Adds a date selection model

* Adds a date selection model

* Use MatDateSelectionModel to model the selected value in MatDatepickerInput (#17497)

* Make the selection model injectable and add an `overlaps` method (#17766)

* Adds a date selection model (#17363)

* Adds a date selection model

* Adds a date selection model

* Add overlaps function to date selection model

* Trying to incorporate the new type definition (#17942)

* incoporate new type definition

* fix test and clean up the types a bit

* update api gold

* fix some nits

* fix lint

Co-authored-by: mmalerba <mmalerba@google.com>

* refactor(datepicker): implement date selection model provider

Reworks the datepicker-related directives to move the source of the value into the new datepicker selection provider.

Co-authored-by: xlou978 <51772166+xlou978@users.noreply.github.com>
Co-authored-by: jaguima <jaguima@gmail.com>
Co-authored-by: mmalerba <mmalerba@google.com>
Co-authored-by: roboshoes <mail@mathias-paumgarten.com>
Co-authored-by: goldblatt <suzgoldblatt@gmail.com>

* feat(datepicker): set up input for date range picker (#18159)

Sets up the UI and most of the boilerplate that we'll need for the input that is associated with a date range picker. Doesn't include any interactions with the datepicker itself yet.

* refactor: move common date input logic into base class (#18213)

Moves the common logic for a date input into a base class and implements it for the range inputs.

* refactor(datepicker): implement range selection model (#18247)

Implements the date range selection model in the individual range inputs.

* refactor: clean up datepicker base class abstract methods (#18278)

I had to do some hacky workarounds in order, because I couldn't figure out how to deal with an abstract class that was being passed into a mixin. These changes clean up the workarounds.

* refactor(datepicker): set up date range picker classes (#18292)

Moves some things around to set up the date range picker. Includes:
* Moves all of the datepicker logic into a base class so that it can be reused between the single and range selection.
* Makes the input being passed into a datepicker generic so that we can strongly type `MatDatepicker` to `MatDatepickerInput` and `MatDateRangePicker` to `MatDateRangeInput`.
* Sets up min, max and date filter validation for the date range picker.
* Hooks up the date range picker to the date range input.
* Makes it so that a generic datepicker can be passed to a datepicker toggle.
* Adds a `DateFilterFn` type so we don't have to repeat the signature for the filter function everywhere.

Note that while picking a date range somewhat works now, it's still a bit broken. The primary goal of these changes was to have all of components in place and wired up so that we can start working on the UI in follow-up PRs.

* feat(datepicker): initial styling for date range (#18369)

Reworks a few things in the calendar and adds the styling for the date range. A couple of notes:
* This isn't the final UX of when start/end ranges will be selected. I wanted to have most of the functionality in place before playing around with the UX.
* This approach currently has an issue where the range won't go from one month into another properly. The problem is that the date cells store the current day internally. I'll make a follow-up PR that'll address the issue by storing the timestamp instead.

* fix(datepicker): handle date ranges across multiple months (#18404)

Currently we don't handle date ranges across months, because we store the date cell's value as the date in the current month. These changes add another value that will be used comparisons and which is based on the time since epoch.

* feat(datepicker): polish up date range selector (#18531)

Makes a bunch of changes to polish up the behavior of the date range picker.

- Makes the range selection logic a bit smarter about when to pick start/end so that it's more intuitive.
- Fixes hovering over disabled cells triggering the range selection styles.
- Fixes a "changed after checked" error when selecting a range using the keyboard.
- Implements validation that the start isn't after the end, and that the end isn't before the start.
- Adds the missing ARIA attributes.
- Fixes being able to select the placeholders of a disabled range input.
- Adds the ability to disable the entire range input.
- Fixes the inputs not greying out their values when they're disabled.
- Makes the range input a bit smarter about which input to focus on click.

* chore: fix grammar

* fix(datepicker): cancel current range selection when pressing escape (#18630)

Adds some extra logic so that the user can abort the current range selection if they press the escape key.

* fix(datepicker): add gap between range rows and handle rtl (#18660)

* Makes the range background shorter so that there's a gap when a range spans across multiple rows. This makes it easier to see what's going on.
* Fixes the range styles not accounting for RTL layouts.

* feat(datepicker): implement comparison and overlap ranges (#18753)

Adds the ability to render a comparison range in the date range picker. When the comparison overlaps with the primary range, the overlapping dates are shown in a separate "overlap" range.

* fix(datepicker): resolve visual inconsistencies with comparison ranges (#18819)

Fixes some extra circles showing up when they're not supposed to when hovering over the start of the range or when the starts/ends of ranges are the same. Also clears out a few selectors that aren't necessary anymore.

* test(datepicker): add unit tests for the date range input (#18874)

Sets up unit tests for the `mat-date-range-input` component.

* test(datepicker): add tests for the date range picker (#18884)

Adds more tests for the date range picker functionality. These cover the logic for displaying and selecting the range, as well as the integration between the range input, range picker and calendar.

Also fixes a couple of smaller issues that were revealed while I was writing the tests.

* refactor(datepicker): clean up date selection model (#18943)

- Removes some methods from the date selection model that were put in place under the assumption that they'd be used, but we never ended up using them.
- Moves the selection model out of `core` and into `datepicker`. I decided to do it, because it seems very tightly coupled to the datepicker and I don't see us needing it in other components in the future.

* refactor(datepicker): align preview range appearance with Material Design spec (#18936)

Our current approach to styling the preview range in the same way as the selected range is discouraged by the Material Design spec and may make it hard in the future if we made it possible to have both a preview and selected range at the same time. These changes align with the spec by using a dashed outline instead.

* build: fix ci issues

* feat(datepicker): allow for date range selection logic to be customized (#18980)

As discussed, adds a provider that allows the consumer to customize how the range is changed after the user has selected a value. For now it only has one method (`selectionFinished`), but the interface should allow us to add more later on.

* fix(datepicker): range input label pointing to non-existent id (#19031)

This is something that I put the code in for in the beginning, but forgot to wire up. The `aria-owns` of the `label` in the `mat-form-field` needs to point to the id of the start input, but it didn't have an id.

* fix(datepicker): allow same start and end dates for range (#19098)

Allows for a range to have the same start and end dates.

* feat(datepicker): allow for the preview range logic to be customized (#19088)

Moves some things around so that the preview range can be controlled through the `MatCalendarRangeSelectionStrategy`.

* fix(datepicker): don't render invalid ranges and clean up range display logic (#19111)

No longer shows dates on the calendar if the range is invalid. Also moves out some common range logic that was being repeated in multiple places.

* fix: golden failure

* fix: remove unused method

* fix(datepicker): changed after checked error when moving preview between months (#19174)

Fixes a "changed after checked" error being thrown if the user has an active preview and they move to a different month using the keyboard. This is something that we had a fix for, but after #19088 it has to be moved one component up, because the binding that changes is in a different view.

* fix(datepicker): clearing completed range when pressing escape (#19179)

The check for when pressing escape should clear a range wasn't quite right which meant that pressing escape would clear a completed range. The intention was to only clear the range if the user has a start, but not an end.

* fix(datepicker): end input reset on load when bound through ngModel (#19176)

This is something I found while I was writing the live examples. When both the start and end inputs have an initial value bound through `ngModel`, the start resets the end, because the end's value wasn't yet defined at the time the start was assigning its value. These changes fix the issue by treating the entire input as a single unit when it comes to change events.

* fix(datepicker): change event dispatched before value is formatted (#19187)

Fixes the `dateChange` event being fired before the value is assigned to the native input value.

* fix(datepicker): calendar dispatching change event on non-user interactions

The calendar was changed to dispatch its `selectedChange` event for some non-user interactions. These changes restore the old behavior.

* fix(datepicker): unable to type in range inputs

In a previous fix I added some changes so that typing in an input counts as typing inside the entire date range input. The problem is that this causes some extra events to be fired which result in the user's typed value being overwritten as they're typing. These changes revert the previous fix and resolve the issue in a different way.

* fix(datepicker): user selection event not emitting value when clicking on the selected date (#19211)

If the user clicks on the selected date, we were emitting null instead of the actual value.

* refactor(datepicker): move date range selection logic out of calendar (#19219)

There are some projects that expect that the `mat-calendar` doesn't assign the value itself, but only renders it out and emits an event when something is selected. These changes move the date selection logic out into the `MatDatepickerContent`.

Also renames the calendar range selection strategy since it doesn't have much to do with the calendar anymore.

* fix(datepicker): move focus into start input when pressing backspace on end input (#19239)

Makes it so that pressing backspace on an empty end input moves focus into the start input. This makes the two separate inputs feel a bit more like a single input.

* docs(datepicker): add docs and live example for date range picker (#19170)

Sets up some live examples and adds docs for the date range picker.

Co-authored-by: xlou978 <51772166+xlou978@users.noreply.github.com>
Co-authored-by: jaguima <jaguima@gmail.com>
Co-authored-by: mmalerba <mmalerba@google.com>
Co-authored-by: roboshoes <mail@mathias-paumgarten.com>
Co-authored-by: goldblatt <suzgoldblatt@gmail.com>
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators May 18, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement P2 The issue is important to a large percentage of users, with a workaround
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants