# DateInput

> 分段输入单个日期，使用共享控件尺寸，保留与时区无关的日期值。

网页来源：/components/date-input

版本：@quirekit/ui 0.3.1；源码修订：d79a6b48d00e+worktree。此文档对应当前源码构建，接入方式以开始使用为准。

接入前置：[开始使用](/raw/components/getting-started.md)（Vue、样式、主题与图标 Provider）。

`@quirekit/ui/vue` · Vue 3

DateInput 用于输入一个确定的日历日期。年、月、日默认使用补零的 YYYY-MM-DD，输入、方向键和焦点行为由 Ark DateInput 提供。
这一页覆盖独立单日期输入；日历弹窗、范围和日期时间由同族后续组件提供。

## 基础输入与清空

### 示例：date-input/basic

文件：`basic.vue`

```vue
<script setup lang="ts">
import { ref } from 'vue';
import { QuireDateInput, QuireButton } from '@quirekit/ui/vue';
const value = ref<string | null>('2026-09-06');
</script>
<template>
  <div class="grid gap-qk-group p-qk-surface" data-date-basic>
    <QuireDateInput v-model="value" label="截止日期" clearable placeholder-value="2026-09-01" description="点击年、月或日输入，使用方向键调整。" />
    <div class="flex flex-wrap items-center gap-qk-inline"><QuireButton variant="outline" @click="value = '2026-12-31'">设为年底</QuireButton><output>当前值：{{ value ?? '未填写' }}</output></div>
  </div>
</template>
```

`v-model` 接收完整 `YYYY-MM-DD` 字符串或 `null`。外部设置完整值会同步更新显示。
未填写、清空或未输入完整时公开值为 `null`；局部输入草稿由 Ark 保留，宿主不能把 `null` 擅自替换为今天。
删除已有日期中的某一段时，公开值立即变为 `null`，其他段仍保留；补回原来的内容也会重新提交完整值。公开值已经为空时，清除按钮仍可清除未完成草稿。
`defaultValue` 用于非受控初始值；`placeholderValue` 决定空字段开始调整时的日期参考，不是已经选择的值。
`clearable` 提供独立的清除操作，并把焦点返回日期字段；禁用和只读时隐藏清除动作。

## 状态与反馈

### 示例：date-input/states

文件：`states.vue`

```vue
<script setup lang="ts">
import { QuireDateInput } from '@quirekit/ui/vue';
</script>
<template>
  <div class="flex flex-wrap items-start gap-qk-group p-qk-surface" data-date-states>
    <QuireDateInput label="未填写" placeholder-value="2026-09-01" clearable />
    <QuireDateInput label="只读日期" default-value="2026-09-06" read-only description="保留聚焦和完整日期阅读。" />
    <QuireDateInput label="禁用日期" default-value="2026-09-06" disabled description="当前操作不可用。" />
    <QuireDateInput label="开始日期" default-value="2026-09-06" required invalid error-text="开始日期应晚于审批日期。" />
    <QuireDateInput label="日期边界" default-value="2025-12-31" min="2026-01-01" error-text="请选择 2026 年起的日期。" />
  </div>
</template>
```

`readOnly` 保留阅读与焦点，`disabled` 禁止编辑并退出表单提交；错误说明通过 `errorText` 与 `invalid` 显式传入。
`description` / `errorText` 关联每个可编辑日期段，不只通过边框颜色提示状态。
`required` 提供必填语义；Ark 使用 hidden input 序列化，浏览器不对 hidden input 执行 required 校验，必填与业务规则应通过宿主 Form 校验，不能误认为原生浏览器会阻止提交。

## 共享尺寸

### 示例：date-input/sizes

文件：`sizes.vue`

```vue
<script setup lang="ts">
import { QuireDateInput, QuireButton } from '@quirekit/ui/vue';
const sizes = ['xs', 'sm', 'md', 'lg', 'xl'] as const;
</script>
<template>
  <div class="grid gap-qk-group p-qk-surface" data-date-sizes>
    <div v-for="size in sizes" :key="size" class="flex flex-wrap items-center gap-qk-surface" :data-size="size">
      <QuireDateInput :label="`${size} 日期`" hide-label clearable default-value="2026-09-06" :size="size" width="12rem" />
      <QuireButton :size="size" variant="outline">保存 {{ size }}</QuireButton>
    </div>
  </div>
</template>
```

xs–xl 与 Button、Input 共享 24/28/32/36/40px 高度和排版，默认 sm。
字段标签与说明在控件外，整体高度不参与单行控件高度比较；`hideLabel` 只隐藏可见标签，保留可访问名称。
边框、颜色、段焦点和留白直接消费语义 Token，继承关系进入 Token 图谱。默认宽度与 Input 一致；`width` 可按表单布局调整，最多占满容器。

独立日期输入默认宽 200px，分隔符与年月日同色，允许通过 `width` 适配布局。

## 地区格式

### 示例：date-input/locale

文件：`locale.vue`

```vue
<script setup lang="ts">
import { ref } from 'vue';
import { QuireDateInput, QuireLocaleProvider } from '@quirekit/ui/vue';
const value = ref<string | null>('2026-09-06');
</script>
<template>
  <div class="flex flex-wrap items-start gap-qk-group p-qk-surface" data-date-locale>
    <QuireDateInput date-format="locale" v-model="value" label="中文日期" />
    <QuireLocaleProvider locale="en-US">
      <QuireDateInput date-format="locale" v-model="value" label="US date" />
    </QuireLocaleProvider>
    <QuireLocaleProvider locale="en-GB">
      <QuireDateInput date-format="locale" v-model="value" label="UK date" />
    </QuireLocaleProvider>
  </div>
</template>
```

默认 `dateFormat="iso"` 使用补零的 `YYYY-MM-DD`，与 DatePicker、DateRangePicker 一致；明确设置 `dateFormat="locale"` 才按地区显示。显示格式不改变提交的 ISO 值。地区格式、段名称与清除按钮文案跟随 [Locale Provider](/raw/components/locale-provider.md) 的语言。
公开值只接受公历单日期，不能传时间戳或本地化日期字符串；将时间戳换算成业务日期是宿主的显式选择。

## 表单与日期边界

### 示例：date-input/form

文件：`form.vue`

```vue
<script setup lang="ts">
import { ref } from 'vue';
import { QuireDateInput, QuireButton } from '@quirekit/ui/vue';
const submitted = ref('尚未提交');
const date = ref<string | null>('2026-09-06');
const error = ref('');
/**
 * Demonstrates ISO native serialization and host-owned required validation.
 * @param event - Native submit event from this local demonstration.
 */
function submit(event: Event): void {
  const data = new FormData(event.currentTarget as HTMLFormElement);
  error.value = !date.value ? '请填写交付日期。' : date.value < '2026-01-01' || date.value > '2026-12-31' ? '交付日期应在 2026 年内。' : '';
  submitted.value = error.value || `交付日期：${data.get('delivery')}`;
}
</script>
<template>
  <form class="grid gap-qk-group p-qk-surface" data-date-form @submit.prevent="submit" @reset="error = ''; submitted = '尚未提交'">
    <QuireDateInput v-model="date" required :invalid="Boolean(error)" :error-text="error" label="交付日期" name="delivery" default-value="2026-09-06" min="2026-01-01" max="2026-12-31" description="允许 2026 年内的日期；重置后回到初始日期。" clearable />
    <div class="flex flex-wrap gap-qk-inline"><QuireButton type="submit">提交日期</QuireButton><QuireButton type="reset" variant="outline">重置日期</QuireButton></div>
    <output role="status">{{ submitted }}</output>
  </form>
</template>
```

`name` 和 `form` 控制原生表单关联；提交完整日期字符串，重置请求恢复 `defaultValue`。
受控模式仍由宿主接受 `update:modelValue` 决定值；取消原生 reset 的宿主不会触发恢复。
`min` / `max` 使用同一日期格式；动态业务禁用规则与日期范围将在日期选择族继续设计。


日期边界会显示文字与错误状态，保留正在编辑的日期以便修正。和必填一样，宿主在提交时应校验范围；示例明确阻止空值与越界结果。

## 设计与参考

优先参考 [Nuxt InputDate](https://github.com/nuxt/ui/blob/v4/docs/content/docs/2.components/input-date.md) 的分段输入、尺寸和外部组合方式；交互封装 [Ark DateInput](https://ark-ui.com/docs/components/date-input)，不引入第二套状态机。
[Ant Design DatePicker](https://ant.design/components/date-picker/) 用于核对清空、只读与限制日期等表单场景，日历交互在后续 DatePicker 中验收。

专注：默认只呈现标签、日期段和必要说明。可控：空值不自动填入今天，外部值与清空行为明确。
体谅：键盘可调整日期段，错误同时有文字，普通日期不因时区转换改变。连贯：同排控件共享尺寸，颜色与边界沿用同一 Token 体系。

## API

### QuireDateInput

#### Props

| 名称 | 必填 | 默认值 | 说明 |
| --- | --- | --- | --- |
| label | 是 | — | Accessible field name, visible unless hideLabel is set. |
| modelValue | 否 | — | Controlled ISO YYYY-MM-DD value; null represents an empty input. |
| defaultValue | 否 | null | Initial value and native form-reset target in uncontrolled mode. |
| size | 否 | "sm" | Shared single-line control size. |
| width | 否 | "200px" | CSS width; the field never exceeds its containing block. |
| hideLabel | 否 | false | Keep the accessible name while letting an external layout present the label. |
| dateFormat | 否 | "iso" | Date display convention; iso by default, locale follows the active language. |
| min | 否 | — | Inclusive minimum ISO calendar date. |
| max | 否 | — | Inclusive maximum ISO calendar date. |
| placeholderValue | 否 | — | Stable reference date for empty segments, independent of the current clock. |
| name | 否 | — | Native form field name. |
| form | 否 | — | Associated native form ID, including forms outside the DOM ancestry. |
| disabled | 否 | false | Prevent interaction and omit the field from native form data. |
| readOnly | 否 | false | Allow reading and focus, without changing the value. |
| required | 否 | false | Required-field semantics; validation is owned by the host Form. |
| invalid | 否 | false | Host-owned validation state, in addition to date-bound validation. |
| description | 否 | — | Supporting text associated with each editable segment. |
| errorText | 否 | — | Recovery guidance presented when the host marks the field invalid. |
| clearable | 否 | false | Offer a clear action, including while date segments are incomplete. |

**label**

```ts
string
```

**modelValue**

```ts
QuireKitDateInputValue | undefined
```

```ts
undefined | null | string
```

**defaultValue**

```ts
QuireKitDateInputValue | undefined
```

```ts
undefined | null | string
```

**size**

```ts
QuireKitControlSize | undefined
```

```ts
undefined | "sm" | "md" | "xs" | "lg" | "xl"
```

**width**

```ts
string | undefined
```

```ts
undefined | string
```

**hideLabel**

```ts
boolean | undefined
```

**dateFormat**

```ts
"iso" | "locale" | undefined
```

```ts
undefined | "iso" | "locale"
```

**min**

```ts
string | undefined
```

```ts
undefined | string
```

**max**

```ts
string | undefined
```

```ts
undefined | string
```

**placeholderValue**

```ts
string | undefined
```

```ts
undefined | string
```

**name**

```ts
string | undefined
```

```ts
undefined | string
```

**form**

```ts
string | undefined
```

```ts
undefined | string
```

**disabled**

```ts
boolean | undefined
```

**readOnly**

```ts
boolean | undefined
```

**required**

```ts
boolean | undefined
```

**invalid**

```ts
boolean | undefined
```

**description**

```ts
string | undefined
```

```ts
undefined | string
```

**errorText**

```ts
string | undefined
```

```ts
undefined | string
```

**clearable**

```ts
boolean | undefined
```

#### Events

| 名称 | 必填 | 默认值 | 说明 |
| --- | --- | --- | --- |
| update\:modelValue | 否 | — |  |

**update:modelValue**

```ts
[value: QuireKitDateInputValue]
```

#### Slots

| 名称 | 必填 | 默认值 | 说明 |
| --- | --- | --- | --- |
| leading | 否 | — | Optional decorative leading icon or short prefix. |
| trailing | 否 | — | Optional trailing content, such as a future calendar trigger. |

**leading**

```ts
any
```

**trailing**

```ts
any
```

#### 公开实例成员

无。
