Skip to content

Commit

Permalink
fix: datefilter bug
Browse files Browse the repository at this point in the history
  • Loading branch information
MarioCastigliano committed Oct 4, 2023
1 parent daffa0c commit 26fa0f4
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/components/sbb-calendar/sbb-calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,6 @@ export class SbbCalendar extends LitElement {

private _calendarController: AbortController;

public constructor() {
super();
this.dateFilter = () => true;
}

private _convertMinDate(newMin: Date | string | number): void {
this._min = this._dateAdapter.deserializeDate(newMin);
}
Expand All @@ -171,8 +166,7 @@ export class SbbCalendar extends LitElement {
const value = this._dateAdapter.deserializeDate(selectedDate);
if (
!!value &&
(!this._isDayInRange(this._dateAdapter.getISOString(value)) ||
(this.dateFilter ? this.dateFilter(value) : true))
(!this._isDayInRange(this._dateAdapter.getISOString(value)) || this.dateFilter(value))
) {
this._selected = this._dateAdapter.getISOString(value);
} else {
Expand All @@ -192,6 +186,9 @@ export class SbbCalendar extends LitElement {
public override connectedCallback(): void {
super.connectedCallback();

if (!this.dateFilter) {
this.dateFilter = () => true;
}
this.focus = () => {
this._resetFocus = true;
this._focusCell();
Expand Down Expand Up @@ -889,7 +886,7 @@ export class SbbCalendar extends LitElement {
private _createDayCells(week: Day[], today: string): TemplateResult[] {
return week.map((day: Day) => {
const isOutOfRange = !this._isDayInRange(day.value);
const isFilteredOut = !this.dateFilter(this._dateAdapter.createDateFromISOString(day.value));
const isFilteredOut = !this?.dateFilter(this._dateAdapter.createDateFromISOString(day.value));
const selected: boolean = !!this._selected && day.value === this._selected;
const dayValue = `${day.dayValue} ${day.monthValue} ${day.yearValue}`;
const isToday = day.value === today;
Expand Down

0 comments on commit 26fa0f4

Please sign in to comment.