Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
fix(datepicker): Fix button label initialization.
Browse files Browse the repository at this point in the history
Closes APM-346025.
  • Loading branch information
nimrod13 authored and ffriedl89 committed Jan 13, 2022
1 parent 990c0b5 commit 067c1c8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,13 @@ describe('DtDatePicker', () => {
fixture.detectChanges();
}));

it('should correctly initialize the value label if a value is set', fakeAsync(() => {
expect(component.datePicker.value).toEqual(new Date(2020, 2, 25));
const label =
fixture.debugElement.nativeElement.querySelector('.dt-button-label');
expect(label.textContent).toContain('3/25/2020');
}));

it('should correctly set a value if it is passed to the datepicker', fakeAsync(() => {
component.datePicker.open();
tick();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,16 @@ export class DtDatePicker<T>
this.id = this.id;
}

ngOnInit(): void {
this._valueLabel = this.value
? this._dateAdapter.format(this.value, {
year: 'numeric',
month: 'numeric',
day: 'numeric',
})
: 'Select date';
}

ngOnDestroy(): void {
this._destroy$.next();
this._destroy$.complete();
Expand Down Expand Up @@ -451,7 +461,7 @@ export class DtDatePicker<T>
month: 'numeric',
day: 'numeric',
})
: '';
: 'Select date';
this._changeDetectorRef.markForCheck();
}

Expand Down

0 comments on commit 067c1c8

Please sign in to comment.