I'd like to perform some actions when mat-datepicker popup closes but only if user clicked on a date (action should not trigger if popup was closed by escape key or backdrop click).
I know there is a @Output('closed') closedStream: EventEmitter<void>
but that is triggered every time popup is closed.
My idea was to detect if there is a dateChange event between opened and closed events but that does not work if the user clicks on the already selected date.
I tried to fix that with custom DateAdapter (overriding sameDate
or compareDate
method to return that selected date is always different then currently selected one) but it seems that mat-month-view
component is not using DateAdapter for comparing dates before emitting selection change:
_dateSelected(date: number) {
if (this._selectedDate != date) {
const selectedYear = this._dateAdapter.getYear(this.activeDate);
const selectedMonth = this._dateAdapter.getMonth(this.activeDate);
const selectedDate = this._dateAdapter.createDate(selectedYear, selectedMonth, date);
this.selectedChange.emit(selectedDate);
}
this._userSelection.emit();
}
Not sure if this in itself is a bug or not...
Does anybody know a simpler way to know if material datepicker popup was closed due to date selection? Am i missing something obvious?
Thanks!