# Date Input

A standalone text field for parsing and formatting dates.

A standalone text field for parsing and formatting dates.

```tsx
import { DateInput, Field } from "@zentara-co/zenos-ui";

function DateInputPreviewExample() {
  return (
    <Field.Root className="w-full max-w-sm">
      <Field.Label>Start date</Field.Label>
      <Field.Control render={<DateInput placeholder="YYYY-MM-DD" />} />
    </Field.Root>
  );
}
```

```tsx
import { DateInput } from "@zentara-co/zenos-ui";
```

## Sizes

DateInput uses the shared Zenos `sm`, `md`, and `lg` control scale from Input.

```tsx
import { DateInput, Stack } from "@zentara-co/zenos-ui";

function DateInputSizesExample() {
  return (
    <Stack gap="3" className="w-full max-w-sm">
      {(["sm", "md", "lg"] as const).map((size) => (
        <DateInput key={size} size={size} placeholder="YYYY-MM-DD" />
      ))}
    </Stack>
  );
}
```

## Variants

Surfaces match Input: `default` (standard), `filled` (subtle), and `none` (borderless).

```tsx
import { DateInput, Stack } from "@zentara-co/zenos-ui";

type CatalogVariantProps = { limit?: number };

const limited = <T,>(items: readonly T[], limit?: number) =>
  limit === undefined ? items : items.slice(0, limit);

const formControlSurfaceVariants = ["default", "filled", "none"] as const;

function DateInputVariantsExample({ limit }: CatalogVariantProps = {}) {
  const sample = new Date(2026, 8, 24);

  if (limit !== undefined) {
    return (
      <Stack gap="3" className="w-full max-w-sm">
        {limited(formControlSurfaceVariants, limit).map((variant) => (
          <DateInput key={variant} variant={variant} defaultValue={sample} />
        ))}
      </Stack>
    );
  }

  return (
    <Stack gap="3" className="w-full max-w-sm">
      {formControlSurfaceVariants.map((variant) => (
        <DateInput key={variant} variant={variant} defaultValue={sample} />
      ))}
    </Stack>
  );
}
```

## States

Empty, filled, invalid, and disabled treatments are inherited from Input. Invalid matches Input. Compose with `Field` for labels, descriptions, and errors. DateInput also sets `invalid` when typed text fails parsing on blur.

```tsx
import { DateInput, Stack } from "@zentara-co/zenos-ui";

function DateInputStatesExample() {
  return (
    <Stack gap="3" className="w-full max-w-sm">
      <DateInput placeholder="YYYY-MM-DD" />
      <DateInput defaultValue={new Date(2026, 8, 24)} />
      <DateInput invalid defaultValue={new Date(2026, 1, 28)} />
      <DateInput disabled defaultValue={new Date(2026, 8, 24)} />
    </Stack>
  );
}
```

## Controlled value and validation

Valid text updates the date immediately. Invalid text remains editable and becomes invalid on blur, while clearing the control emits `undefined`.

```tsx
import { DateInput, Field, Stack, Text } from "@zentara-co/zenos-ui";
import { useState } from "react";

function DateInputControlledExample() {
  const [date, setDate] = useState<Date | undefined>(new Date(2026, 8, 24));
  const [invalid, setInvalid] = useState(false);

  return (
    <Stack gap="3" className="w-full max-w-sm">
      <Field.Root invalid={invalid}>
        <Field.Label>Deployment date</Field.Label>
        <Field.Control
          render={<DateInput value={date} onValueChange={setDate} onInvalidChange={setInvalid} />}
        />
        <Field.Description>Use YYYY-MM-DD.</Field.Description>
        <Field.Error>Enter a valid calendar date.</Field.Error>
      </Field.Root>
      <Text className="text-sm text-text-subtle" aria-live="polite">
        Value:{" "}
        {date
          ? `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, "0")}-${String(date.getDate()).padStart(2, "0")}`
          : "None"}
      </Text>
    </Stack>
  );
}
```

## Custom format and parser

Provide `format` and `parse` together when a product uses a different typed-date convention.

```tsx
import { DateInput, Field } from "@zentara-co/zenos-ui";

function DateInputCustomFormatExample() {
  const format = (date: Date) =>
    `${String(date.getDate()).padStart(2, "0")}/${String(date.getMonth() + 1).padStart(2, "0")}/${date.getFullYear()}`;
  const parse = (text: string) => {
    const match = /^(\d{2})\/(\d{2})\/(\d{4})$/.exec(text.trim());
    if (!match) return undefined;
    const day = Number(match[1]);
    const month = Number(match[2]);
    const year = Number(match[3]);
    const date = new Date(year, month - 1, day);
    return date.getFullYear() === year && date.getMonth() === month - 1 && date.getDate() === day
      ? date
      : undefined;
  };

  return (
    <Field.Root className="w-full max-w-sm">
      <Field.Label>Local date</Field.Label>
      <Field.Control
        render={
          <DateInput
            defaultValue={new Date(2026, 8, 24)}
            format={format}
            parse={parse}
            placeholder="DD/MM/YYYY"
          />
        }
      />
      <Field.Description>Displayed and parsed as DD/MM/YYYY.</Field.Description>
    </Field.Root>
  );
}
```

## Variants

default, filled, none

## Sizes

sm, md, lg

## API

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| value | Date \| undefined | — | Controlled parsed date. |
| defaultValue | Date \| undefined | — | Initial uncontrolled date. |
| onValueChange | (date: Date \| undefined) => void | — | Runs after valid parsing or clearing. |
| variant | default \| filled \| none | default | Surface treatment inherited from Input (`default` = standard, `filled` = subtle, `none` = borderless). |
| size | sm \| md \| lg | md | Control height inherited from Input. |
| format | (date: Date) => string | — | Custom date formatter. |
| parse | (text: string) => Date \| undefined | — | Custom date parser. |
| invalid | boolean | — | Controls the invalid presentation. |
| onInvalidChange | (invalid: boolean) => void | — | Runs when validity changes, including validation on blur. |
| onChange | ChangeEventHandler<HTMLInputElement> | — | Runs for every text edit before parsing completes. |
| native props | React.InputHTMLAttributes<HTMLInputElement> | — | Forwards native attributes, events, aria-*, data-*, className, style, and ref. |

Unless narrowed above, each DOM-rendering part also accepts its underlying native or Base UI props, including className, style, aria-*, and data-*.

## Accessibility

DateInput remains a native text input with numeric input mode. Give it a visible Field label or another accessible name, provide format instructions in `Field.Description`, and connect validation feedback through `Field.Error`. The component preserves native `required`, `disabled`, `name`, autocomplete, and focus behavior.

Source: https://zenos-ui.pages.dev/components/date-input/