Skip to content

Commit 46cc4dd

Browse files
authored
fix: TT-205 in safari browser dont work the date picker (#668)
* fix: TT-205 In safari browser don t work the date picker * fix: TT-205 spaces and use constants * fix: TT-205 refactor code and move style
1 parent 65e525f commit 46cc4dd

File tree

9 files changed

+66
-9
lines changed

9 files changed

+66
-9
lines changed

angular.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"src/assets"
2525
],
2626
"styles": [
27+
"./node_modules/@angular/material/prebuilt-themes/indigo-pink.css",
2728
"node_modules/datatables.net-dt/css/jquery.dataTables.css",
2829
"node_modules/datatables.net-responsive-dt/css/responsive.dataTables.css",
2930
"./node_modules/bootstrap/dist/css/bootstrap.min.css",
@@ -106,6 +107,7 @@
106107
"src/assets"
107108
],
108109
"styles": [
110+
"./node_modules/@angular/material/prebuilt-themes/indigo-pink.css",
109111
"src/styles.scss"
110112
],
111113
"scripts": []

package-lock.json

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
"@angular/compiler": "~10.2.2",
2121
"@angular/core": "~10.2.2",
2222
"@angular/forms": "~10.2.2",
23+
"@angular/material": "^11.2.3",
24+
"@angular/material-moment-adapter": "^11.2.9",
2325
"@angular/platform-browser": "~10.2.2",
2426
"@angular/platform-browser-dynamic": "~10.2.2",
2527
"@angular/router": "~10.2.2",

src/app/app.module.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ import { StoreModule } from '@ngrx/store';
1111
import { EffectsModule } from '@ngrx/effects';
1212
import { StoreDevtoolsModule } from '@ngrx/store-devtools';
1313
import { DragDropModule } from '@angular/cdk/drag-drop';
14-
14+
import { MatDatepickerModule } from '@angular/material/datepicker';
15+
import { MatInputModule } from '@angular/material/input';
16+
import { MatMomentDateModule } from '@angular/material-moment-adapter';
1517
import { NgxPaginationModule } from 'ngx-pagination';
1618
import { AutocompleteLibModule } from 'angular-ng-autocomplete';
1719

@@ -134,6 +136,9 @@ const maskConfig: Partial<IConfig> = {
134136
],
135137
imports: [
136138
NgxMaskModule.forRoot(maskConfig),
139+
MatInputModule,
140+
MatDatepickerModule,
141+
MatMomentDateModule,
137142
CommonModule,
138143
BrowserModule,
139144
BrowserAnimationsModule,

src/app/modules/shared/components/details-fields/details-fields.component.html

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@
8282
<label class="col-12 col-sm-2">Date in:</label>
8383
<div class="col-12 col-sm-4">
8484
<input
85+
matInput
8586
formControlName="start_date"
8687
id="start_date"
87-
type="date"
8888
class="form-control"
8989
aria-label="Small"
9090
aria-describedby="inputGroup-sizing-sm"
@@ -93,7 +93,11 @@
9393
(ngModelChange)="onStartDateChange($event)"
9494
[max]="getCurrentDate()"
9595
onkeydown="return false"
96+
(click)="openOrCloseDatePicker(datepickerStartDate)"
97+
(dateInput)="start_date.setValue($event.value.format('YYYY-MM-DD'))"
98+
[matDatepicker]="datepickerStartDate"
9699
/>
100+
<mat-datepicker #datepickerStartDate></mat-datepicker>
97101
</div>
98102

99103
<label class="col-12 col-sm-2">Time in:</label>
@@ -112,17 +116,21 @@
112116
<label class="col-12 col-sm-2">Date out:</label>
113117
<div class="col-12 col-sm-4">
114118
<input
119+
matInput
115120
formControlName="end_date"
116121
id="end_date"
117-
type="date"
118122
class="form-control"
119123
aria-label="Small"
120124
aria-describedby="inputGroup-sizing-sm"
121125
[class.is-invalid]="end_date.invalid && end_date.touched"
122126
required
123127
[max]="getCurrentDate()"
124128
onkeydown="return false"
129+
(click)="openOrCloseDatePicker(datepickerEndDate)"
130+
(dateInput)="end_date.setValue($event.value.format('YYYY-MM-DD'))"
131+
[matDatepicker]="datepickerEndDate"
125132
/>
133+
<mat-datepicker #datepickerEndDate></mat-datepicker>
126134
</div>
127135

128136
<label class="col-12 col-sm-2">Time out:</label>

src/app/modules/shared/components/details-fields/details-fields.component.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,7 @@ input[type="date"]::-webkit-clear-button {
115115
border-radius: 5px;
116116
margin-top: 10px;
117117
}
118+
119+
::ng-deep .cdk-overlay-container {
120+
z-index: 1100 !important;
121+
}

src/app/modules/shared/components/details-fields/details-fields.component.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -489,14 +489,14 @@ describe('DetailsFieldsComponent', () => {
489489
});
490490

491491
it('on get current date should return expected date', () => {
492-
const expectedDate = new Date().toISOString().split('T')[0];
492+
const expectedDate = moment(new Date()).format(DATE_FORMAT_YEAR);
493493

494494
expect(component.getCurrentDate()).toEqual(expectedDate);
495495
});
496496

497497
it('on the input with id #start_date we could get the id and max value', () => {
498498
fixture.detectChanges();
499-
const expectedDate = new Date().toISOString().split('T')[0];
499+
const expectedDate = moment(new Date()).format(DATE_FORMAT_YEAR);
500500
const startDateInput: HTMLInputElement = fixture.debugElement.
501501
nativeElement.querySelector(`input[id="start_date"],input[max="${component.getCurrentDate()}"]`);
502502

@@ -506,7 +506,7 @@ describe('DetailsFieldsComponent', () => {
506506

507507
it('on the input with id #end_date we could get the current Date ', () => {
508508
fixture.detectChanges();
509-
const expectedDate = new Date().toISOString().split('T')[0];
509+
const expectedDate = moment(new Date()).format(DATE_FORMAT_YEAR);
510510
const endDateInput = fixture.debugElement.nativeElement.querySelector('[id=end_date]');
511511

512512
expect(endDateInput.id).toEqual('end_date');

src/app/modules/shared/components/details-fields/details-fields.component.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ import { EntryActionTypes } from './../../../time-clock/store/entry.actions';
1818
import { SaveEntryEvent } from './save-entry-event';
1919
import { ProjectSelectedEvent } from './project-selected-event';
2020
import { get } from 'lodash';
21-
import { DATE_FORMAT } from 'src/environments/environment';
21+
import { DATE_FORMAT, DATE_FORMAT_YEAR } from 'src/environments/environment';
2222
import { TechnologiesComponent } from '../technologies/technologies.component';
23+
import { MatDatepicker } from '@angular/material/datepicker';
2324

2425
type Merged = TechnologyState & ProjectState & ActivityState & EntryState;
2526
@Component({
@@ -192,7 +193,7 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
192193
}
193194

194195
getCurrentDate(): string {
195-
return new Date().toISOString().split('T')[0];
196+
return moment(new Date()).format(DATE_FORMAT_YEAR);
196197
}
197198

198199
get project_id() {
@@ -290,4 +291,8 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
290291
}
291292
this.shouldRestartEntry = !this.entryToEdit?.running && this.goingToWorkOnThis;
292293
}
294+
295+
openOrCloseDatePicker(datepicker: MatDatepicker<Date>): void {
296+
return datepicker.opened ? datepicker.close() : datepicker.open();
297+
}
293298
}

src/styles.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,5 @@ body {
3030

3131
.timepicker-backdrop-overlay {
3232
z-index: 1100 !important;
33-
}
33+
}
34+

0 commit comments

Comments
 (0)