Skip to content

Commit

Permalink
Merge pull request #26695 from leeovictor/date-picker-fix
Browse files Browse the repository at this point in the history
Controls: fix date picker control validation and input value assign
  • Loading branch information
valentinpalkovic authored May 22, 2024
2 parents 0616c33 + 051b3ef commit 9226a94
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions code/ui/blocks/src/controls/Date.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,16 @@ export const DateControl: FC<DateProps> = ({ name, value, onChange, onFocus, onB
useEffect(() => {
if (valid !== false) {
if (dateRef && dateRef.current) {
dateRef.current.value = formatDate(value);
dateRef.current.value = value ? formatDate(value) : '';
}
if (timeRef && timeRef.current) {
timeRef.current.value = formatTime(value);
timeRef.current.value = value ? formatTime(value) : '';
}
}
}, [value]);

const onDateChange = (e: ChangeEvent<HTMLInputElement>) => {
if (!e.target.value) return onChange();
const parsed = parseDate(e.target.value);
const result = new Date(value);
result.setFullYear(parsed.getFullYear(), parsed.getMonth(), parsed.getDate());
Expand All @@ -92,6 +93,7 @@ export const DateControl: FC<DateProps> = ({ name, value, onChange, onFocus, onB
};

const onTimeChange = (e: ChangeEvent<HTMLInputElement>) => {
if (!e.target.value) return onChange();
const parsed = parseTime(e.target.value);
const result = new Date(value);
result.setHours(parsed.getHours());
Expand Down
2 changes: 1 addition & 1 deletion code/ui/blocks/src/controls/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export interface ControlProps<T> {
value?: T;
defaultValue?: T;
argType?: ArgType;
onChange: (value: T) => T | void;
onChange: (value?: T) => T | void;
onFocus?: (evt: any) => void;
onBlur?: (evt: any) => void;
}
Expand Down

0 comments on commit 9226a94

Please sign in to comment.