Skip to content

Commit 8099e63

Browse files
committed
fix: TT-230 implement datepicker safari on Reports
1 parent 5b2126f commit 8099e63

File tree

4 files changed

+26
-12
lines changed

4 files changed

+26
-12
lines changed

src/app/modules/reports/components/time-range-form/time-range-form.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ export class TimeRangeFormComponent implements OnInit {
2929

3030
setInitialDataOnScreen() {
3131
this.reportForm.setValue({
32-
startDate: formatDate(moment().startOf('week').toString(), DATE_FORMAT, 'en'),
33-
endDate: formatDate(moment().endOf('week').toString(), DATE_FORMAT, 'en')
32+
startDate: formatDate(moment().startOf('week').format('l'), DATE_FORMAT, 'en'),
33+
endDate: formatDate(moment().endOf('week').format('l'), DATE_FORMAT, 'en')
3434
});
3535
this.onSubmit();
3636
}
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
<input
22
[value]="value"
33
[disabled]="isDisabled"
4-
(input)="onInput($event.target.value)"
5-
type="date"
4+
(dateInput)="onInput($event.target.value.format('YYYY-MM-DD'))"
65
class="form-control"
76
aria-label="Small"
87
aria-describedby="inputGroup-sizing-sm"
98
required="required"
9+
[matDatepicker]="datepicker"
10+
(click)="openOrCloseDatePicker(datepicker)"
1011
/>
12+
<mat-datepicker #datepicker ></mat-datepicker>

src/app/modules/shared/components/input-date/input-date.component.spec.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
1-
import {waitForAsync, ComponentFixture, fakeAsync, TestBed, tick} from '@angular/core/testing';
2-
import {InputDateComponent} from './input-date.component';
1+
import { waitForAsync, ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
2+
import { MatMomentDateModule } from '@angular/material-moment-adapter';
3+
import { MatInputModule } from '@angular/material/input';
4+
import { MatDatepickerModule } from '@angular/material/datepicker';
5+
import { InputDateComponent } from './input-date.component';
6+
import * as moment from 'moment';
37

48
describe('InputDateComponent', () => {
59
let component: InputDateComponent;
610
let fixture: ComponentFixture<InputDateComponent>;
711
let input;
812

9-
beforeEach(waitForAsync(() => {
10-
TestBed.configureTestingModule({
11-
declarations: [InputDateComponent]
12-
}).compileComponents();
13-
}));
13+
beforeEach(
14+
waitForAsync(() => {
15+
TestBed.configureTestingModule({
16+
declarations: [InputDateComponent],
17+
imports: [MatInputModule, MatDatepickerModule, MatMomentDateModule],
18+
}).compileComponents();
19+
})
20+
);
1421

1522
beforeEach(() => {
1623
fixture = TestBed.createComponent(InputDateComponent);
@@ -25,7 +32,7 @@ describe('InputDateComponent', () => {
2532
});
2633

2734
it('should insert the provided text into the component', fakeAsync(() => {
28-
setInputValue('input', '2020-05-20');
35+
setInputValue('input', moment('2020-05-20').format('l'));
2936

3037
expect(component.value).toEqual('2020-05-20');
3138
}));

src/app/modules/shared/components/input-date/input-date.component.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {Component, forwardRef} from '@angular/core';
22
import {ControlValueAccessor, NG_VALUE_ACCESSOR} from '@angular/forms';
3+
import { MatDatepicker } from '@angular/material/datepicker';
34

45
@Component({
56
selector: 'app-input-date',
@@ -47,4 +48,8 @@ export class InputDateComponent implements ControlValueAccessor {
4748
setDisabledState(isDisabled: boolean): void {
4849
this.isDisabled = isDisabled;
4950
}
51+
52+
openOrCloseDatePicker(datepicker: MatDatepicker<Date>): void {
53+
return datepicker.opened ? datepicker.close() : datepicker.open();
54+
}
5055
}

0 commit comments

Comments
 (0)