Skip to content

Commit c06e972

Browse files
committed
fix(#2664): move away from Date value within the calendar/datepicker
Since time is never wanted when selecting dates it only adds to complexity and adds issues regarding timezones. These changes replace the Date with a custom type and minimizes the use of the Date type to prevent breaking the current component binding.
1 parent 45b5320 commit c06e972

13 files changed

Lines changed: 1736 additions & 666 deletions

File tree

libs/angular-components/src/lib/components/date-picker/date-picker.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ import { GoabControlValueAccessor } from "../base.component";
5555
export class GoabDatePicker extends GoabControlValueAccessor implements OnInit {
5656
isReady = false;
5757
@Input() name?: string;
58-
// ** NOTE: can we just use the base component for this?
5958
@Input() override value?: Date | string | null | undefined;
6059
@Input() min?: Date | string;
6160
@Input() max?: Date | string;
@@ -100,6 +99,12 @@ export class GoabDatePicker extends GoabControlValueAccessor implements OnInit {
10099
this.isReady = true;
101100
this.cdr.detectChanges();
102101
}, 0);
102+
103+
if (this.value && typeof this.value !== "string") {
104+
console.warn(
105+
"Using a `Date` type for value is deprecated. Instead use a string of the format `yyyy-mm-dd`",
106+
);
107+
}
103108
}
104109

105110
override setDisabledState(isDisabled: boolean) {
@@ -120,7 +125,11 @@ export class GoabDatePicker extends GoabControlValueAccessor implements OnInit {
120125
if (!value) {
121126
this.renderer.setAttribute(datePickerEl, "value", "");
122127
} else {
123-
this.renderer.setAttribute(datePickerEl, "value", value instanceof Date ? value.toISOString() : value);
128+
this.renderer.setAttribute(
129+
datePickerEl,
130+
"value",
131+
value instanceof Date ? value.toISOString() : value,
132+
);
124133
}
125134
}
126135
}

libs/common/src/lib/common.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export type GoabInputOnFocusDetail<T = string> = GoabInputOnChangeDetail<T>;
2828

2929
export type GoabMenuButtonOnActionDetail = {
3030
action: string;
31-
}
31+
};
3232

3333
export type GoabInputAutoCapitalize =
3434
| "on"
@@ -70,7 +70,11 @@ export type GoabDropdownOnChangeDetail = {
7070

7171
export type GoabDatePickerOnChangeDetail = {
7272
name?: string;
73-
value: string | Date | undefined;
73+
valueStr: string;
74+
/**
75+
* @deprecated Use `valueStr` instead
76+
*/
77+
value: Date;
7478
};
7579
export type GoabDatePickerInputType = "calendar" | "input";
7680

@@ -1158,7 +1162,6 @@ export type GoabPublicFormStatus = "initializing" | "complete";
11581162
export type GoabPublicFormPageStep = "step" | "summary" | "multistep";
11591163
export type GoabPublicFormPageButtonVisibility = "visible" | "hidden";
11601164

1161-
11621165
// Public form Task
11631166
export type GoabPublicFormTaskStatus = "completed" | "not-started" | "cannot-start";
11641167

0 commit comments

Comments
 (0)