junyeong0619 commented on code in PR #66251:
URL: https://github.com/apache/airflow/pull/66251#discussion_r3219924015
##########
airflow-core/src/airflow/ui/src/components/DateTimeInput.tsx:
##########
@@ -54,16 +54,31 @@ export const DateTimeInput = forwardRef<HTMLInputElement,
Props>(({ onChange, va
debounceDelay,
);
+ const onPaste = (event: ClipboardEvent<HTMLInputElement>) => {
+ const pasted = event.clipboardData.getData("text");
+ const parsed = dayjs(pasted);
+
+ if (parsed.isValid()) {
+ event.preventDefault();
+ // datetime-local input requires YYYY-MM-DDTHH:mm format
+ const localFormat = parsed.format("YYYY-MM-DDTHH:mm");
+
+ setDisplayDate(localFormat);
+ onDateChange({
+ ...event,
+ target: { ...event.currentTarget, value: localFormat },
+ } as unknown as ChangeEvent<HTMLInputElement>);
+ }
+ };
+
return (
<Input
data-testid="datetime-input"
onChange={(event) => {
- const local = dayjs(event.target.value).isValid() ? event.target.value
: "";
-
- setDisplayDate(local);
- // Parse input to UTC once user finishes typing
Review Comment:
This refactor was based on @bbovenzi's review on the previous attempt
(#65461):
> onPaste and onChange are both parsing a string. Let's try to pull
> out the shared logic into one function. Probably by modifying
> onDateChange since onPaste doesn't need debouncing.
onPaste now calls onDateChange directly (no debounce), and the onChange
cleanup keeps both paths consistent.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]