Skip to content

Commit 96efaad

Browse files
crisbetoxlou978jaguimammalerbaroboshoes
authored
feat(datepicker): add date range picker (#19125)
* 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 <[email protected]> * 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 <[email protected]> Co-authored-by: jaguima <[email protected]> Co-authored-by: mmalerba <[email protected]> Co-authored-by: roboshoes <[email protected]> Co-authored-by: goldblatt <[email protected]> * 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 <[email protected]> Co-authored-by: jaguima <[email protected]> Co-authored-by: mmalerba <[email protected]> Co-authored-by: roboshoes <[email protected]> Co-authored-by: goldblatt <[email protected]>
1 parent 658896f commit 96efaad

File tree

54 files changed

+4908
-1088
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+4908
-1088
lines changed

goldens/ts-circular-deps.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@
5252
"src/material/core/ripple/ripple-ref.ts",
5353
"src/material/core/ripple/ripple-renderer.ts"
5454
],
55+
[
56+
"src/material/datepicker/date-range-input.ts",
57+
"src/material/datepicker/date-range-picker.ts"
58+
],
5559
[
5660
"src/material/datepicker/datepicker-input.ts",
5761
"src/material/datepicker/datepicker.ts"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.example-form-field {
2+
margin: 0 8px 16px 0;
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<mat-form-field class="example-form-field">
2+
<mat-label>First campaign</mat-label>
3+
<mat-date-range-input
4+
[formGroup]="campaignOne"
5+
[rangePicker]="campaignOnePicker"
6+
[comparisonStart]="campaignTwo.value.start"
7+
[comparisonEnd]="campaignTwo.value.end">
8+
<input matStartDate matInput placeholder="Start date" formControlName="start">
9+
<input matEndDate matInput placeholder="End date" formControlName="end">
10+
</mat-date-range-input>
11+
<mat-datepicker-toggle matSuffix [for]="campaignOnePicker"></mat-datepicker-toggle>
12+
<mat-date-range-picker #campaignOnePicker></mat-date-range-picker>
13+
</mat-form-field>
14+
15+
<mat-form-field class="example-form-field">
16+
<mat-label>Second campaign</mat-label>
17+
<mat-date-range-input
18+
[formGroup]="campaignTwo"
19+
[rangePicker]="campaignTwoPicker"
20+
[comparisonStart]="campaignOne.value.start"
21+
[comparisonEnd]="campaignOne.value.end">
22+
<input matStartDate matInput placeholder="Start date" formControlName="start">
23+
<input matEndDate matInput placeholder="End date" formControlName="end">
24+
</mat-date-range-input>
25+
<mat-datepicker-toggle matSuffix [for]="campaignTwoPicker"></mat-datepicker-toggle>
26+
<mat-date-range-picker #campaignTwoPicker></mat-date-range-picker>
27+
</mat-form-field>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import {Component} from '@angular/core';
2+
import {FormGroup, FormControl} from '@angular/forms';
3+
4+
/** @title Date range picker comparison ranges */
5+
@Component({
6+
selector: 'date-range-picker-comparison-example',
7+
templateUrl: 'date-range-picker-comparison-example.html',
8+
styleUrls: ['date-range-picker-comparison-example.css'],
9+
})
10+
export class DateRangePickerComparisonExample {
11+
campaignOne: FormGroup;
12+
campaignTwo: FormGroup;
13+
14+
constructor() {
15+
const today = new Date();
16+
const month = today.getMonth();
17+
const year = today.getFullYear();
18+
19+
this.campaignOne = new FormGroup({
20+
start: new FormControl(new Date(year, month, 13)),
21+
end: new FormControl(new Date(year, month, 16))
22+
});
23+
24+
this.campaignTwo = new FormGroup({
25+
start: new FormControl(new Date(year, month, 15)),
26+
end: new FormControl(new Date(year, month, 19))
27+
});
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/** No CSS for this example */
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<mat-form-field>
2+
<mat-label>Enter a date range</mat-label>
3+
<mat-date-range-input [formGroup]="range" [rangePicker]="picker">
4+
<input matStartDate matInput formControlName="start" placeholder="Start date">
5+
<input matEndDate matInput formControlName="end" placeholder="End date">
6+
</mat-date-range-input>
7+
<mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
8+
<mat-date-range-picker #picker></mat-date-range-picker>
9+
10+
<mat-error *ngIf="range.controls.start.hasError('matStartDateInvalid')">Invalid start date</mat-error>
11+
<mat-error *ngIf="range.controls.end.hasError('matEndDateInvalid')">Invalid end date</mat-error>
12+
</mat-form-field>
13+
14+
<p>Selected range: {{range.value | json}}</p>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import {Component} from '@angular/core';
2+
import {FormGroup, FormControl} from '@angular/forms';
3+
4+
/** @title Date range picker forms integration */
5+
@Component({
6+
selector: 'date-range-picker-forms-example',
7+
templateUrl: 'date-range-picker-forms-example.html',
8+
styleUrls: ['date-range-picker-forms-example.css'],
9+
})
10+
export class DateRangePickerFormsExample {
11+
range = new FormGroup({
12+
start: new FormControl(),
13+
end: new FormControl()
14+
});
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/** No CSS for this example */
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<mat-form-field>
2+
<mat-label>Enter a date range</mat-label>
3+
<mat-date-range-input [rangePicker]="picker">
4+
<input matStartDate matInput placeholder="Start date">
5+
<input matEndDate matInput placeholder="End date">
6+
</mat-date-range-input>
7+
<mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
8+
<mat-date-range-picker #picker></mat-date-range-picker>
9+
</mat-form-field>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import {Component} from '@angular/core';
2+
3+
/** @title Basic date range picker */
4+
@Component({
5+
selector: 'date-range-picker-overview-example',
6+
templateUrl: 'date-range-picker-overview-example.html',
7+
styleUrls: ['date-range-picker-overview-example.css'],
8+
})
9+
export class DateRangePickerOverviewExample {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/** No CSS for this example */
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<mat-form-field>
2+
<mat-label>Enter a date range</mat-label>
3+
<mat-date-range-input [rangePicker]="picker">
4+
<input matStartDate matInput placeholder="Start date">
5+
<input matEndDate matInput placeholder="End date">
6+
</mat-date-range-input>
7+
<mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
8+
<mat-date-range-picker #picker></mat-date-range-picker>
9+
</mat-form-field>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import {Component, Injectable} from '@angular/core';
2+
import {DateAdapter} from '@angular/material/core';
3+
import {
4+
MatDateRangeSelectionStrategy,
5+
DateRange,
6+
MAT_DATE_RANGE_SELECTION_STRATEGY,
7+
} from '@angular/material/datepicker';
8+
9+
@Injectable()
10+
export class FiveDayRangeSelectionStrategy<D> implements MatDateRangeSelectionStrategy<D> {
11+
constructor(private _dateAdapter: DateAdapter<D>) {}
12+
13+
selectionFinished(date: D | null): DateRange<D> {
14+
return this._createFiveDayRange(date);
15+
}
16+
17+
createPreview(activeDate: D | null): DateRange<D> {
18+
return this._createFiveDayRange(activeDate);
19+
}
20+
21+
private _createFiveDayRange(date: D | null): DateRange<D> {
22+
if (date) {
23+
const start = this._dateAdapter.addCalendarDays(date, -2);
24+
const end = this._dateAdapter.addCalendarDays(date, 2);
25+
return new DateRange<D>(start, end);
26+
}
27+
28+
return new DateRange<D>(null, null);
29+
}
30+
}
31+
32+
/** @title Date range picker with custom a selection strategy */
33+
@Component({
34+
selector: 'date-range-picker-selection-strategy-example',
35+
templateUrl: 'date-range-picker-selection-strategy-example.html',
36+
styleUrls: ['date-range-picker-selection-strategy-example.css'],
37+
providers: [{
38+
provide: MAT_DATE_RANGE_SELECTION_STRATEGY,
39+
useClass: FiveDayRangeSelectionStrategy
40+
}]
41+
})
42+
export class DateRangePickerSelectionStrategyExample {}

src/components-examples/material/datepicker/index.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {CommonModule} from '@angular/common';
22
import {NgModule} from '@angular/core';
3-
import {ReactiveFormsModule} from '@angular/forms';
3+
import {ReactiveFormsModule, FormsModule} from '@angular/forms';
44
import {MatButtonModule} from '@angular/material/button';
55
import {MatNativeDateModule} from '@angular/material/core';
66
import {MatDatepickerModule} from '@angular/material/datepicker';
@@ -29,6 +29,18 @@ import {DatepickerValueExample} from './datepicker-value/datepicker-value-exampl
2929
import {
3030
DatepickerViewsSelectionExample
3131
} from './datepicker-views-selection/datepicker-views-selection-example';
32+
import {
33+
DateRangePickerOverviewExample
34+
} from './date-range-picker-overview/date-range-picker-overview-example';
35+
import {
36+
DateRangePickerFormsExample
37+
} from './date-range-picker-forms/date-range-picker-forms-example';
38+
import {
39+
DateRangePickerComparisonExample
40+
} from './date-range-picker-comparison/date-range-picker-comparison-example';
41+
import {
42+
DateRangePickerSelectionStrategyExample
43+
} from './date-range-picker-selection-strategy/date-range-picker-selection-strategy-example';
3244

3345
export {
3446
DatepickerApiExample,
@@ -48,6 +60,10 @@ export {
4860
DatepickerTouchExample,
4961
DatepickerValueExample,
5062
DatepickerViewsSelectionExample,
63+
DateRangePickerOverviewExample,
64+
DateRangePickerFormsExample,
65+
DateRangePickerComparisonExample,
66+
DateRangePickerSelectionStrategyExample,
5167
ExampleHeader,
5268
};
5369

@@ -69,6 +85,10 @@ const EXAMPLES = [
6985
DatepickerTouchExample,
7086
DatepickerValueExample,
7187
DatepickerViewsSelectionExample,
88+
DateRangePickerOverviewExample,
89+
DateRangePickerFormsExample,
90+
DateRangePickerComparisonExample,
91+
DateRangePickerSelectionStrategyExample,
7292
ExampleHeader,
7393
];
7494

@@ -81,6 +101,7 @@ const EXAMPLES = [
81101
MatIconModule,
82102
MatNativeDateModule,
83103
ReactiveFormsModule,
104+
FormsModule,
84105
],
85106
declarations: EXAMPLES,
86107
exports: EXAMPLES,

src/dev-app/datepicker/BUILD.bazel

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ ng_module(
2727
sass_binary(
2828
name = "datepicker_demo_scss",
2929
src = "datepicker-demo.scss",
30+
deps = [
31+
"//src/material/datepicker:datepicker_scss_lib",
32+
],
3033
)
3134

3235
sass_binary(

src/dev-app/datepicker/datepicker-demo-module.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@ import {MatIconModule} from '@angular/material/icon';
1818
import {MatInputModule} from '@angular/material/input';
1919
import {MatSelectModule} from '@angular/material/select';
2020
import {RouterModule} from '@angular/router';
21-
import {CustomHeader, CustomHeaderNgContent, DatepickerDemo} from './datepicker-demo';
21+
import {
22+
CustomHeader,
23+
CustomHeaderNgContent,
24+
DatepickerDemo,
25+
CustomRangeStrategy,
26+
} from './datepicker-demo';
2227

2328
@NgModule({
2429
imports: [
@@ -35,7 +40,7 @@ import {CustomHeader, CustomHeaderNgContent, DatepickerDemo} from './datepicker-
3540
ReactiveFormsModule,
3641
RouterModule.forChild([{path: '', component: DatepickerDemo}]),
3742
],
38-
declarations: [CustomHeader, CustomHeaderNgContent, DatepickerDemo],
43+
declarations: [CustomHeader, CustomHeaderNgContent, DatepickerDemo, CustomRangeStrategy],
3944
})
4045
export class DatepickerDemoModule {
4146
}

src/dev-app/datepicker/datepicker-demo.html

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,92 @@ <h2>Datepicker with custom header extending the default header</h2>
169169
<mat-datepicker #customHeaderNgContentPicker [calendarHeaderComponent]="customHeaderNgContent"></mat-datepicker>
170170
</mat-form-field>
171171
</p>
172+
173+
<h2>Range picker</h2>
174+
175+
<div class="demo-range-group">
176+
<mat-form-field>
177+
<mat-label>Enter a date range</mat-label>
178+
<mat-date-range-input
179+
[formGroup]="range1"
180+
[rangePicker]="range1Picker"
181+
[min]="minDate"
182+
[max]="maxDate"
183+
[disabled]="inputDisabled"
184+
[comparisonStart]="comparisonStart"
185+
[comparisonEnd]="comparisonEnd"
186+
[dateFilter]="filterOdd ? dateFilter : undefined">
187+
<input matStartDate formControlName="start" placeholder="Start date"/>
188+
<input matEndDate formControlName="end" placeholder="End date"/>
189+
</mat-date-range-input>
190+
<mat-datepicker-toggle [for]="range1Picker" matSuffix></mat-datepicker-toggle>
191+
<mat-date-range-picker
192+
[touchUi]="touch"
193+
[disabled]="datepickerDisabled"
194+
#range1Picker></mat-date-range-picker>
195+
</mat-form-field>
196+
<div>{{range1.value | json}}</div>
197+
</div>
198+
199+
<div class="demo-range-group">
200+
<mat-form-field appearance="fill">
201+
<mat-label>Enter a date range</mat-label>
202+
<mat-date-range-input
203+
[formGroup]="range2"
204+
[rangePicker]="range2Picker"
205+
[min]="minDate"
206+
[max]="maxDate"
207+
[disabled]="inputDisabled"
208+
[comparisonStart]="comparisonStart"
209+
[comparisonEnd]="comparisonEnd"
210+
[dateFilter]="filterOdd ? dateFilter : undefined">
211+
<input matStartDate formControlName="start" placeholder="Start date"/>
212+
<input matEndDate formControlName="end" placeholder="End date"/>
213+
</mat-date-range-input>
214+
<mat-datepicker-toggle [for]="range2Picker" matSuffix></mat-datepicker-toggle>
215+
<mat-date-range-picker
216+
[touchUi]="touch"
217+
[disabled]="datepickerDisabled"
218+
panelClass="demo-custom-range"
219+
#range2Picker></mat-date-range-picker>
220+
</mat-form-field>
221+
<div>{{range2.value | json}}</div>
222+
</div>
223+
224+
<div class="demo-range-group">
225+
<mat-form-field appearance="outline">
226+
<mat-label>Enter a date range</mat-label>
227+
<mat-date-range-input
228+
[formGroup]="range3"
229+
[rangePicker]="range3Picker"
230+
[min]="minDate"
231+
[max]="maxDate"
232+
[disabled]="inputDisabled"
233+
[comparisonStart]="comparisonStart"
234+
[comparisonEnd]="comparisonEnd"
235+
[dateFilter]="filterOdd ? dateFilter : undefined">
236+
<input matStartDate formControlName="start" placeholder="Start date"/>
237+
<input matEndDate formControlName="end" placeholder="End date"/>
238+
</mat-date-range-input>
239+
<mat-datepicker-toggle [for]="range3Picker" matSuffix></mat-datepicker-toggle>
240+
<mat-date-range-picker
241+
[touchUi]="touch"
242+
[disabled]="datepickerDisabled"
243+
#range3Picker></mat-date-range-picker>
244+
</mat-form-field>
245+
<div>{{range3.value | json}}</div>
246+
</div>
247+
248+
249+
<h2>Range picker with custom selection strategy</h2>
250+
<div class="demo-range-group">
251+
<mat-form-field>
252+
<mat-label>Enter a date range</mat-label>
253+
<mat-date-range-input [rangePicker]="range4Picker">
254+
<input matStartDate placeholder="Start date"/>
255+
<input matEndDate placeholder="End date"/>
256+
</mat-date-range-input>
257+
<mat-datepicker-toggle [for]="range4Picker" matSuffix></mat-datepicker-toggle>
258+
<mat-date-range-picker customRangeStrategy #range4Picker></mat-date-range-picker>
259+
</mat-form-field>
260+
</div>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1+
@import '../../material/datepicker/datepicker-theme';
2+
13
mat-calendar {
24
width: 300px;
35
}
46

7+
.demo-range-group {
8+
margin-bottom: 30px;
9+
}
10+
11+
.demo-custom-range {
12+
@include mat-date-range-colors(hotpink, teal, yellow, purple);
13+
}

0 commit comments

Comments
 (0)