From 083f3a2d0d2db41ea60ecd87e579038efb2acede Mon Sep 17 00:00:00 2001 From: Gabriele Petronella Date: Thu, 14 Sep 2023 11:05:16 +0200 Subject: [PATCH 1/2] Remove unnecessary workaround --- packages/bento-design-system/src/TimeField/TimeField.tsx | 5 ----- 1 file changed, 5 deletions(-) diff --git a/packages/bento-design-system/src/TimeField/TimeField.tsx b/packages/bento-design-system/src/TimeField/TimeField.tsx index 841aa30dd..33837cbd3 100644 --- a/packages/bento-design-system/src/TimeField/TimeField.tsx +++ b/packages/bento-design-system/src/TimeField/TimeField.tsx @@ -24,9 +24,6 @@ export function TimeField(props: Props) { const { locale } = useLocale(); const validationState = props.isReadOnly ? undefined : props.issues ? "invalid" : "valid"; - // NOTE(gabro): not sure why we need this cast, but we get a build error if we remove it - const value = props.value as TimeValue | undefined; - const onChange = (value: TimeValue) => { const time = new Time(value.hour, value.minute, value.second, value.millisecond); return props.onChange(time); @@ -37,7 +34,6 @@ export function TimeField(props: Props) { validationState, isDisabled: props.disabled, locale, - value, onChange, }); const ref = useRef(null); @@ -45,7 +41,6 @@ export function TimeField(props: Props) { const { labelProps, fieldProps, descriptionProps, errorMessageProps } = useTimeField( { ...props, - value, onChange, }, state, From a373251ec4f39ac42502cba01b729b9352a36568 Mon Sep 17 00:00:00 2001 From: Gabriele Petronella Date: Thu, 14 Sep 2023 11:05:32 +0200 Subject: [PATCH 2/2] Handle null in TimeField internal onChange This is not reflected in the react-aria types, but it's happening at runtime regardless. --- packages/bento-design-system/src/TimeField/TimeField.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/bento-design-system/src/TimeField/TimeField.tsx b/packages/bento-design-system/src/TimeField/TimeField.tsx index 33837cbd3..551f0ad3d 100644 --- a/packages/bento-design-system/src/TimeField/TimeField.tsx +++ b/packages/bento-design-system/src/TimeField/TimeField.tsx @@ -24,7 +24,8 @@ export function TimeField(props: Props) { const { locale } = useLocale(); const validationState = props.isReadOnly ? undefined : props.issues ? "invalid" : "valid"; - const onChange = (value: TimeValue) => { + const onChange = (value: TimeValue | null) => { + if (value == null) return; const time = new Time(value.hour, value.minute, value.second, value.millisecond); return props.onChange(time); };