Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Controls: Fix date picker control validation and assignment #26695

Merged
merged 8 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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