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

[Bugfix] Keep initially set values of beginDate and endDate for datepicker #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mat-range-datepicker/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mat-range-datepicker",
"version": "0.2.0",
"version": "1.1.0",
"repository": "https://github.com/Sugarball/mat-range-datepicker",
"keywords": ["angular", "material", "datepicker", "range datepicker"],
"author": "sugarball <[email protected]>",
Expand Down
17 changes: 9 additions & 8 deletions mat-range-datepicker/src/datepicker/datepicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import {
} from '@angular/core';
import {CanColor, mixinColor, ThemePalette} from '@angular/material/core';
import {MatDialog, MatDialogRef} from '@angular/material/dialog';
import {merge, Subject, Subscription} from 'rxjs';
import {merge, Subject, BehaviorSubject, Subscription, combineLatest, Observable} from 'rxjs';
import {SatCalendar} from './calendar';
import {RangeCalendar} from './range-calendar';
import {matDatepickerAnimations} from './datepicker-animations';
Expand Down Expand Up @@ -173,17 +173,17 @@ export class matRangeDatepicker<D> implements OnDestroy, CanColor {
/** Whenever datepicker is for selecting range of dates. */
@Input()
get rangeMode(): boolean {
return this._rangeMode;
return this._rangeModeSubject.value;
}
set rangeMode(mode: boolean) {
this._rangeMode = mode;
if (this.rangeMode) {
if (mode) {
this._validSelected = null;
} else {
this._beginDate = this._endDate = null;
}
this._rangeModeSubject.next(mode);
}
private _rangeMode;
private _rangeModeSubject: BehaviorSubject<boolean> = new BehaviorSubject(false);

/** Start of dates interval. */
@Input()
Expand Down Expand Up @@ -411,14 +411,15 @@ export class matRangeDatepicker<D> implements OnDestroy, CanColor {
throw Error('A matRangeDatepicker can only be associated with a single input.');
}
this._datepickerInput = input;
const valueChanges = (<Observable<matRangeDatepickerRangeValue<D>|D|null>>this._datepickerInput._valueChange);
this._inputSubscription =
this._datepickerInput._valueChange
.subscribe((value: matRangeDatepickerRangeValue<D> | D | null) => {
combineLatest(valueChanges, this._rangeModeSubject)
.subscribe(([value, rangeMode]) => {
if (value === null) {
this.beginDate = this.endDate = this._selected = null;
return;
}
if (this.rangeMode) {
if (rangeMode) {
value = <matRangeDatepickerRangeValue<D>>value;
if (value.begin && value.end &&
this._dateAdapter.compareDate(value.begin, value.end) <= 0) {
Expand Down
Loading