# TimeInput

> 分段输入纯时间，统一尺寸与表单合同，支持 12/24 小时制和秒精度。

网页来源：/components/time-input

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

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

`@quirekit/ui/vue` · Vue 3

TimeInput 用于输入一天内的墙上时钟时间，例如营业时间或每日提醒。它不表示某个时区的时间点。
交互封装 Ark DateInput 的时间段，日期基准只用于内部适配，公开值与表单提交都不带日期、时区或 UTC 偏移。

## 基础输入与清空

### 示例：time-input/basic

文件：`basic.vue`

```vue
<script setup lang="ts">
import { ref } from 'vue';
import { QuireTimeInput, QuireButton } from '@quirekit/ui/vue';
const time = ref<string | null>('09:30');
</script>
<template>
  <div class="grid gap-qk-group p-qk-surface" data-time-basic>
    <QuireTimeInput v-model="time" label="开始时间" clearable description="点击时或分输入，使用方向键调整。" />
    <div class="flex flex-wrap items-center gap-qk-inline"><QuireButton variant="outline" @click="time = '17:45'">设为傍晚</QuireButton><output role="status">当前值：{{ time ?? '未填写' }}</output></div>
  </div>
</template>
```

`v-model` 接收 `HH:mm`（分钟精度）、`HH:mm:ss`（秒精度）或 `null`，统一使用 24 小时制。
部分输入保留在 Ark 草稿中；填写完整后才提交值。删除已有时间中的某一段时，公开值立即变为 `null`，其余段仍保留；补回相同内容也会重新提交完整值。公开值已经为空时，清除按钮仍可清除未完成草稿。空字段不会自动填入当前时间。
`placeholderValue` 为方向键开始调整时提供参考，默认内部参考为午夜，不代表用户已选择。
清除动作将焦点返回时间字段；外部赋值同步更新。

## 显示周期与精度

### 示例：time-input/precision

文件：`precision.vue`

```vue
<script setup lang="ts">
import { ref } from 'vue';
import { QuireTimeInput } from '@quirekit/ui/vue';
const minute = ref<string | null>('13:30');
const second = ref<string | null>('23:59:58');
</script>
<template>
  <div class="grid gap-qk-group p-qk-surface" data-time-precision>
    <div class="flex flex-wrap items-start gap-qk-group">
      <QuireTimeInput v-model="minute" label="24 小时制" :hour-cycle="24" />
      <QuireTimeInput v-model="minute" label="12 小时制" :hour-cycle="12" />
      <QuireTimeInput v-model="second" label="精确到秒" granularity="second" />
    </div>
    <output role="status">分钟：{{ minute ?? '未填写' }}；秒：{{ second ?? '未填写' }}</output>
  </div>
</template>
```

`hourCycle` 为 12 或 24，默认 24；改变显示不会改变提交格式。12 小时制显示独立上午/下午段。
`granularity` 为 `minute` 或 `second`，默认分钟。值应与精度一致；分钟模式拒绝隐藏非零秒值，避免编辑时静默丢失精度。秒输入适用于确有秒级需求的场景。
午夜为 `00:00`，一天的最后一分钟为 `23:59`，不把 `24:00` 作为第二种午夜写法。

## 状态与边界

### 示例：time-input/states

文件：`states.vue`

```vue
<script setup lang="ts">
import { QuireTimeInput } from '@quirekit/ui/vue';
</script>
<template>
  <div class="flex flex-wrap items-start gap-qk-group p-qk-surface" data-time-states>
    <QuireTimeInput label="未填写时间" clearable />
    <QuireTimeInput label="只读时间" default-value="09:30" read-only clearable description="保留阅读与焦点。" />
    <QuireTimeInput label="禁用时间" default-value="09:30" disabled clearable />
    <QuireTimeInput label="预约时间" default-value="07:30" min="09:00" max="18:00" error-text="请选择 09:00 至 18:00 之间的时间。" />
  </div>
</template>
```

只读保留阅读与焦点；禁用禁止编辑并退出表单提交。边界与宿主错误均有文字和可访问关联。
`min` / `max` 是同一天内的时间边界。跨午夜营业区间应由后续范围组件或宿主业务显式表达。
`errorText` 可提供更具体的恢复指引；颜色辅助识别，不单独承担错误信息。

## 共享尺寸

### 示例：time-input/sizes

文件：`sizes.vue`

```vue
<script setup lang="ts">
import { QuireTimeInput, 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-time-sizes>
    <div v-for="size in sizes" :key="size" class="flex flex-wrap items-center gap-qk-surface" :data-size="size">
      <QuireTimeInput :label="`${size} 时间`" hide-label clearable default-value="09:30" :size="size" width="12rem" />
      <QuireButton :size="size" variant="outline">保存 {{ size }}</QuireButton>
    </div>
  </div>
</template>
```

xs–xl 与 DateInput、Input、Button 共享 24/28/32/36/40px 高度，默认 sm。
较大尺寸增加控件留白；分段文字沿用共享排版。清除按钮复用 xs IconButton，保持可操作面积。

## 表单与重置

### 示例：time-input/form

文件：`form.vue`

```vue
<script setup lang="ts">
import { ref } from 'vue';
import { QuireTimeInput, QuireButton } from '@quirekit/ui/vue';
const time = ref<string | null>('09:30');
const error = ref('');
const submitted = ref('尚未提交');
/**
 * Validates wall-clock values before using native serialization.
 * @param event - Native submit event for this example.
 */
function submit(event: Event): void {
  error.value = !time.value ? '请填写交付时间。' : time.value < '09:00' || time.value > '18:00' ? '交付时间应在 09:00 至 18:00 之间。' : '';
  const data = new FormData(event.currentTarget as HTMLFormElement);
  submitted.value = error.value || `交付时间：${data.get('deliveryTime')}`;
}
</script>
<template>
  <form class="grid gap-qk-group p-qk-surface" data-time-form @submit.prevent="submit" @reset="error = ''; submitted = '尚未提交'">
    <QuireTimeInput v-model="time" label="交付时间" name="deliveryTime" default-value="09:30" min="09:00" max="18:00" required clearable :invalid="Boolean(error)" :error-text="error" description="允许 09:00 至 18:00；重置后回到 09:30。" />
    <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` 同时是原生 reset 的恢复目标。
受控模式由宿主接受更新；取消 reset 不会恢复值。隐藏字段不能执行浏览器必填校验，因此示例在提交时校验必填及边界。

## 设计与参考

优先对照 [Nuxt InputTime](https://ui.nuxt.com/docs/components/input-time) 的分段输入、显示周期和独立组合，
交互采用 [Ark DateInput](https://ark-ui.com/docs/components/date-input)。
[Ant Design TimePicker](https://ant.design/components/time-picker/) 用于核对时间精度、清空和业务边界；时间选择弹层在后续 TimePicker 验收。

专注：仅在需要时显示秒；可控：空值、草稿和提交格式明确；体谅：键盘输入、文字错误及稳定的纯时间值；连贯：共用日期字段的视觉规则与单行控件尺寸。

独立时间输入默认宽 160px，避免短时间值占用整条宽输入。分钟精度保留 `HH:mm`，明确需要秒时使用 `granularity="second"` 呈现 `HH:mm:ss`；不为视觉整齐擅自改变业务精度。

## API

### QuireTimeInput

#### Props

| 名称 | 必填 | 默认值 | 说明 |
| --- | --- | --- | --- |
| label | 是 | — | Accessible field name, visible unless hideLabel is set. |
| modelValue | 否 | — | Controlled 24-hour HH\:mm or HH\:mm\:ss 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 | 否 | "160px" | CSS width; the field never exceeds its containing block. |
| hideLabel | 否 | false | Keep the accessible name while letting an external layout present the label. |
| min | 否 | — | Inclusive minimum wall-clock time. |
| max | 否 | — | Inclusive maximum wall-clock time. |
| placeholderValue | 否 | — | Stable reference date for empty segments, independent of the current clock. |
| granularity | 否 | "minute" | Smallest displayed unit; defaults to minute. |
| hourCycle | 否 | 24 | Display cycle, independent of the 24-hour public value; defaults to 24. |
| 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 time-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 time segments are incomplete. |

**label**

```ts
string
```

**modelValue**

```ts
QuireKitTimeInputValue | undefined
```

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

**defaultValue**

```ts
QuireKitTimeInputValue | 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
```

**min**

```ts
string | undefined
```

```ts
undefined | string
```

**max**

```ts
string | undefined
```

```ts
undefined | string
```

**placeholderValue**

```ts
string | undefined
```

```ts
undefined | string
```

**granularity**

```ts
"minute" | "second" | undefined
```

```ts
undefined | "minute" | "second"
```

**hourCycle**

```ts
12 | 24 | undefined
```

```ts
undefined | 12 | 24
```

**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: QuireKitTimeInputValue]
```

#### Slots

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

**leading**

```ts
any
```

**trailing**

```ts
any
```

#### 公开实例成员

无。
