Field.DateTimeInput
Field.DateTimeInput은 Field 안에서 날짜와 시각을 로캘의 방식대로 입력하는 텍스트 입력입니다. value는 Temporal.PlainDateTime이나 null입니다. 텍스트는 확정될 때, 즉 포커스를 잃을 때, Enter를 누를 때, 폼을 제출할 때 읽고, formatDateTime이 쓰는 대로 다시 쓴 뒤 그 값으로 onValueChange를 호출합니다. 입력하는 것만으로는 아무것도 호출하지 않습니다. onValueChange가 없으면 입력은 읽기 전용입니다. Field.DateInput, Field.TimeInput처럼 동작하고, 뜻이 같은 props는 똑같이 받습니다. PlainDateTime에는 시간대가 없습니다. 사용자의 시계로 본 날짜와 시각입니다. 특정 시점으로 저장하려면 value.toZonedDateTime(zone)처럼 직접 작성한 코드에서 시간대와 합치세요.
이 페이지의 내용
import { Code, Field, Label, Stack } from '@tounsoo/todae';
import { useId, useState } from 'react';
// The value changes when the text is committed: on blur, on Enter, or when the form is submitted.
export default function FieldDateTimeInputAlone({ locale }: { locale: string }) {
const id = useId();
const [departs, setDeparts] = useState<Temporal.PlainDateTime | null>(null);
return (
<Stack.Root gap="condensed">
<Field.Group>
<Label.Root htmlFor={id}>Departs</Label.Root>
<Field.Root id={id} name="departs">
<Field.DateTimeInput value={departs} onValueChange={setDeparts} locale={locale} />
</Field.Root>
</Field.Group>
<Code.Root>{departs ? departs.toString() : 'null'}</Code.Root>
</Stack.Root>
);
}
null단독으로 쓰면 Field.DateTimeInput이 버튼 없이 필드의 컨트롤입니다. 값을 고를 수도 있게 하려면 옆에 Calendar와 시각의 OptionList를 담은 Field.Picker를 두세요. 날짜와 시각을 함께 고르는 패널은 따로 없습니다. Date and time picker 레시피가 그런 패널을 조합합니다. 날짜를 고르면 시각을, 시각을 고르면 날짜를 그대로 두고, 둘 다 정해지면 선택기를 닫습니다.
import { Calendar, Field, Label, OptionList, timeOptions } from '@tounsoo/todae';
import { useId, useState } from 'react';
import styles from './DateTimePicker.module.css';
// A day or a time picked while the other half is missing, held until the other is picked too.
type Halves = { date: Temporal.PlainDate | null; time: Temporal.PlainTime | null };
const NONE: Halves = { date: null, time: null };
export default function DateTimePicker({ locale }: { locale: string }) {
const id = useId();
const [starts, setStarts] = useState<Temporal.PlainDateTime | null>(null);
const [held, setHeld] = useState<Halves>(NONE);
const date = starts?.toPlainDate() ?? held.date;
const time = starts?.toPlainTime() ?? held.time;
// A pick keeps the other half, and makes the value, and closes the picker, once both are set.
function pick(next: Halves, close: () => void) {
const day = next.date ?? date;
const at = next.time ?? time;
if (day && at) {
setStarts(day.toPlainDateTime(at));
setHeld(NONE);
close();
} else {
setHeld({ date: day, time: at });
}
}
return (
<Field.Group>
<Label.Root htmlFor={id}>Meeting starts</Label.Root>
<Field.Root id={id} name="starts">
<Field.DateTimeInput value={starts} onValueChange={setStarts} locale={locale} />
{/* A half picked and then left is dropped when the picker closes. */}
<Field.Picker
closeOnPick={false}
onOpenChange={(open) => {
if (!open) setHeld(NONE);
}}
>
{({ close }) => (
<div className={styles.panel}>
<Calendar.Root
aria-label="Day"
value={date}
onValueChange={(day) => pick({ date: day, time: null }, close)}
locale={locale}
>
<Calendar.Header />
<Calendar.Grid />
</Calendar.Root>
<div className={styles.times}>
<OptionList.Root
aria-label="Times"
value={time?.toString() ?? null}
onValueChange={(next) => pick({ date: null, time: Temporal.PlainTime.from(next) }, close)}
>
{timeOptions({ step: 15, value: time, locale }).map((option) => (
<OptionList.Option key={option.value} value={option.value}>
{option.label}
</OptionList.Option>
))}
</OptionList.Root>
</div>
</div>
)}
</Field.Picker>
</Field.Root>
</Field.Group>
);
}
/* The calendar and the times side by side, the times as tall as the calendar. */
.panel {
display: flex;
align-items: flex-start;
gap: var(--todae-space-stack-gap);
}
/* The times scroll in their own box. The padding and scroll padding leave room
for the list's focus ring, which the box would otherwise cut. */
.times {
--_times-height: calc(6 * var(--todae-space-12));
align-self: stretch;
max-block-size: var(--_times-height);
overflow-y: auto;
padding: calc(var(--todae-focus-ring-width) + var(--todae-focus-ring-offset));
scroll-padding: calc(var(--todae-focus-ring-width) + var(--todae-focus-ring-offset));
}
/* On a narrow screen the times go under the calendar, in a shorter box. */
@media (width < 32rem) {
.panel {
flex-direction: column;
align-items: stretch;
}
.times {
--_times-height: calc(3 * var(--todae-space-12));
}
}
입력한 날짜와 시각
formatDateTime은 en-US의 10/13/2026, 9:30 PM처럼 날짜를 숫자로, 시각을 시와 분으로 쓰고, parseDateTime은 Oct 13, 2026 at 9:30 PM처럼 로캘이 쓰는 순서로 입력한 날짜와 시각을 읽습니다. 각각 무엇을 쓰고 읽는지는 formatDateTime과 parseDateTime에 있습니다.
Field.DateTimeInput은 자신의 locale로 텍스트를 parseDateTime으로 읽고 formatDateTime으로 씁니다. 빈 텍스트는 null로 확정됩니다. 날짜와 시각이 아닌 텍스트는 입력한 그대로 남고, onValueChange는 호출되지 않으며, 확정하면서 읽으려다 실패한 뒤에는 필드가 유효하지 않음으로 표시됩니다. 텍스트가 날짜와 시각이거나 비어 있을 때까지 폼은 제출되지 않습니다.
폼에서
값은 텍스트 입력 옆의 네이티브 <input type="datetime-local">에 담겨, 필드의 name이나 입력 자체의 name으로, HTML이 쓰는 형식으로 폼과 함께 전송됩니다. 예: 2026-10-13T09:30. 텍스트 입력은 아무것도 보내지 않고, 네이티브 입력은 화면과 보조 기술에서 숨겨지며 탭 정지점이 아닙니다. required는 값이 없는 폼을, min과 max는 그보다 이르거나 늦은 값이 있는 폼을 유효하지 않게 합니다. 브라우저가 네이티브 입력에서 세 가지를 모두 검사하고, 날짜와 시각이 아닌 텍스트도 제출을 막습니다. Form.Root 안에서는 문제가 필드의 ErrorMessage.Root에 페이지의 언어로 나타나고 min이나 max는 formatDateTime이 쓰는 방식으로 표기되며, 포커스는 텍스트 입력으로 갑니다. Form.Root 밖에서도 브라우저가 제출을 막고, 포커스는 마찬가지로 텍스트 입력에 놓입니다. 네이티브 날짜 입력은 1년부터 275760년까지만 담을 수 있으므로, 그 밖의 값이나 범위는 값 없음으로 읽힙니다. 빈 값으로 전송되고 required, min, max는 이를 무시하며, 개발 빌드는 한 번 경고합니다.
Temporal
Todae는 Temporal 폴리필을 포함하지 않습니다. 입력의 값과 formatDateTime, parseDateTime은 Temporal.PlainDateTime이므로, 브라우저에 Temporal이 없는 곳에서는 앱이 폴리필을 불러옵니다(네이티브 플랫폼 참고). Todae의 타입에는 Temporal을 선언하는 TypeScript 6 이상이 필요합니다.
접근성을 지키는 조합
Todae가 맡는 것: 텍스트 입력은 Field.Root에서 id, aria-label, aria-labelledby, aria-describedby를 받고, Root나 바깥 Fieldset에서 네이티브 disabled와 aria-invalid를 받습니다. 확정할 때 텍스트를 읽지 못하면 aria-invalid가, required가 있으면 aria-required가 붙습니다. Field.Picker 옆에서도 입력이 필드의 컨트롤이고, 선택기의 버튼은 StringsProvider의 dateTimePicker 문자열로 이름이 붙으며 GlyphsProvider의 calendar 글리프를 보여 줍니다.
직접 제공할 것: 이름. htmlFor가 Root id인 Label이나, Root의 aria-label / aria-labelledby입니다. 선택기를 둔다면 레시피처럼 패널과 그 이름도 직접 제공합니다.
주의할 점: value가 있으면 서버는 그 날짜와 시각을 서버의 로캘로 쓰므로, 서버에서 렌더링할 때는 locale을 넘기세요. 값을 특정 시점인 것처럼 저장하지 마세요. PlainDateTime은 읽는 사람의 시계를 따르므로, 시점을 저장하기 전에 시간대를 더하세요.
언제 쓰나요
Field.DateTimeInput
언제: 회의 시작이나 항공편 출발처럼 날짜와 하루 중 시각을 하나의 값으로.
쓰지 않을 때: 날짜만 → Field.DateInput. 시각만 → Field.TimeInput. 시간대가 있는 시점 → 이 입력을 쓰고 시간대는 직접 작성한 코드에서 더하세요.
Props
| 이름 | 타입 | 설명 |
|---|---|---|
value 필수 | Temporal.PlainDateTime | null | 날짜와 시각, 없으면 null. |
onValueChange | (value: Temporal.PlainDateTime | null) => void | 사람이 확정할 때, 즉 포커스를 잃거나 Enter를 누르거나 폼을 제출할 때, 텍스트를 parseDateTime으로 읽은 날짜와 시각이나 빈 텍스트면 null을 받아 호출됩니다. 입력하는 것만으로는 호출되지 않고, 날짜와 시각이 아닌 텍스트는 유효하지 않은 채로 남습니다. 없으면 입력은 읽기 전용입니다. |
min | Temporal.PlainDateTime | 가장 이른 날짜와 시각. 이보다 이른 값이 있으면 폼이 유효하지 않습니다. |
max | Temporal.PlainDateTime | 가장 늦은 날짜와 시각. 이보다 늦은 값이 있으면 폼이 유효하지 않습니다. |
required | boolean | 날짜와 시각이 없으면 폼이 유효하지 않습니다. |
locale | string | 텍스트를 읽고 쓰는 로캘, 예: "ko". 없으면 브라우저의 로캘이므로, 서버에서 렌더링할 때는 넘기세요. |
placeholder | string | 네이티브 placeholder. |