merge: integrate DateField and date foundations
This commit is contained in:
@@ -446,3 +446,17 @@ Vaul Vue 官方已说明停止维护并推荐 Reka Drawer;新项目不采用 V
|
||||
|
||||
- 正常 HTTP 页面恢复访问后,Select 已完成重点浏览器补验,可以按本轮验证结果集成 main;上一节“留在任务分支”的要求是此前阻断阶段,不再适用。
|
||||
- 不能只断言焦点正确:Floating 首次定位前 scrollIntoView 可能无效。定位后的动画开始及无动画路径重新检查当前焦点可见性;尊重取消、不抢焦点、忽略子动画、清理帧回调。长列表同时核对 activeElement、滚动区边界和 scrollTop。
|
||||
|
||||
## DATE-01 日期基建(2026-10-23)
|
||||
|
||||
- 日期任务从同步 main `3c878d2` 新建 feat/date-calendar-foundation,先读[日期基建决策](docs/decisions/date-calendar-foundation.md)。当前仅私有值/接受值协议和安装版探针,尚未公开 DateField/Calendar 或宣称文档完成。
|
||||
- DateField 与独立 DateInputGroup 共用分段部件;日期、时间、范围与 Picker 不再各自建值、表单或焦点模型。Calendar 的 week/day view、YearPicker 和非公历不能被普通月历替代。
|
||||
- 已实测底座受控拒绝后分段前移、reset 不恢复、秒/zone/非公历提交差异。接受值与显示 wire 分开,wire 只能是接受值副本;唯一提交层保留完整日期序列化,显示粒度不裁剪模型。
|
||||
- disabled/unavailable、locale/calendar/timeZone、纯日期/DateTime/ZonedDateTime 分别建模;SSR 使用明确值/placeholder 验证,不把 Node 本地时区或 UTC 强加给用户日期。
|
||||
- Calendar runtime 多选事件与安装版声明不一致;键盘导航使用 code 并在子项停止冒泡。公共 API 类型及事件取消须重新验证,不能把探针中的已知缺口当公共契约。
|
||||
|
||||
## DATE-02 与下一任务(2026-10-23)
|
||||
|
||||
DateField/DateInputGroup 已公开,先读[DATE-02 报告](docs/migrations/DATE-02-date-field.md)。空值受控拒绝不能靠重新传 null 触发底座 watch;回归完整提案、部分草稿和 reset,保留原节点/焦点。使用 shallowRef 保留日期类类型,完整 ISO 原生提交不跟显示粒度裁剪。Reka Root asChild/导航取消、完整日期粘贴和 13 月/era 差异必须保留说明。
|
||||
|
||||
用户最新要求:完成 DateField 后暂停组件迁移,先对齐文档站整体架构、结构、布局与公共控件;已经具备的 HeroUI Vue 组件用于文档壳层,暂缺的保留现有实现,不为文档任务插入 Calendar。
|
||||
|
||||
@@ -62,6 +62,7 @@ const groups = [
|
||||
{ title: "CheckboxGroup 复选框组", url: "/components/checkbox-group" },
|
||||
{ title: "Chip 标签", url: "/components/chip" },
|
||||
{ title: "CloseButton 关闭按钮", url: "/components/close-button" },
|
||||
{ title: "DateField 日期字段", url: "/components/date-field" },
|
||||
{ title: "Description 描述", url: "/components/description" },
|
||||
{ title: "Disclosure 折叠面板", url: "/components/disclosure" },
|
||||
{
|
||||
|
||||
@@ -60,3 +60,5 @@ description: 已迁移组件及文档
|
||||
- [NumberField 数字输入框](./components/number-field)
|
||||
|
||||
- [Slider 滑块](./components/slider)
|
||||
|
||||
- [DateField 日期字段](./components/date-field):日期分段输入、描述与表单校验。
|
||||
|
||||
@@ -0,0 +1,477 @@
|
||||
---
|
||||
title: DateField 日期字段
|
||||
description: 日期输入字段,包含标签、说明与校验
|
||||
---
|
||||
|
||||
## 用法
|
||||
|
||||
```ts
|
||||
import {
|
||||
DateField,
|
||||
DateFieldGroup,
|
||||
DateFieldInput,
|
||||
DateFieldSegment,
|
||||
} from "@heroui-vue/components";
|
||||
```
|
||||
|
||||
<ComponentPreview name="date-field-basic" />
|
||||
|
||||
## 组件结构
|
||||
|
||||
```vue
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
DateField,
|
||||
DateFieldGroup,
|
||||
DateFieldInput,
|
||||
DateFieldSegment,
|
||||
Label,
|
||||
Description,
|
||||
FieldError,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
<template>
|
||||
<DateField>
|
||||
<Label>日期</Label>
|
||||
<DateFieldGroup>
|
||||
<DateFieldInput v-slot="{ segment }">
|
||||
<DateFieldSegment :segment="segment" />
|
||||
</DateFieldInput>
|
||||
</DateFieldGroup>
|
||||
<Description>输入日期</Description>
|
||||
<FieldError />
|
||||
</DateField>
|
||||
</template>
|
||||
```
|
||||
|
||||
> **DateField** 将标签、日期输入、说明与错误信息组合为单个无障碍组件。
|
||||
|
||||
## 示例
|
||||
|
||||
### 带图标
|
||||
|
||||
通过前缀或后缀图标增强日期输入。
|
||||
|
||||
<ComponentPreview name="date-field-with-prefix-icon" />
|
||||
|
||||
<ComponentPreview name="date-field-with-suffix-icon" />
|
||||
|
||||
<ComponentPreview name="date-field-with-prefix-and-suffix" />
|
||||
|
||||
### 变体
|
||||
|
||||
DateFieldGroup 组件支持两种视觉变体:
|
||||
|
||||
- **`primary`**(默认)- 标准样式带阴影,适用于大多数场景
|
||||
- **`secondary`** - 低强调变体无阴影,适用于 Surface 组件内
|
||||
|
||||
<ComponentPreview name="date-field-variants" />
|
||||
|
||||
### 表面样式
|
||||
|
||||
在 [Surface](/components/surface) 内使用时,请在 DateFieldGroup 上使用 `variant="secondary"` 以应用适合 Surface 背景的低强调变体。
|
||||
|
||||
<ComponentPreview name="date-field-on-surface" />
|
||||
|
||||
### 带描述
|
||||
|
||||
<ComponentPreview name="date-field-with-description" />
|
||||
|
||||
### 必填字段
|
||||
|
||||
<ComponentPreview name="date-field-required" />
|
||||
|
||||
### 禁用
|
||||
|
||||
<ComponentPreview name="date-field-disabled" />
|
||||
|
||||
### 宽度充满
|
||||
|
||||
<ComponentPreview name="date-field-full-width" />
|
||||
|
||||
### 表单校验
|
||||
|
||||
配合 `FieldError` 使用 `isInvalid` 展示校验消息。
|
||||
|
||||
<ComponentPreview name="date-field-invalid" />
|
||||
|
||||
### 时间粒度
|
||||
|
||||
<ComponentPreview name="date-field-granularity" />
|
||||
|
||||
### 受控组件
|
||||
|
||||
使用 `v-model` 控制日期值,以与其他组件或状态管理同步。
|
||||
|
||||
<ComponentPreview name="date-field-controlled" />
|
||||
|
||||
### 表单示例
|
||||
|
||||
包含校验与提交的完整表单示例。
|
||||
|
||||
<ComponentPreview name="date-field-form-example" />
|
||||
|
||||
### 带校验
|
||||
|
||||
DateField 支持 `minValue`、`maxValue` 与自定义校验逻辑。
|
||||
|
||||
<ComponentPreview name="date-field-with-validation" />
|
||||
|
||||
### 渲染函数
|
||||
|
||||
<ComponentPreview name="date-field-render-function" />
|
||||
|
||||
## 自定义样式
|
||||
|
||||
### Tailwind CSS
|
||||
|
||||
<ComponentPreview name="date-field-custom-styles" />
|
||||
|
||||
### 全局 CSS
|
||||
|
||||
DateField 默认样式较轻量。覆盖 `.hv-date-field` 类可自定义容器样式。
|
||||
|
||||
```css
|
||||
@layer components {
|
||||
.hv-date-field {
|
||||
@apply flex flex-col gap-1;
|
||||
|
||||
&[data-invalid="true"],
|
||||
&[aria-invalid="true"] {
|
||||
[data-slot="description"] {
|
||||
@apply hidden;
|
||||
}
|
||||
}
|
||||
|
||||
[data-slot="label"] {
|
||||
@apply w-fit;
|
||||
}
|
||||
|
||||
[data-slot="description"] {
|
||||
@apply px-1;
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 样式参考
|
||||
|
||||
HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态可复用且易于自定义。
|
||||
|
||||
### CSS 类
|
||||
|
||||
- `.hv-date-field` – 轻量样式的根容器(`flex flex-col gap-1`)
|
||||
|
||||
> **Note:** 子组件([Label](/components/label)、[Description](/components/description)、[FieldError](/components/field-error))拥有各自的 CSS 类与样式。自定义方式请参阅对应文档。DateFieldGroup 样式见下文 API 参考。
|
||||
|
||||
### 交互状态
|
||||
|
||||
DateField 会根据状态自动设置以下 data 属性:
|
||||
|
||||
- **Invalid**:`[data-invalid="true"]` 或 `[aria-invalid="true"]` - 无效时自动隐藏 description slot
|
||||
- **Required**:`[data-required="true"]` - 当 `isRequired` 为 true 时应用
|
||||
- **Disabled**:`[data-disabled="true"]` - 当 `isDisabled` 为 true 时应用
|
||||
- **Focus Within**:`[data-focus-within="true"]` - 任一子输入聚焦时应用
|
||||
|
||||
## API 参考
|
||||
|
||||
### DateField
|
||||
|
||||
DateField 使用 Vue 日期值、作用域插槽和共享字段协议。与固定 HeroUI 基线的差异见下方兼容说明。
|
||||
|
||||
#### Base Props
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| ----------- | ---------------- | ------- | ---------------------------------------------------- |
|
||||
| 默认插槽 | `DateFieldState` | - | 子组件(Label、DateFieldGroup 等),支持作用域状态。 |
|
||||
| `class` | `string` | - | 与组件默认样式合并。 |
|
||||
| `style` | `StyleValue` | - | Vue 内联样式。 |
|
||||
| `fullWidth` | `boolean` | `false` | 日期字段是否占满容器宽度。 |
|
||||
| `id` | `string` | - | 元素的唯一 id。 |
|
||||
| `as` | `string` | `"div"` | 自定义容器元素,属性与事件绑定到该容器。 |
|
||||
|
||||
#### Value Props
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| ------------------------------ | ------------------------------------ | ------ | ------------------------------------------------------------------------------------------------------------ |
|
||||
| `modelValue` / `value` | `DateValue \| null` | - | 当前值(受控)。类型见 [`@internationalized/date`](https://react-aria.adobe.com/internationalized/date/)。 |
|
||||
| `defaultValue` | `DateValue \| null` | - | 默认值(非受控)。类型见 [`@internationalized/date`](https://react-aria.adobe.com/internationalized/date/)。 |
|
||||
| `update:modelValue` / `change` | `(value: DateValue \| null) => void` | - | 值变化时触发的事件处理函数。 |
|
||||
| `placeholderValue` | `DateValue \| null` | - | 影响占位符格式的占位日期。 |
|
||||
|
||||
#### Validation Props
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| -------------------- | ------------------------------------------------------------------------------- | ---------- | -------------------------------------------------------------------------------------------------------------- |
|
||||
| `isRequired` | `boolean` | `false` | 是否在提交表单前要求用户输入。 |
|
||||
| `isInvalid` | `boolean` | - | 值是否无效。 |
|
||||
| `minValue` | `DateValue \| null` | - | 用户可选择最早日期。类型见 [`@internationalized/date`](https://react-aria.adobe.com/internationalized/date/)。 |
|
||||
| `maxValue` | `DateValue \| null` | - | 用户可选择最晚日期。类型见 [`@internationalized/date`](https://react-aria.adobe.com/internationalized/date/)。 |
|
||||
| `isDateUnavailable` | `(date: DateValue) => boolean` | - | 针对每个日期调用;返回 true 表示该日期不可用。 |
|
||||
| `validate` | `(value: DateValue \| null) => string \| string[] \| true \| null \| undefined` | - | 自定义校验函数。 |
|
||||
| `validationBehavior` | `'native' \| 'aria'` | `'native'` | 使用原生 HTML 表单校验还是 ARIA 属性。 |
|
||||
|
||||
#### Format Props
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| ------------------------- | ------------- | ------- | ----------------------------------------------------------- |
|
||||
| `granularity` | `Granularity` | - | 显示的最小单位。日期默认为 `"day"`,时间默认为 `"minute"`。 |
|
||||
| `hourCycle` | `12 \| 24` | - | 以 12 或 24 小时制显示时间;默认由语言环境决定。 |
|
||||
| `hideTimeZone` | `boolean` | `false` | 是否隐藏时区缩写。 |
|
||||
| `shouldForceLeadingZeros` | `boolean` | - | 是否始终为月、日、小时等显示前导零。 |
|
||||
|
||||
#### State Props
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| ------------ | --------- | ------ | ---------------------- |
|
||||
| `isDisabled` | `boolean` | - | 是否禁用输入。 |
|
||||
| `isReadOnly` | `boolean` | - | 是否可选中但不可修改。 |
|
||||
|
||||
#### Form Props
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| -------------- | --------- | ------ | ------------------------------------------------------------- |
|
||||
| `name` | `string` | - | 输入元素的 name,用于 HTML 表单提交;以 ISO 8601 字符串提交。 |
|
||||
| `autoFocus` | `boolean` | - | 是否在渲染后自动聚焦该元素。 |
|
||||
| `autoComplete` | `string` | - | 输入应提供的自动完成类型。 |
|
||||
|
||||
#### Accessibility Props
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| ------------------ | -------- | ------ | -------------------------- |
|
||||
| `aria-label` | `string` | - | 无可见标签时的无障碍标签。 |
|
||||
| `aria-labelledby` | `string` | - | 标注该字段的元素 id。 |
|
||||
| `aria-describedby` | `string` | - | 描述该字段的元素 id。 |
|
||||
| `aria-details` | `string` | - | 包含额外详情的元素 id。 |
|
||||
|
||||
### Composition Components
|
||||
|
||||
DateField 与以下独立组件配合使用,请分别导入并直接使用:
|
||||
|
||||
- **Label** – 来自 `@heroui-vue/components` 的字段标签
|
||||
- **DateFieldGroup** – 日期输入分组(详见下文)
|
||||
- **DateFieldInput** – 来自 `@heroui-vue/components` 的分段位编辑输入
|
||||
- **DateFieldInputContainer** – 可横向滚动的容器,用于组合多个输入(例如开始/结束范围)
|
||||
- **DateFieldSegment** – 单个日期段位(年、月、日等)
|
||||
- **DateFieldPrefix** / **DateFieldSuffix** – 输入组的前缀与后缀插槽
|
||||
- **Description** – 来自 `@heroui-vue/components` 的辅助说明
|
||||
- **FieldError** – 来自 `@heroui-vue/components` 的校验错误信息
|
||||
|
||||
这些组件各自有独立的 props API。在 DateField 中直接组合使用:
|
||||
|
||||
```vue
|
||||
<script setup lang="ts">
|
||||
import { shallowRef } from "vue";
|
||||
import {
|
||||
today,
|
||||
getLocalTimeZone,
|
||||
type DateValue,
|
||||
} from "@internationalized/date";
|
||||
import {
|
||||
DateField,
|
||||
DateFieldGroup,
|
||||
DateFieldInput,
|
||||
DateFieldSegment,
|
||||
Label,
|
||||
Description,
|
||||
FieldError,
|
||||
} from "@heroui-vue/components";
|
||||
const date = shallowRef<DateValue | null>(null);
|
||||
const earliest = today(getLocalTimeZone());
|
||||
</script>
|
||||
<template>
|
||||
<DateField v-model="date" is-required :min-value="earliest">
|
||||
<Label>Appointment Date</Label>
|
||||
<DateFieldGroup>
|
||||
<DateFieldInput v-slot="{ segment }">
|
||||
<DateFieldSegment :segment="segment" />
|
||||
</DateFieldInput>
|
||||
</DateFieldGroup>
|
||||
<Description>Select a date from today onwards.</Description>
|
||||
<FieldError />
|
||||
</DateField>
|
||||
</template>
|
||||
```
|
||||
|
||||
### DateValue Types
|
||||
|
||||
DateField 使用 [`@internationalized/date`](https://react-aria.adobe.com/internationalized/date/) 中的类型:
|
||||
|
||||
- `CalendarDate` – 不含时间与时区的日期
|
||||
- `CalendarDateTime` – 含时间、不含时区
|
||||
- `ZonedDateTime` – 含时间与时区
|
||||
|
||||
`Time` 仅表示时间,不属于 DateField 的 `DateValue`;后续 TimeField 单独提供。
|
||||
|
||||
示例:
|
||||
|
||||
```ts
|
||||
import { parseDate, today, getLocalTimeZone } from "@internationalized/date";
|
||||
const date = parseDate("2024-01-15");
|
||||
const todayDate = today(getLocalTimeZone());
|
||||
```
|
||||
|
||||
> **说明:** DateField 依赖 [`@internationalized/date`](https://react-aria.adobe.com/internationalized/date/) 进行解析、运算与类型定义。更多类型与函数见 [Internationalized Date 文档](https://react-aria.adobe.com/internationalized/date/)。
|
||||
|
||||
### Render Props
|
||||
|
||||
默认作用域插槽可读取以下状态;`class`、`style` 使用 Vue 绑定表达式。
|
||||
|
||||
| Prop | 类型 | 描述 |
|
||||
| ------------------ | ------------------- | ---------------------- |
|
||||
| `isDisabled` | `boolean` | 字段是否禁用。 |
|
||||
| `isInvalid` | `boolean` | 字段当前是否无效。 |
|
||||
| `isReadOnly` | `boolean` | 字段是否只读。 |
|
||||
| `isRequired` | `boolean` | 字段是否必填。 |
|
||||
| `isFocusVisible` | `boolean` | 键盘焦点是否可见。 |
|
||||
| `isFocused` | `boolean` | 字段是否聚焦。 |
|
||||
| `isFocusWithin` | `boolean` | 是否有子元素聚焦。 |
|
||||
| `value` | `DateValue \| null` | 当前接受的日期。 |
|
||||
| `validationErrors` | `string[]` | 当前可显示的校验错误。 |
|
||||
|
||||
### DateFieldGroup
|
||||
|
||||
DateFieldGroup 与独立 DateInputGroup 共用部件,透传原生容器属性,并支持:
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| ----------- | -------------------------- | ----------- | -------------------------------------------------------------------------------------- |
|
||||
| `class` | `string` | - | 与组件样式合并的 Tailwind CSS 类。 |
|
||||
| `fullWidth` | `boolean` | `false` | 日期输入组是否占满容器宽度。 |
|
||||
| `variant` | `"primary" \| "secondary"` | `"primary"` | 视觉变体。`primary` 为默认带阴影样式;`secondary` 为低强调、无阴影,适合用于 Surface。 |
|
||||
|
||||
### DateFieldInput
|
||||
|
||||
DateFieldInput 使用默认作用域插槽逐段渲染;省略插槽时自动渲染全部段位。
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| ------- | -------- | ------- | ---------------------------------- |
|
||||
| `class` | `string` | - | 与组件样式合并的 Tailwind CSS 类。 |
|
||||
| `as` | `string` | `"div"` | 输入容器元素。 |
|
||||
|
||||
`DateFieldInput` 通过 `v-slot="{ segment, index }"` 提供日期段位;每个段位对应日期的一部分(年、月、日等)。
|
||||
|
||||
### DateFieldSegment
|
||||
|
||||
DateFieldSegment 渲染来自输入作用域插槽的段位:
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| --------- | ------------- | ------ | ----------------------------------------------------- |
|
||||
| `segment` | `DateSegment` | - | 来自 DateFieldInput 作用域插槽的 `DateSegment` 对象。 |
|
||||
| `class` | `string` | - | 与组件样式合并的 Tailwind CSS 类。 |
|
||||
|
||||
### DateFieldInputContainer
|
||||
|
||||
DateFieldInputContainer 接受标准 HTML `div` 属性:
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| -------- | -------- | ------ | ------------------------------------------------- |
|
||||
| `class` | `string` | - | 与组件样式合并的 Tailwind CSS 类。 |
|
||||
| 默认插槽 | 默认插槽 | - | 滚动容器中的内容(通常为多个 `DateFieldInput`)。 |
|
||||
|
||||
### DateFieldPrefix
|
||||
|
||||
DateFieldPrefix 接受标准 HTML `div` 属性:
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| -------- | -------- | ------ | ---------------------------------- |
|
||||
| `class` | `string` | - | 与组件样式合并的 Tailwind CSS 类。 |
|
||||
| 默认插槽 | 默认插槽 | - | 前缀插槽中要显示的内容。 |
|
||||
|
||||
### DateFieldSuffix
|
||||
|
||||
DateFieldSuffix 接受标准 HTML `div` 属性:
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| -------- | -------- | ------ | ---------------------------------- |
|
||||
| `class` | `string` | - | 与组件样式合并的 Tailwind CSS 类。 |
|
||||
| 默认插槽 | 默认插槽 | - | 后缀插槽中要显示的内容。 |
|
||||
|
||||
## DateFieldGroup Styling
|
||||
|
||||
### Customizing the component classes
|
||||
|
||||
基础类作用于所有实例,可通过 `@layer components` 一次性覆盖。
|
||||
|
||||
```css
|
||||
@layer components {
|
||||
.hv-date-input-group {
|
||||
@apply inline-flex h-9 items-center overflow-hidden rounded-field border bg-field text-sm text-field-foreground shadow-field outline-none;
|
||||
|
||||
&:hover,
|
||||
&[data-hovered="true"] {
|
||||
@apply bg-field-hover;
|
||||
}
|
||||
|
||||
&[data-focus-within="true"],
|
||||
&:focus-within {
|
||||
@apply status-focused-field;
|
||||
}
|
||||
|
||||
&[data-invalid="true"] {
|
||||
@apply status-invalid-field;
|
||||
}
|
||||
|
||||
&[data-disabled="true"],
|
||||
&[aria-disabled="true"] {
|
||||
@apply status-disabled;
|
||||
}
|
||||
}
|
||||
|
||||
.hv-date-input-group__input {
|
||||
@apply flex flex-1 items-center gap-px rounded-none border-0 bg-transparent px-3 py-2 shadow-none outline-none;
|
||||
}
|
||||
|
||||
.hv-date-input-group__segment {
|
||||
@apply inline-block rounded-md px-0.5 text-end tabular-nums outline-none;
|
||||
|
||||
&:focus,
|
||||
&[data-focused="true"] {
|
||||
@apply bg-accent-soft text-accent-soft-foreground;
|
||||
}
|
||||
}
|
||||
|
||||
.hv-date-input-group__input-container {
|
||||
@apply flex flex-1 items-center;
|
||||
overflow-x: auto;
|
||||
overflow-y: clip;
|
||||
scrollbar-width: none;
|
||||
}
|
||||
|
||||
.hv-date-input-group__prefix,
|
||||
.hv-date-input-group__suffix {
|
||||
@apply pointer-events-none shrink-0 text-field-placeholder flex items-center;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### DateFieldGroup CSS Classes
|
||||
|
||||
- `.hv-date-input-group` – 根容器样式
|
||||
- `.hv-date-input-group__input` – 输入包裹层样式
|
||||
- `.hv-date-input-group__input-container` – 用于组合多个输入的滚动容器
|
||||
- `.hv-date-input-group__segment` – 单个日期段位样式
|
||||
- `.hv-date-input-group__prefix` – 前缀元素样式
|
||||
- `.hv-date-input-group__suffix` – 后缀元素样式
|
||||
|
||||
### DateFieldGroup Interactive States
|
||||
|
||||
- **Hover**:`:hover` 或 `[data-hovered="true"]`
|
||||
- **Focus Within**:`[data-focus-within="true"]` 或 `:focus-within`
|
||||
- **Invalid**:`[data-invalid="true"]`(与 `aria-invalid` 同步)
|
||||
- **Disabled**:`[data-disabled="true"]` 或 `[aria-disabled="true"]`
|
||||
- **Segment Focus**:段位上 `:focus` 或 `[data-focused="true"]`
|
||||
- **Segment Placeholder**:段位上 `[data-placeholder="true"]`
|
||||
|
||||
## 相关组件
|
||||
|
||||
[TextField 文本输入框](./text-field) · [NumberField 数字输入框](./number-field) · [Select 选择器](./select)
|
||||
|
||||
## Vue 兼容说明
|
||||
|
||||
- DateField 七部件与 DateInputGroup 六部件共用实现。React 对象组合名改为具名导出,`render` 改为 `as`,渲染函数改为作用域插槽。
|
||||
- 值使用 `v-model` / `update:modelValue`,`change` 是同一次日期提案通知。父组件拒绝更新时显示恢复接受值;未完成的空字段分段输入保留为草稿。显式 `null` / `undefined` 均表示受控空值,初始值只用于非受控状态。
|
||||
- 分段按 locale 日历显示,事件与原生 ISO 提交保留原始模型日历、时间精度和命名时区;`granularity` 只改变显示,不截断提交值。可用 `locale` / `dir` 覆盖 ConfigProvider。
|
||||
- `autoComplete` 传给视觉隐藏的 ISO 文本提交输入;自动填充的 ISO 输入与普通编辑共用接受值协议,不承诺各浏览器会为分段字段提供日期自动填充建议。
|
||||
- 安装版 Reka 2.11.0 的 Root 忽略 `asChild`,内部保留一个无视觉包装;`as`、样式及 DOM 引用归属本库内层容器。原底座左右段位导航不检查 `defaultPrevented`,拦截左右导航时在 Segment 使用 `@keydown.stop.prevent`;仅 `.prevent` 可取消数字/增减编辑,但不能取消祖先底座导航。
|
||||
- 本轮支持键盘与输入法数字编辑。底座没有完整日期粘贴解析;不声明支持粘贴任意本地化日期字符串。全格式粘贴、不同日历的 13 月/era 编辑和完整读屏验收仍需后续专项补齐。
|
||||
- 默认占位日期采用当前本地日期;SSR 跨时区使用者应传入明确的 `placeholderValue` 或初始日期以固定首屏。
|
||||
@@ -0,0 +1,19 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
DateField,
|
||||
DateFieldGroup,
|
||||
DateFieldInput,
|
||||
DateFieldSegment,
|
||||
Label,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
<template>
|
||||
<DateField class="w-[256px]" name="date">
|
||||
<Label>日期</Label>
|
||||
<DateFieldGroup>
|
||||
<DateFieldInput v-slot="{ segment }">
|
||||
<DateFieldSegment :segment="segment" />
|
||||
</DateFieldInput>
|
||||
</DateFieldGroup>
|
||||
</DateField>
|
||||
</template>
|
||||
@@ -0,0 +1,38 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
DateField,
|
||||
DateFieldGroup,
|
||||
DateFieldInput,
|
||||
DateFieldSegment,
|
||||
Label,
|
||||
Description,
|
||||
Button,
|
||||
} from "@heroui-vue/components";
|
||||
import { shallowRef } from "vue";
|
||||
import {
|
||||
today,
|
||||
getLocalTimeZone,
|
||||
type DateValue,
|
||||
} from "@internationalized/date";
|
||||
const value = shallowRef<DateValue | null>(null);
|
||||
const todayDate = today(getLocalTimeZone());
|
||||
</script>
|
||||
<template>
|
||||
<div class="flex flex-col gap-4">
|
||||
<DateField v-model="value" class="w-[256px]" name="date">
|
||||
<Label>日期</Label>
|
||||
<DateFieldGroup>
|
||||
<DateFieldInput v-slot="{ segment }">
|
||||
<DateFieldSegment :segment="segment" />
|
||||
</DateFieldInput>
|
||||
</DateFieldGroup>
|
||||
<Description>
|
||||
当前值:{{ value ? value.toString() : "(空)" }}
|
||||
</Description>
|
||||
</DateField>
|
||||
<div class="flex gap-2">
|
||||
<Button variant="tertiary" @click="value = todayDate">设为今天</Button>
|
||||
<Button variant="tertiary" @click="value = null">清空</Button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,22 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
DateField,
|
||||
DateFieldGroup,
|
||||
DateFieldInput,
|
||||
DateFieldSegment,
|
||||
Label,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
<template>
|
||||
<DateField class="w-64" name="due-date">
|
||||
<Label>截止日期</Label>
|
||||
<DateFieldGroup
|
||||
variant="secondary"
|
||||
class="rounded-xl border border-border/80 bg-default shadow-sm"
|
||||
>
|
||||
<DateFieldInput v-slot="{ segment }">
|
||||
<DateFieldSegment :segment="segment" />
|
||||
</DateFieldInput>
|
||||
</DateFieldGroup>
|
||||
</DateField>
|
||||
</template>
|
||||
@@ -0,0 +1,34 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
DateField,
|
||||
DateFieldGroup,
|
||||
DateFieldInput,
|
||||
DateFieldSegment,
|
||||
Label,
|
||||
Description,
|
||||
} from "@heroui-vue/components";
|
||||
import { today, getLocalTimeZone } from "@internationalized/date";
|
||||
const todayDate = today(getLocalTimeZone());
|
||||
</script>
|
||||
<template>
|
||||
<div class="flex flex-col gap-4">
|
||||
<DateField is-disabled :value="todayDate" class="w-[256px]" name="date">
|
||||
<Label>日期</Label>
|
||||
<DateFieldGroup>
|
||||
<DateFieldInput v-slot="{ segment }">
|
||||
<DateFieldSegment :segment="segment" />
|
||||
</DateFieldInput>
|
||||
</DateFieldGroup>
|
||||
<Description>该日期字段已禁用</Description>
|
||||
</DateField>
|
||||
<DateField is-disabled class="w-[256px]" name="date-empty">
|
||||
<Label>日期</Label>
|
||||
<DateFieldGroup>
|
||||
<DateFieldInput v-slot="{ segment }">
|
||||
<DateFieldSegment :segment="segment" />
|
||||
</DateFieldInput>
|
||||
</DateFieldGroup>
|
||||
<Description>该日期字段已禁用</Description>
|
||||
</DateField>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,70 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
DateField,
|
||||
DateFieldGroup,
|
||||
DateFieldInput,
|
||||
DateFieldSegment,
|
||||
DateFieldPrefix,
|
||||
Label,
|
||||
Description,
|
||||
FieldError,
|
||||
Form,
|
||||
Button,
|
||||
} from "@heroui-vue/components";
|
||||
import { IconCalendar } from "@tabler/icons-vue";
|
||||
import { shallowRef, computed, onBeforeUnmount } from "vue";
|
||||
import {
|
||||
today,
|
||||
getLocalTimeZone,
|
||||
type DateValue,
|
||||
} from "@internationalized/date";
|
||||
const value = shallowRef<DateValue | null>(null);
|
||||
const todayDate = today(getLocalTimeZone());
|
||||
const isInvalid = computed(
|
||||
() => value.value !== null && value.value.compare(todayDate) < 0,
|
||||
);
|
||||
const isSubmitting = shallowRef(false);
|
||||
let timer: ReturnType<typeof setTimeout> | undefined;
|
||||
function submit() {
|
||||
if (!value.value || isInvalid.value || isSubmitting.value) return;
|
||||
isSubmitting.value = true;
|
||||
timer = setTimeout(() => {
|
||||
value.value = null;
|
||||
isSubmitting.value = false;
|
||||
}, 1500);
|
||||
}
|
||||
onBeforeUnmount(() => clearTimeout(timer));
|
||||
</script>
|
||||
<template>
|
||||
<Form class="flex w-[280px] flex-col gap-4" @submit.prevent="submit">
|
||||
<DateField
|
||||
v-model="value"
|
||||
is-required
|
||||
:is-invalid="isInvalid"
|
||||
:min-value="todayDate"
|
||||
class="w-full"
|
||||
name="date"
|
||||
>
|
||||
<Label>预约日期</Label>
|
||||
<DateFieldGroup>
|
||||
<DateFieldPrefix>
|
||||
<IconCalendar class="size-4 text-muted" />
|
||||
</DateFieldPrefix>
|
||||
<DateFieldInput v-slot="{ segment }">
|
||||
<DateFieldSegment :segment="segment" />
|
||||
</DateFieldInput>
|
||||
</DateFieldGroup>
|
||||
<FieldError v-if="isInvalid">日期须为今天或将来</FieldError>
|
||||
<Description v-else>输入日期 from today onwards</Description>
|
||||
</DateField>
|
||||
<Button
|
||||
class="w-full"
|
||||
:is-disabled="!value || isInvalid"
|
||||
:is-pending="isSubmitting"
|
||||
type="submit"
|
||||
variant="primary"
|
||||
>
|
||||
{{ isSubmitting ? "提交中…" : "Submit" }}
|
||||
</Button>
|
||||
</Form>
|
||||
</template>
|
||||
@@ -0,0 +1,38 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
DateField,
|
||||
DateFieldGroup,
|
||||
DateFieldInput,
|
||||
DateFieldSegment,
|
||||
DateFieldPrefix,
|
||||
DateFieldSuffix,
|
||||
Label,
|
||||
} from "@heroui-vue/components";
|
||||
import { IconCalendar, IconChevronDown } from "@tabler/icons-vue";
|
||||
</script>
|
||||
<template>
|
||||
<div class="w-[400px] max-w-full space-y-4">
|
||||
<DateField full-width name="date">
|
||||
<Label>日期</Label>
|
||||
<DateFieldGroup>
|
||||
<DateFieldInput v-slot="{ segment }">
|
||||
<DateFieldSegment :segment="segment" />
|
||||
</DateFieldInput>
|
||||
</DateFieldGroup>
|
||||
</DateField>
|
||||
<DateField full-width name="date-icons">
|
||||
<Label>日期</Label>
|
||||
<DateFieldGroup>
|
||||
<DateFieldPrefix>
|
||||
<IconCalendar class="size-4 text-muted" />
|
||||
</DateFieldPrefix>
|
||||
<DateFieldInput v-slot="{ segment }">
|
||||
<DateFieldSegment :segment="segment" />
|
||||
</DateFieldInput>
|
||||
<DateFieldSuffix>
|
||||
<IconChevronDown class="size-4 text-muted" />
|
||||
</DateFieldSuffix>
|
||||
</DateFieldGroup>
|
||||
</DateField>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,98 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
DateField,
|
||||
DateFieldGroup,
|
||||
DateFieldInput,
|
||||
DateFieldSegment,
|
||||
Label,
|
||||
Select,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
SelectIndicator,
|
||||
SelectPopover,
|
||||
ListBox,
|
||||
ListBoxItem,
|
||||
ListBoxItemIndicator,
|
||||
Tooltip,
|
||||
TooltipTrigger,
|
||||
TooltipContent,
|
||||
} from "@heroui-vue/components";
|
||||
import { computed, ref } from "vue";
|
||||
import { IconHelpCircle } from "@tabler/icons-vue";
|
||||
import { parseDate, parseZonedDateTime } from "@internationalized/date";
|
||||
type Granularity = "day" | "hour" | "minute" | "second";
|
||||
const options = [
|
||||
{ id: "day", label: "日" },
|
||||
{ id: "hour", label: "时" },
|
||||
{ id: "minute", label: "分" },
|
||||
{ id: "second", label: "秒" },
|
||||
] as const;
|
||||
const granularity = ref<Granularity>("day");
|
||||
function setGranularity(value: unknown) {
|
||||
if (options.some((option) => option.id === value))
|
||||
granularity.value = value as Granularity;
|
||||
}
|
||||
const defaultValue = computed(() =>
|
||||
granularity.value === "day"
|
||||
? parseDate("2025-02-03")
|
||||
: parseZonedDateTime("2025-02-03T08:45:00[America/Los_Angeles]"),
|
||||
);
|
||||
</script>
|
||||
<template>
|
||||
<div class="flex flex-wrap gap-4">
|
||||
<DateField
|
||||
:key="granularity"
|
||||
class="w-[256px]"
|
||||
:default-value="defaultValue"
|
||||
:granularity="granularity"
|
||||
name="granularity-date"
|
||||
>
|
||||
<Label>预约日期</Label>
|
||||
<DateFieldGroup>
|
||||
<DateFieldInput v-slot="{ segment }">
|
||||
<DateFieldSegment :segment="segment" />
|
||||
</DateFieldInput>
|
||||
</DateFieldGroup>
|
||||
</DateField>
|
||||
<div class="flex flex-col gap-1">
|
||||
<div class="flex items-center gap-2">
|
||||
<Label>粒度</Label>
|
||||
<Tooltip :delay="0">
|
||||
<TooltipTrigger aria-label="粒度说明">
|
||||
<IconHelpCircle class="size-4 text-muted" />
|
||||
</TooltipTrigger>
|
||||
<TooltipContent placement="bottom start">
|
||||
<p>
|
||||
决定日期选择器显示的最小单位。默认情况下,日期为「日」,时间为「分」。
|
||||
</p>
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
</div>
|
||||
<Select
|
||||
class="w-[110px]"
|
||||
:model-value="granularity"
|
||||
placeholder="选择粒度"
|
||||
variant="secondary"
|
||||
@update:model-value="setGranularity"
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue />
|
||||
<SelectIndicator />
|
||||
</SelectTrigger>
|
||||
<SelectPopover>
|
||||
<ListBox>
|
||||
<ListBoxItem
|
||||
v-for="option in options"
|
||||
:id="option.id"
|
||||
:key="option.id"
|
||||
:text-value="option.label"
|
||||
>
|
||||
{{ option.label }}
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
</ListBox>
|
||||
</SelectPopover>
|
||||
</Select>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,32 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
DateField,
|
||||
DateFieldGroup,
|
||||
DateFieldInput,
|
||||
DateFieldSegment,
|
||||
Label,
|
||||
FieldError,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
<template>
|
||||
<div class="flex flex-col gap-4">
|
||||
<DateField is-invalid is-required class="w-[256px]" name="date">
|
||||
<Label>日期</Label>
|
||||
<DateFieldGroup>
|
||||
<DateFieldInput v-slot="{ segment }">
|
||||
<DateFieldSegment :segment="segment" />
|
||||
</DateFieldInput>
|
||||
</DateFieldGroup>
|
||||
<FieldError>请输入有效日期</FieldError>
|
||||
</DateField>
|
||||
<DateField is-invalid class="w-[256px]" name="invalid-date">
|
||||
<Label>日期</Label>
|
||||
<DateFieldGroup>
|
||||
<DateFieldInput v-slot="{ segment }">
|
||||
<DateFieldSegment :segment="segment" />
|
||||
</DateFieldInput>
|
||||
</DateFieldGroup>
|
||||
<FieldError>日期须为将来</FieldError>
|
||||
</DateField>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,38 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
DateField,
|
||||
DateFieldGroup,
|
||||
DateFieldInput,
|
||||
DateFieldSegment,
|
||||
DateFieldPrefix,
|
||||
Label,
|
||||
Description,
|
||||
Surface,
|
||||
} from "@heroui-vue/components";
|
||||
import { IconCalendar } from "@tabler/icons-vue";
|
||||
</script>
|
||||
<template>
|
||||
<Surface class="flex w-full max-w-sm flex-col gap-4 rounded-3xl p-6">
|
||||
<DateField class="w-full" name="date">
|
||||
<Label>日期</Label>
|
||||
<DateFieldGroup variant="secondary">
|
||||
<DateFieldInput v-slot="{ segment }">
|
||||
<DateFieldSegment :segment="segment" />
|
||||
</DateFieldInput>
|
||||
</DateFieldGroup>
|
||||
<Description>输入日期</Description>
|
||||
</DateField>
|
||||
<DateField class="w-full" name="date-2">
|
||||
<Label>预约日期</Label>
|
||||
<DateFieldGroup variant="secondary">
|
||||
<DateFieldPrefix>
|
||||
<IconCalendar class="size-4 text-muted" />
|
||||
</DateFieldPrefix>
|
||||
<DateFieldInput v-slot="{ segment }">
|
||||
<DateFieldSegment :segment="segment" />
|
||||
</DateFieldInput>
|
||||
</DateFieldGroup>
|
||||
<Description>输入预约日期</Description>
|
||||
</DateField>
|
||||
</Surface>
|
||||
</template>
|
||||
@@ -0,0 +1,23 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
DateField,
|
||||
DateFieldGroup,
|
||||
DateFieldInput,
|
||||
DateFieldSegment,
|
||||
Label,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
<template>
|
||||
<DateField class="w-[256px]" as="div" data-custom="date-field" name="date">
|
||||
<Label data-custom="date-field-label">日期</Label>
|
||||
<DateFieldGroup as="div" data-custom="date-field-group">
|
||||
<DateFieldInput
|
||||
as="div"
|
||||
data-custom="date-field-input"
|
||||
v-slot="{ segment }"
|
||||
>
|
||||
<DateFieldSegment :segment="segment" />
|
||||
</DateFieldInput>
|
||||
</DateFieldGroup>
|
||||
</DateField>
|
||||
</template>
|
||||
@@ -0,0 +1,31 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
DateField,
|
||||
DateFieldGroup,
|
||||
DateFieldInput,
|
||||
DateFieldSegment,
|
||||
Label,
|
||||
Description,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
<template>
|
||||
<div class="flex flex-col gap-4">
|
||||
<DateField is-required class="w-[256px]" name="date">
|
||||
<Label>日期</Label>
|
||||
<DateFieldGroup>
|
||||
<DateFieldInput v-slot="{ segment }">
|
||||
<DateFieldSegment :segment="segment" />
|
||||
</DateFieldInput>
|
||||
</DateFieldGroup>
|
||||
</DateField>
|
||||
<DateField is-required class="w-[256px]" name="start-date">
|
||||
<Label>开始日期</Label>
|
||||
<DateFieldGroup>
|
||||
<DateFieldInput v-slot="{ segment }">
|
||||
<DateFieldSegment :segment="segment" />
|
||||
</DateFieldInput>
|
||||
</DateFieldGroup>
|
||||
<Description>必填项</Description>
|
||||
</DateField>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,29 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
DateField,
|
||||
DateFieldGroup,
|
||||
DateFieldInput,
|
||||
DateFieldSegment,
|
||||
Label,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
<template>
|
||||
<div class="flex flex-col gap-4">
|
||||
<DateField class="w-[256px]" name="primary-date">
|
||||
<Label>主要变体</Label>
|
||||
<DateFieldGroup variant="primary">
|
||||
<DateFieldInput v-slot="{ segment }">
|
||||
<DateFieldSegment :segment="segment" />
|
||||
</DateFieldInput>
|
||||
</DateFieldGroup>
|
||||
</DateField>
|
||||
<DateField class="w-[256px]" name="secondary-date">
|
||||
<Label>次要变体</Label>
|
||||
<DateFieldGroup variant="secondary">
|
||||
<DateFieldInput v-slot="{ segment }">
|
||||
<DateFieldSegment :segment="segment" />
|
||||
</DateFieldInput>
|
||||
</DateFieldGroup>
|
||||
</DateField>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,32 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
DateField,
|
||||
DateFieldGroup,
|
||||
DateFieldInput,
|
||||
DateFieldSegment,
|
||||
Label,
|
||||
Description,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
<template>
|
||||
<div class="flex flex-col gap-4">
|
||||
<DateField class="w-[256px]" name="date">
|
||||
<Label>出生日期</Label>
|
||||
<DateFieldGroup>
|
||||
<DateFieldInput v-slot="{ segment }">
|
||||
<DateFieldSegment :segment="segment" />
|
||||
</DateFieldInput>
|
||||
</DateFieldGroup>
|
||||
<Description>输入出生日期</Description>
|
||||
</DateField>
|
||||
<DateField class="w-[256px]" name="appointment-date">
|
||||
<Label>预约日期</Label>
|
||||
<DateFieldGroup>
|
||||
<DateFieldInput v-slot="{ segment }">
|
||||
<DateFieldSegment :segment="segment" />
|
||||
</DateFieldInput>
|
||||
</DateFieldGroup>
|
||||
<Description>输入预约日期</Description>
|
||||
</DateField>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,30 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
DateField,
|
||||
DateFieldGroup,
|
||||
DateFieldInput,
|
||||
DateFieldSegment,
|
||||
DateFieldPrefix,
|
||||
DateFieldSuffix,
|
||||
Label,
|
||||
Description,
|
||||
} from "@heroui-vue/components";
|
||||
import { IconCalendar, IconChevronDown } from "@tabler/icons-vue";
|
||||
</script>
|
||||
<template>
|
||||
<DateField class="w-[256px]" name="date">
|
||||
<Label>日期</Label>
|
||||
<DateFieldGroup>
|
||||
<DateFieldPrefix>
|
||||
<IconCalendar class="size-4 text-muted" />
|
||||
</DateFieldPrefix>
|
||||
<DateFieldInput v-slot="{ segment }">
|
||||
<DateFieldSegment :segment="segment" />
|
||||
</DateFieldInput>
|
||||
<DateFieldSuffix>
|
||||
<IconChevronDown class="size-4 text-muted" />
|
||||
</DateFieldSuffix>
|
||||
</DateFieldGroup>
|
||||
<Description>输入日期</Description>
|
||||
</DateField>
|
||||
</template>
|
||||
@@ -0,0 +1,24 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
DateField,
|
||||
DateFieldGroup,
|
||||
DateFieldInput,
|
||||
DateFieldSegment,
|
||||
DateFieldPrefix,
|
||||
Label,
|
||||
} from "@heroui-vue/components";
|
||||
import { IconCalendar } from "@tabler/icons-vue";
|
||||
</script>
|
||||
<template>
|
||||
<DateField class="w-[256px]" name="date">
|
||||
<Label>日期</Label>
|
||||
<DateFieldGroup>
|
||||
<DateFieldPrefix>
|
||||
<IconCalendar class="size-4 text-muted" />
|
||||
</DateFieldPrefix>
|
||||
<DateFieldInput v-slot="{ segment }">
|
||||
<DateFieldSegment :segment="segment" />
|
||||
</DateFieldInput>
|
||||
</DateFieldGroup>
|
||||
</DateField>
|
||||
</template>
|
||||
@@ -0,0 +1,24 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
DateField,
|
||||
DateFieldGroup,
|
||||
DateFieldInput,
|
||||
DateFieldSegment,
|
||||
DateFieldSuffix,
|
||||
Label,
|
||||
} from "@heroui-vue/components";
|
||||
import { IconCalendar } from "@tabler/icons-vue";
|
||||
</script>
|
||||
<template>
|
||||
<DateField class="w-[256px]" name="date">
|
||||
<Label>日期</Label>
|
||||
<DateFieldGroup>
|
||||
<DateFieldInput v-slot="{ segment }">
|
||||
<DateFieldSegment :segment="segment" />
|
||||
</DateFieldInput>
|
||||
<DateFieldSuffix>
|
||||
<IconCalendar class="size-4 text-muted" />
|
||||
</DateFieldSuffix>
|
||||
</DateFieldGroup>
|
||||
</DateField>
|
||||
</template>
|
||||
@@ -0,0 +1,43 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
DateField,
|
||||
DateFieldGroup,
|
||||
DateFieldInput,
|
||||
DateFieldSegment,
|
||||
Label,
|
||||
Description,
|
||||
FieldError,
|
||||
} from "@heroui-vue/components";
|
||||
import { shallowRef, computed } from "vue";
|
||||
import {
|
||||
today,
|
||||
getLocalTimeZone,
|
||||
type DateValue,
|
||||
} from "@internationalized/date";
|
||||
const value = shallowRef<DateValue | null>(null);
|
||||
const todayDate = today(getLocalTimeZone());
|
||||
const isInvalid = computed(
|
||||
() => value.value !== null && value.value.compare(todayDate) < 0,
|
||||
);
|
||||
</script>
|
||||
<template>
|
||||
<div class="flex flex-col gap-4">
|
||||
<DateField
|
||||
v-model="value"
|
||||
is-required
|
||||
:is-invalid="isInvalid"
|
||||
:min-value="todayDate"
|
||||
class="w-[256px]"
|
||||
name="date"
|
||||
>
|
||||
<Label>日期</Label>
|
||||
<DateFieldGroup>
|
||||
<DateFieldInput v-slot="{ segment }">
|
||||
<DateFieldSegment :segment="segment" />
|
||||
</DateFieldInput>
|
||||
</DateFieldGroup>
|
||||
<FieldError v-if="isInvalid">日期须为今天或将来</FieldError>
|
||||
<Description v-else>输入日期 from today onwards</Description>
|
||||
</DateField>
|
||||
</div>
|
||||
</template>
|
||||
+85
-85
@@ -2,91 +2,91 @@
|
||||
|
||||
基于固定上游提交的公共组件导出清单。验证中不等于完整兼容;目前没有组件完成视觉、浏览器与完整行为验收。
|
||||
|
||||
| 组件 | 状态 | 当前能力 / 差异 |
|
||||
| -------------------- | -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| accordion | 验证中(M23) | Accordion/Item/Heading/Trigger/Panel/Body/Indicator;10/10 基线例;surface/hideSeparator;复用组键协议 |
|
||||
| alert-dialog | 验证中(M33) | 11 部件;role=alertdialog;默认不误关;14/14 基线例;Reka Dialog 底座 |
|
||||
| autocomplete | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| avatar | 验证中(最小实现) | Reka Avatar 加载/回退;size/color/variant;Image asChild;AvatarGroup 继承仅限直接子级 |
|
||||
| avatar-group | 验证中(最小实现) | max 截断与自动计数、显式 Count 不受截断、isGrid、overlap clip/ring;默认无 role=group |
|
||||
| badge | 验证中(最小实现) | Badge/BadgeAnchor/BadgeLabel;四角定位、圆点、文本/数字自动包装;Anchor 非链接 |
|
||||
| breadcrumbs | 验证中(M17) | Breadcrumbs/BreadcrumbsItem;7/7 基线例;ol+aria-label、末项 current、禁用/无 href span、separator 插槽;onAction 未提供,class 同时落 li/link |
|
||||
| button | 验证中(最小实现) | 基线全部 7 种变体、尺寸、isIconOnly/isDisabled/isPending;PressEvent 与 Vue click 差异见文档 |
|
||||
| button-group | 验证中(M26) | ButtonGroup/ButtonGroupSeparator;9/9 基线例;直接子 Button 继承 size/variant/isDisabled/fullWidth;嵌套不继承;圆角与 outline 边框处理 |
|
||||
| card | 验证中(最小实现) | 4 种表面变体;Header/Title/Description/Content/Footer 已实现;以基线 CSS 为准 |
|
||||
| checkbox | 验证中(基线实现) | 原生 label/input;checked/isSelected、半选、primary/secondary、Content/Control/Indicator;15 个基线预览 |
|
||||
| checkbox-group | 验证中(基线实现) | 数组模型、同名重复提交、required/readonly/disabled/reset、组标签与成员描述隔离;10 个基线预览 |
|
||||
| chip | 验证中(最小实现) | color/size/variant;纯文本/数字自动包装为 ChipLabel;显式部件不重复包装;组合内容可动态切换 |
|
||||
| color-area | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| color-field | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| color-picker | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| color-slider | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| color-swatch | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| color-swatch-picker | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| close-button | 验证中(最小实现) | 专用 CSS/变体、默认基线 CloseIcon、插槽替换图标、isDisabled、aria-label 默认 Close;onPress 由 click 适配 |
|
||||
| combo-box | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| date-field | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| date-picker | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| date-range-picker | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| drawer | 验证中(M34) | 11 部件;四方向拖动关闭(30%/0.5px/ms);9/9 基线例;Content/Dialog 职责分离 |
|
||||
| progress-bar | 验证中(M18) | ProgressBar/Output/Track/Fill;7/7 基线例;确定/未知进度、min/max/formatOptions/valueLabel;custom-value 的 NumberField/Select 为原生临时控件 |
|
||||
| progress-circle | 验证中(M19) | ProgressCircle/Track/TrackCircle/FillCircle;7/7 基线例;圆环几何可覆盖;与 ProgressBar 共用取值语义 |
|
||||
| time-field | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| disclosure | 验证中(M21) | Disclosure/Heading/Trigger/Content/Body/Indicator;3/3 基线例;v-model:expanded;asChild 触发;高度动画映射测量变量 |
|
||||
| disclosure-group | 验证中(M22) | DisclosureGroup + useDisclosureGroupNavigation;3/3 基线例;展开键为数组(string 或 number);单选替换/多选增量 |
|
||||
| error-message | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| kbd | 验证中(最小实现) | variant;KbdAbbr keyValue 映射与 title;KbdContent;上下文类名;导出 kbdKeysMap/LabelMap |
|
||||
| link | 验证中(最小实现) | 原生 a + LinkIcon;isDisabled/asChild/焦点与 data 状态;默认图标为基线 ExternalLinkIcon;onPress 由 click 适配 |
|
||||
| popover | 验证中(OVERLAY-02) | Root/Trigger/Content/Dialog/Heading/Arrow;6/6 基线例;逻辑定位/碰撞/退出/标题;模态 closeAutoFocus 不支持取消恢复,见 OVERLAY-02 |
|
||||
| scroll-shadow | 验证中(M24) | 7/7 基线例;fade/方向/尺寸/偏移/受控可见性;VueUse 测量与公开 useScrollShadow,RTL/动态内容;CSS scroll timeline 保留 |
|
||||
| separator | 验证中(最小实现) | orientation/variant/decorative;默认 hr + role=separator;asChild 自定义根;Reka Separator |
|
||||
| skeleton | 验证中(最小实现) | shimmer/pulse/none、--skeleton-animation 全局默认、父级单次 shimmer;挂载后改 CSS 变量不自动更新 |
|
||||
| spinner | 验证中(最小实现) | size/color 变体、role=status、内置渐变 SVG;嵌入 Button 保持 16px;reduced-motion 支持 |
|
||||
| surface | 验证中(最小实现) | 4 种变体、data-slot、surfaceContextKey 提供当前变体;Input 文档表面示例已替换为 Surface |
|
||||
| toast | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| toggle-button | 验证中(M27) | ToggleButton;7/7 基线例;v-model/isSelected/defaultSelected;data-selected/pressed/hover/focus;Enter/Space;组内 radio 语义 |
|
||||
| switch | 验证中(最小实现) | 根字段与组合部件、3 尺寸、ARIA 透传、原生/ARIA 校验、FormData/reset;PressEvent 不等价 |
|
||||
| switch-group | 验证中(布局) | vertical/horizontal;不共享选择值,已移植基线 CSS |
|
||||
| tabs | 验证中(M25) | 七部件、10/10 基线例;primary/secondary、方向/对齐、受控/键盘/禁用/滚动/指示器;Vue 模型与 ID/集合差异见报告 |
|
||||
| tag | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| tag-group | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| toggle-button-group | 验证中(M28) | ToggleButtonGroup/Separator;10/10 基线例;single/multiple、disallowEmptySelection、roving focus;Vue 数组模型替代 Set<Key> |
|
||||
| toolbar | 验证中(M29) | Toolbar;5/5 基线例;isAttached/orientation/dir;跨组单 Tab 入口与方向键;子组焦点让位;Separator 垂直继承 |
|
||||
| tooltip | 验证中(OVERLAY-02) | Root/Trigger/Content/Arrow;6/6 基线例;CSS 延迟/焦点/禁用/替换/定位;Provider warmup 与 RAC 全局调度不同 |
|
||||
| input | 验证中(字段接入) | 接入 TextField;复用值恢复/reset/ARIA;独立使用保持兼容;完整消费验收未完成 |
|
||||
| input-group | 验证中(字段接入) | Root/Input/TextArea/Prefix/Suffix;复用 useTextControl;变体继承 TextField 可覆盖;前后缀非表单字段 |
|
||||
| textarea | 验证中(字段接入) | rows 默认 3;变体/fullWidth/受控/FormData/reset;独立页 7/7 示例;接入 useTextControl |
|
||||
| textfield | 验证中(字段接入) | 值/状态/约束/校验/ID;独立页 13/13 示例;render 自定义根类型未支持(data-* 透传) |
|
||||
| search-field | 验证中(FORM-02) | 五部件、15 基线例;共享文本内核、clear/submit/IME/reset/SSR,边界见 FORM-02 |
|
||||
| typography | 验证中(M15) | Typography/Heading/Paragraph/Code/Prose 具名导出;6/6 基线例;type/as/align/color/weight/truncate;render 映射为 as |
|
||||
| label | 验证中(通用字段) | 自动 for、Switch 内 span、状态继承;独立页 2/2 示例 |
|
||||
| description | 验证中(通用字段) | 动态 ID 清理、外部 describedby 合并;独立页 2/2 示例;SSR 包装限制见基础协议 |
|
||||
| empty-state | 验证中(M16) | 单根 EmptyState;4 个自编示例(基线无页面/示例);默认 fallback;空节点判断与上游 children 真值回退边界不同 |
|
||||
| field-error | 验证中(通用字段) | 作用域插槽 validationErrors;独立页 2/2 示例;无完整 validationDetails(见基础协议) |
|
||||
| fieldset | 验证中(FORM-02) | 四部件、3 基线例与禁用验证例;响应式禁用、首 Legend 例外,边界见 FORM-02 |
|
||||
| form | 验证中(基础设施) | native/aria 校验、FormData/reset、服务端错误;完整基线文档与生态集成未完成 |
|
||||
| header | 验证中(M31) | Header/HeaderRoot;原生 `<header>` 集合分组标题;基线无独立文档/演示,自编 3 例并标注;无 v-model |
|
||||
| radio | 验证中(基线实现) | 原生 radio + Content/Control/Indicator;须在 RadioGroup 内,成员禁用/只读、作用域状态 |
|
||||
| radio-group | 验证中(基线实现) | 标量模型、roving Tab/方向键/dir/loop、原生提交/校验/reset;12 个基线预览 |
|
||||
| input-otp | 验证中(M32) | Root/Group/Slot/Separator + 3 正则常量;Reka PinInput 底座;字符串+索引数组;reset/Fieldset/Form/ARIA/mask 已接入;11/11 例;自动填充/IME/读屏未真机验证 |
|
||||
| alert | 验证中(最小实现) | status 五态;默认图标随 status;自定义 Indicator 空内容回退;内部 Surface 重置为 default |
|
||||
| list-box | 验证中(LISTBOX-01) | 四部件、9/9 基线例;typed key/数组模型、none/single/multiple、键盘/范围/全选、1000 项固定行高虚拟化;差异见 LISTBOX-01 |
|
||||
| list-box-item | 验证中(LISTBOX-01) | ListBox 子部件;独立标签/描述作用域、自动分组名称、原生标签替换、状态/指示器;见 LISTBOX-01 |
|
||||
| list-box-section | 验证中(LISTBOX-01) | ListBox 子部件;独立标签/描述作用域、自动分组名称、原生标签替换、状态/指示器;见 LISTBOX-01 |
|
||||
| dropdown | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| menu | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| menu-item | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| menu-section | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| modal | 验证中(OVERLAY-02) | Root/Trigger/Backdrop/Container/Dialog/Heading/Header/Body/Footer/Icon/Close/CloseTrigger;14/14 基线例;焦点/锁/滚动/退出动画;Vue close 部件替代 React slot |
|
||||
| pagination | 验证中(M30) | 组合式 nav 容器(无 total/page 状态机);11 具名部件;9/9 基线例;onPress→@click;显式 aria-current 可覆盖 |
|
||||
| number-field | 验证中(NUMBER-01) | 五部件与 17/17 基线例;Reka 数值内核;受控/只读/表单 reset、SSR/水合;差异见 NUMBER-01 报告 |
|
||||
| select | 验证中(SELECT-01) | 六部件、19/19 例、单/多选、清空、字段/原生提交/SSR/异步;复用 ListBox + Popover,重点浏览器已验,限制见 SELECT-01 |
|
||||
| meter | 验证中(M20) | Meter/Output/Track/Fill;6/6 基线例;role=meter progressbar;无 isIndeterminate;测量语义独立于 Progress |
|
||||
| slider | 验证中(SLIDER-01) | 六部件、9/9 基线例;原生 range/局部指针适配,单值/范围、受控/reset/SSR/水合;差异见 SLIDER-01 |
|
||||
| table | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| calendar | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| range-calendar | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| calendar-year-picker | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| 组件 | 状态 | 当前能力 / 差异 |
|
||||
| -------------------- | ------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| accordion | 验证中(M23) | Accordion/Item/Heading/Trigger/Panel/Body/Indicator;10/10 基线例;surface/hideSeparator;复用组键协议 |
|
||||
| alert-dialog | 验证中(M33) | 11 部件;role=alertdialog;默认不误关;14/14 基线例;Reka Dialog 底座 |
|
||||
| autocomplete | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| avatar | 验证中(最小实现) | Reka Avatar 加载/回退;size/color/variant;Image asChild;AvatarGroup 继承仅限直接子级 |
|
||||
| avatar-group | 验证中(最小实现) | max 截断与自动计数、显式 Count 不受截断、isGrid、overlap clip/ring;默认无 role=group |
|
||||
| badge | 验证中(最小实现) | Badge/BadgeAnchor/BadgeLabel;四角定位、圆点、文本/数字自动包装;Anchor 非链接 |
|
||||
| breadcrumbs | 验证中(M17) | Breadcrumbs/BreadcrumbsItem;7/7 基线例;ol+aria-label、末项 current、禁用/无 href span、separator 插槽;onAction 未提供,class 同时落 li/link |
|
||||
| button | 验证中(最小实现) | 基线全部 7 种变体、尺寸、isIconOnly/isDisabled/isPending;PressEvent 与 Vue click 差异见文档 |
|
||||
| button-group | 验证中(M26) | ButtonGroup/ButtonGroupSeparator;9/9 基线例;直接子 Button 继承 size/variant/isDisabled/fullWidth;嵌套不继承;圆角与 outline 边框处理 |
|
||||
| card | 验证中(最小实现) | 4 种表面变体;Header/Title/Description/Content/Footer 已实现;以基线 CSS 为准 |
|
||||
| checkbox | 验证中(基线实现) | 原生 label/input;checked/isSelected、半选、primary/secondary、Content/Control/Indicator;15 个基线预览 |
|
||||
| checkbox-group | 验证中(基线实现) | 数组模型、同名重复提交、required/readonly/disabled/reset、组标签与成员描述隔离;10 个基线预览 |
|
||||
| chip | 验证中(最小实现) | color/size/variant;纯文本/数字自动包装为 ChipLabel;显式部件不重复包装;组合内容可动态切换 |
|
||||
| color-area | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| color-field | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| color-picker | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| color-slider | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| color-swatch | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| color-swatch-picker | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| close-button | 验证中(最小实现) | 专用 CSS/变体、默认基线 CloseIcon、插槽替换图标、isDisabled、aria-label 默认 Close;onPress 由 click 适配 |
|
||||
| combo-box | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| date-field | 已迁移(有已知差异) | DateField 七部件与 DateInputGroup 六部件、17 预览;完整 ISO、字段校验、reset、SSR/水合与浏览器重点检查,见 DATE-02 报告;本地化整日期粘贴、13 月/era 编辑等仍待专项。 |
|
||||
| date-picker | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| date-range-picker | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| drawer | 验证中(M34) | 11 部件;四方向拖动关闭(30%/0.5px/ms);9/9 基线例;Content/Dialog 职责分离 |
|
||||
| progress-bar | 验证中(M18) | ProgressBar/Output/Track/Fill;7/7 基线例;确定/未知进度、min/max/formatOptions/valueLabel;custom-value 的 NumberField/Select 为原生临时控件 |
|
||||
| progress-circle | 验证中(M19) | ProgressCircle/Track/TrackCircle/FillCircle;7/7 基线例;圆环几何可覆盖;与 ProgressBar 共用取值语义 |
|
||||
| time-field | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| disclosure | 验证中(M21) | Disclosure/Heading/Trigger/Content/Body/Indicator;3/3 基线例;v-model:expanded;asChild 触发;高度动画映射测量变量 |
|
||||
| disclosure-group | 验证中(M22) | DisclosureGroup + useDisclosureGroupNavigation;3/3 基线例;展开键为数组(string 或 number);单选替换/多选增量 |
|
||||
| error-message | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| kbd | 验证中(最小实现) | variant;KbdAbbr keyValue 映射与 title;KbdContent;上下文类名;导出 kbdKeysMap/LabelMap |
|
||||
| link | 验证中(最小实现) | 原生 a + LinkIcon;isDisabled/asChild/焦点与 data 状态;默认图标为基线 ExternalLinkIcon;onPress 由 click 适配 |
|
||||
| popover | 验证中(OVERLAY-02) | Root/Trigger/Content/Dialog/Heading/Arrow;6/6 基线例;逻辑定位/碰撞/退出/标题;模态 closeAutoFocus 不支持取消恢复,见 OVERLAY-02 |
|
||||
| scroll-shadow | 验证中(M24) | 7/7 基线例;fade/方向/尺寸/偏移/受控可见性;VueUse 测量与公开 useScrollShadow,RTL/动态内容;CSS scroll timeline 保留 |
|
||||
| separator | 验证中(最小实现) | orientation/variant/decorative;默认 hr + role=separator;asChild 自定义根;Reka Separator |
|
||||
| skeleton | 验证中(最小实现) | shimmer/pulse/none、--skeleton-animation 全局默认、父级单次 shimmer;挂载后改 CSS 变量不自动更新 |
|
||||
| spinner | 验证中(最小实现) | size/color 变体、role=status、内置渐变 SVG;嵌入 Button 保持 16px;reduced-motion 支持 |
|
||||
| surface | 验证中(最小实现) | 4 种变体、data-slot、surfaceContextKey 提供当前变体;Input 文档表面示例已替换为 Surface |
|
||||
| toast | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| toggle-button | 验证中(M27) | ToggleButton;7/7 基线例;v-model/isSelected/defaultSelected;data-selected/pressed/hover/focus;Enter/Space;组内 radio 语义 |
|
||||
| switch | 验证中(最小实现) | 根字段与组合部件、3 尺寸、ARIA 透传、原生/ARIA 校验、FormData/reset;PressEvent 不等价 |
|
||||
| switch-group | 验证中(布局) | vertical/horizontal;不共享选择值,已移植基线 CSS |
|
||||
| tabs | 验证中(M25) | 七部件、10/10 基线例;primary/secondary、方向/对齐、受控/键盘/禁用/滚动/指示器;Vue 模型与 ID/集合差异见报告 |
|
||||
| tag | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| tag-group | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| toggle-button-group | 验证中(M28) | ToggleButtonGroup/Separator;10/10 基线例;single/multiple、disallowEmptySelection、roving focus;Vue 数组模型替代 Set<Key> |
|
||||
| toolbar | 验证中(M29) | Toolbar;5/5 基线例;isAttached/orientation/dir;跨组单 Tab 入口与方向键;子组焦点让位;Separator 垂直继承 |
|
||||
| tooltip | 验证中(OVERLAY-02) | Root/Trigger/Content/Arrow;6/6 基线例;CSS 延迟/焦点/禁用/替换/定位;Provider warmup 与 RAC 全局调度不同 |
|
||||
| input | 验证中(字段接入) | 接入 TextField;复用值恢复/reset/ARIA;独立使用保持兼容;完整消费验收未完成 |
|
||||
| input-group | 验证中(字段接入) | Root/Input/TextArea/Prefix/Suffix;复用 useTextControl;变体继承 TextField 可覆盖;前后缀非表单字段 |
|
||||
| textarea | 验证中(字段接入) | rows 默认 3;变体/fullWidth/受控/FormData/reset;独立页 7/7 示例;接入 useTextControl |
|
||||
| textfield | 验证中(字段接入) | 值/状态/约束/校验/ID;独立页 13/13 示例;render 自定义根类型未支持(data-* 透传) |
|
||||
| search-field | 验证中(FORM-02) | 五部件、15 基线例;共享文本内核、clear/submit/IME/reset/SSR,边界见 FORM-02 |
|
||||
| typography | 验证中(M15) | Typography/Heading/Paragraph/Code/Prose 具名导出;6/6 基线例;type/as/align/color/weight/truncate;render 映射为 as |
|
||||
| label | 验证中(通用字段) | 自动 for、Switch 内 span、状态继承;独立页 2/2 示例 |
|
||||
| description | 验证中(通用字段) | 动态 ID 清理、外部 describedby 合并;独立页 2/2 示例;SSR 包装限制见基础协议 |
|
||||
| empty-state | 验证中(M16) | 单根 EmptyState;4 个自编示例(基线无页面/示例);默认 fallback;空节点判断与上游 children 真值回退边界不同 |
|
||||
| field-error | 验证中(通用字段) | 作用域插槽 validationErrors;独立页 2/2 示例;无完整 validationDetails(见基础协议) |
|
||||
| fieldset | 验证中(FORM-02) | 四部件、3 基线例与禁用验证例;响应式禁用、首 Legend 例外,边界见 FORM-02 |
|
||||
| form | 验证中(基础设施) | native/aria 校验、FormData/reset、服务端错误;完整基线文档与生态集成未完成 |
|
||||
| header | 验证中(M31) | Header/HeaderRoot;原生 `<header>` 集合分组标题;基线无独立文档/演示,自编 3 例并标注;无 v-model |
|
||||
| radio | 验证中(基线实现) | 原生 radio + Content/Control/Indicator;须在 RadioGroup 内,成员禁用/只读、作用域状态 |
|
||||
| radio-group | 验证中(基线实现) | 标量模型、roving Tab/方向键/dir/loop、原生提交/校验/reset;12 个基线预览 |
|
||||
| input-otp | 验证中(M32) | Root/Group/Slot/Separator + 3 正则常量;Reka PinInput 底座;字符串+索引数组;reset/Fieldset/Form/ARIA/mask 已接入;11/11 例;自动填充/IME/读屏未真机验证 |
|
||||
| alert | 验证中(最小实现) | status 五态;默认图标随 status;自定义 Indicator 空内容回退;内部 Surface 重置为 default |
|
||||
| list-box | 验证中(LISTBOX-01) | 四部件、9/9 基线例;typed key/数组模型、none/single/multiple、键盘/范围/全选、1000 项固定行高虚拟化;差异见 LISTBOX-01 |
|
||||
| list-box-item | 验证中(LISTBOX-01) | ListBox 子部件;独立标签/描述作用域、自动分组名称、原生标签替换、状态/指示器;见 LISTBOX-01 |
|
||||
| list-box-section | 验证中(LISTBOX-01) | ListBox 子部件;独立标签/描述作用域、自动分组名称、原生标签替换、状态/指示器;见 LISTBOX-01 |
|
||||
| dropdown | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| menu | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| menu-item | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| menu-section | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| modal | 验证中(OVERLAY-02) | Root/Trigger/Backdrop/Container/Dialog/Heading/Header/Body/Footer/Icon/Close/CloseTrigger;14/14 基线例;焦点/锁/滚动/退出动画;Vue close 部件替代 React slot |
|
||||
| pagination | 验证中(M30) | 组合式 nav 容器(无 total/page 状态机);11 具名部件;9/9 基线例;onPress→@click;显式 aria-current 可覆盖 |
|
||||
| number-field | 验证中(NUMBER-01) | 五部件与 17/17 基线例;Reka 数值内核;受控/只读/表单 reset、SSR/水合;差异见 NUMBER-01 报告 |
|
||||
| select | 验证中(SELECT-01) | 六部件、19/19 例、单/多选、清空、字段/原生提交/SSR/异步;复用 ListBox + Popover,重点浏览器已验,限制见 SELECT-01 |
|
||||
| meter | 验证中(M20) | Meter/Output/Track/Fill;6/6 基线例;role=meter progressbar;无 isIndeterminate;测量语义独立于 Progress |
|
||||
| slider | 验证中(SLIDER-01) | 六部件、9/9 基线例;原生 range/局部指针适配,单值/范围、受控/reset/SSR/水合;差异见 SLIDER-01 |
|
||||
| table | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| calendar | 基建中(DATE-01,未公开) | 月历/多选/非公历/键盘/SSR 探针;公共部件、YearPicker 与 19 预览待实施,见日期基建决策 |
|
||||
| range-calendar | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| calendar-year-picker | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
|
||||
## 公共导出差异
|
||||
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
# DATE-01:日期字段与日历基建
|
||||
|
||||
2026-10-23,独立目录 `heroui-vue-core`,`feat/date-calendar-foundation`,从同步并推送的 main `3c878d2` 新建。其他 AI 的 Toast/Table 任务与本目录隔离。
|
||||
|
||||
## 基线和范围
|
||||
|
||||
固定 HeroUI 3.2.6 / `ce90ea3ab49d58f6c428f71bfd6fe8ae2a87b960`。核对本地基线的 date-field、date-input-group、calendar、calendar-year-picker、date/time/range/picker 相关导出;对应 CSS/tv、中文正文及演示是后续公共迁移清单。
|
||||
|
||||
- DateField 共七部件:Root、Group、Input、InputContainer、Segment、Prefix、Suffix。后六项实际复用 DateInputGroup;不能漏掉独立 DateInputGroup 的六个具名部件,也不能给 TimeField/DatePicker 再建一套分段输入内核。
|
||||
- DateField 中文正文 **16** 预览:basic、with-prefix-icon、with-suffix-icon、with-prefix-and-suffix、variants、on-surface、with-description、required、disabled、full-width、invalid、granularity、controlled、form-example、with-validation、custom-styles。目录的 render-function 存在,但不是该正文预览;后续作为补充,不替换任何基线例。
|
||||
- Calendar 中文正文 **19** 预览:basic、disabled、read-only、default-value、year-picker、controlled、min-max-dates、unavailable-dates、weeks-in-month、week-view、day-view、multiple-selection、focused-value、with-indicators、custom-icons、multiple-months、booking-calendar、international-calendar、custom-styles。
|
||||
- Calendar 为十个日历部件加六个 YearPicker 部件;CalendarYearPicker 独立导出及 Calendar 的便捷别名均须核对。visibleDuration 的 month/week/day、焦点日期、1900–2099 默认年界、非公历和范围族不是普通月历的同义词。
|
||||
|
||||
本轮只落地私有日期值边界、接受值薄适配、安装版能力夹具和测试。**没有导出公共 DateField / Calendar,没有复制日期 CSS 或把未完成示例加入导航,不宣称组件或视觉迁移完成。**
|
||||
|
||||
## 安装版本与依赖边界
|
||||
|
||||
实际安装 Reka **2.11.0**、`@internationalized/date` **3.12.4**(Apache-2.0)。组件包将日期库声明为直接依赖并 external;根测试也显式声明,不依赖上游目录或碰巧提升的传递依赖。保留现有声明路径规范化,后续公开类型继续核对 bundler/NodeNext 正反例。
|
||||
|
||||
不转成 JS Date 再还原 CalendarDate,不解析格式化的人类文字作为模型,不把 locale、calendar、timeZone 和 granularity 当作同一概念。
|
||||
|
||||
## 真实底座结果
|
||||
|
||||
探针为 `tests/date-foundation.test.ts` 和真正 node 的 `date-foundation-ssr.test.ts`。以下已操作实际 DOM / 焦点 / FormData / 事件载荷,未用组件仍挂载代替验收。
|
||||
|
||||
| 场景 | Reka 2.11.0 结果 | 接续方案 |
|
||||
| ---------------------------- | ------------------------------------------------------------------------------- | --------------------------------------------------------------------------------- |
|
||||
| DateField day ArrowUp | 保留 CalendarDate 类并提交 ISO date | 可复用分段交互;公共事件用 DateValue/null |
|
||||
| DateField 受控拒绝 | 原生输入仍为父日期,day 分段却前移一天 | 私有接受值适配已证明修复,不保存乐观接受值 |
|
||||
| 原生 form.reset | 已编辑分段不恢复初值 | 复用 useChoiceForm,重置接受值并刷新 wire;取消/受控 reset 分开测 |
|
||||
| DateTime minute 显示 | 编辑后事件保留秒/毫秒,原生提交截断为 minute | 显示粒度不裁剪模型;唯一序列化层保留完整 toString |
|
||||
| ZonedDateTime | 分段可显示 PST,但 datetime-local 提交缺少 offset / zone | 保留完整 DateValue 和 zone,不拿本地 datetime 字符串当完整模型 |
|
||||
| 非公历 DateField | 原生输入按 calendar.year/month/day 拼值,与 ISO toString 不同 | 公共提交使用日期库的序列化边界 |
|
||||
| required/readonly/disabled | native required 生效;readonly 仍提交;disabled 不提交 | 公共字段仍消费本库 Fieldset/Form,不直接接 Reka FieldRoot 另建协议 |
|
||||
| locale 动态切换 | en-US 月/日/年切到 zh-CN 年/月/日 | 可复用格式化;组合部件需同步焦点和 DOM ref |
|
||||
| Calendar 闰月/禁用/不可用 | 2 月 29 日存在;方向键跳过 disabled,但可聚焦 unavailable;不可用项不能选择 | disabled 与 unavailable 分开,不能统一过滤成不可聚焦 |
|
||||
| Calendar 受控拒绝/重试 | 选择仍由父值控制,两次相同点击均发出提案 | 复用已接受选择语义 |
|
||||
| Calendar multiple | runtime 发 DateValue[],声明仍写 scalar emit/defaultValue | 公共 schema 自己定义,不从底座泛型/事件机械提取 |
|
||||
| Calendar 键盘取消 | 子 Cell 处理导航并 stopPropagation,Root 的 bubble keydown 无法取消已执行的移动 | 公共层必须先验证真实 asChild 节点取消;若仍过晚再局部适配键盘,不悄悄挪到 capture |
|
||||
| Calendar 两个月/fixedWeeks | 两张月表、每月 6 行 | 可复用普通月网格,不据此声称 week/day view 已具备 |
|
||||
| Gregorian 值 + Indian locale | 明确 Gregorian placeholder 时仍生成 Gregorian 2 月 29 项网格 | 明确转换视图 calendar,不能只换标题格式或静默改写公共模型 |
|
||||
| Calendar node SSR | 可输出选中日、闰月和日期值;CalendarGrid 默认为 role=application | 核对 RAC 真正 ARIA 与原生 asChild 归属后再适配,不能凭名字认定 role=grid |
|
||||
|
||||
Calendar 键盘探针同时发送 key/code;安装版用 code 导航。只发 key 的 jsdom 事件不能作为“导航失败”的结论。
|
||||
|
||||
## 已落地的私有值协议
|
||||
|
||||
`packages/vue/src/components/date/` 不从公共入口导出。
|
||||
|
||||
- `value.ts`:复制 CalendarDate / CalendarDateTime / ZonedDateTime,保留 calendar/era/时间精度/zone/offset;日期身份区分纯日期与午夜 DateTime、相同 ISO 下的不同日历。复制数组去重和范围保留不完整草稿,不把清空、未完成和倒置范围混同。
|
||||
- `serializeDateValue` 使用完整 toString,null/undefined 为空字符串;未来公共表单须明确单选/多选/范围的 name 规则,底座不再重复提交。
|
||||
- `calendarDayState` 按本地 calendar day 比较范围,并区分 disabled/unavailable/selectable。它只负责日历日,不冒充时间字段的精确时刻边界。
|
||||
- `dateForLocale` 只转换视图,保留日期类、时间/zone 和瞬时值;公共模型是否转换、变更事件如何返回必须由组件边界明确处理。
|
||||
- `model.ts` 复用既有 useChoiceValue:只保存接受值与捕获的初值。wire 为接受值副本,显式空值用 null 避免底座在 undefined 初值下进入 passive。完成提案后重新提供副本,让底座重新同步分段;部分未完成草稿仍留给底座,不在每个按键后清掉。
|
||||
- 受控拒绝时真实分段和提交保持父值,同一提案可重试;事件对象与内部值分别复制。非受控 reset 恢复初值,受控 reset 保留父值,不合成 change 事件。沿用 useChoiceForm 的归属/取消/清理,不建第二套 reset 监听器。
|
||||
|
||||
`AcceptedDateFieldFoundation.vue` 是适配验证夹具,不是公开字段:它用 nameless 底座输入和一个完整 ISO 隐藏提交值证明边界;尚未实现本库 Label/Description/FieldError、完整字段约束、插槽与主题,不能拿它充数上线。
|
||||
|
||||
## 验证与后续批次
|
||||
|
||||
本轮新增 **39** 项:10 项值边界、15 项底座探针、10 项接受值/表单/实际 jsdom 水合,以及 4 项真正 node SSR。模型类/秒毫秒/DST/alternate calendar、拒绝重试、取消 reset、SSR 与水合分别断言。最终完整回归数量见 verification.md。
|
||||
|
||||
下一步按依赖顺序实施:
|
||||
|
||||
1. **DateInputGroup + DateField**:七部件与独立组导出,复用 choice/field;接入 ConfigProvider locale/dir;对 defaultPlaceholder/SSR 时区、受控 null/undefined、不可用日期、原生约束、粘贴/IME、粒度动态切换逐项验证,完成全部 16 例及 granularity 例内 Select/Tooltip 组合。
|
||||
2. **Calendar + YearPicker**:先确定 Cell 导航取消/ARIA 适配,再实现月视图、多选、焦点/翻页、week/day view、YearPicker、国际历法及 19 例。不是用普通月表替换所有布局。范围与日期选择弹层沿用同一接受值/字段/overlay 边界。
|
||||
3. **Range/Picker/Time** 后续独立批次:未做探针的能力不能从同名导出推断;状态与唯一提交层由集成人维护,适合外包的展示/文档任务再按实际完成度派发。
|
||||
|
||||
没有日期公共浏览器验收、自动逐像素、完整读屏/触屏、Nuxt 或日期产物安装结论。Select 本轮的浏览器结果只属于 Select,不能挪作日期家族验收。
|
||||
|
||||
## DATE-02 接续更新
|
||||
|
||||
本轮公共 DateField/DateInputGroup 已实现,基线正文实际包含 render-function 共 **17** 例,早期 16 例计数更正。新增空值接受协议探针:完整空值提案被拒绝时要清空底座 segmentValues;仅刷新 null 副本不会触发 watch。使用公开注入上下文的局部适配,保持 DOM/焦点不变,见 [DATE-02](../migrations/DATE-02-date-field.md)。该报告和 verification.md 替代本文件此前“没有公开组件验收”的阶段状态。
|
||||
|
||||
用户要求暂停后续日期组件;先做文档整体结构/布局/公共组件对齐。Calendar/YearPicker 仍只是底座探针。
|
||||
@@ -282,3 +282,11 @@ ListBox 已完成公共首轮实现,见 [报告](migrations/LISTBOX-01-list-bo
|
||||
## SELECT-01 接续与复核要点
|
||||
|
||||
Select 已接入六部件和十九例,见 [报告](migrations/SELECT-01-select.md)。后续集合/日期选择字段复用 CollectionOwner / ListBox、choice/Form 与 overlay,不复制状态或焦点栈。通用弹层 role/ARIA 默认覆盖、非模态 Tab 仍循环、受控 reset 后原生 DOM 不回写、SSR 关闭态缺少元数据、空字符串布尔属性及动态删除留下幽灵提交是本轮重点回归。其他 AI 不自行修改这些共享协议。真实浏览器受 URL 策略阻断,仍待补验,不能把已通过的自动化检查当作最终视觉或交互验收。
|
||||
|
||||
## DATE-01 日期基建分工
|
||||
|
||||
集成人已开始[日期基建](decisions/date-calendar-foundation.md),尚未导出公开日期组件。其他 AI 的 Toast/Table 任务不依赖这些私有模块;不要修改 date/value/model 或另建日期表单协议。DateInputGroup 与 DateField、Calendar 与 YearPicker 先由集成人纵向验证,公开演示与可派发范围以后续交付为准。
|
||||
|
||||
## 当前用户调整
|
||||
|
||||
DateField 七部件与 DateInputGroup 六部件、17 例已落地,范围和差异见 [DATE-02](migrations/DATE-02-date-field.md)。历史“未公开”的文字是审计阶段记录。集成人完成本轮后暂停 Calendar,优先对齐文档站结构、布局和公共控件,消费已有库组件;暂缺组件保留现状。其他 AI 的 Toast/Table 与这个壳层任务分别保持任务分支和 checkout。
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
# DATE-02 DateField / DateInputGroup
|
||||
|
||||
固定来源:HeroUI 3.2.6,ce90ea3ab49d58f6c428f71bfd6fe8ae2a87b960;React date-field/date-input-group、两个同名 CSS/variants、中文正文和 **17** 个演示(包括 render-function)。Apache-2.0 归属保留在 third-party/HEROUI-LICENSE。
|
||||
|
||||
## 实现
|
||||
|
||||
DateField 七部件及独立 DateInputGroup 六部件共享分段模型和样式。采用已安装 Reka 2.11.0 日期交互与 @internationalized/date 3.12.4,复用 choice/field、Form、Fieldset、ConfigProvider 和 reset 设施。样式数值、状态、变体和中文例顺序来自基线,图标用 Tabler Vue。
|
||||
|
||||
接受值与编辑草稿分离:显式 undefined/null 是受控空值;非空拒绝用副本恢复,空值完成提案被拒绝时通过公开 injectDateFieldRootContext 的 segmentValues 引用清空草稿,不替换 DOM 或焦点。未完成草稿保留,reset 则恢复捕获的初值或父接受值。底座升级需回归这一适配。
|
||||
|
||||
唯一命名表单输入提交完整 ISO toString,底座截断 datetime-local 不再带 name/required。视觉隐藏 ISO 文本输入支持 autoComplete 透传与 ISO input 更新;分段显示粒度不截断秒、毫秒和 zone。字段约束通过既有无名代理承载,错误关联与标签使用共享协议。视图转换为 locale 日历,事件转回模型原始日历。
|
||||
|
||||
## 验证与实际差异
|
||||
|
||||
- 私有探针/模型与值协议、公共 DOM/键盘/FormData/reset/受控拒绝/约束/locale/粒度/IME composing、真正 Node SSR、jsdom 水合、17 个同源演示挂载及受控按钮行为分别验收。最终全量结果见 verification.md。
|
||||
- 5174 实际浏览器:空字段月/日/年逐段 ArrowUp,ISO 同步;受控设为今天/清空;Select 切到秒并保留 America/Los_Angeles,显示 PST;浅/深色、错误样式与分隔符;示例高亮 369 个样式 span;API 表格无横溢出。没有逐像素或完整读屏/触屏结论。
|
||||
- 安装版 Reka Root 忽略 asChild,公共 as/class/element 归属本库内层容器,外层保留无视觉包装。段位数字/增减默认行为可用 preventDefault 取消;底座祖先左右导航忽略取消,阻止导航需要 Segment 的 .stop.prevent。此差异不能写成完整原生取消兼容。
|
||||
- 本地化整日期粘贴尚无解析器。非公历 13 月/era 的完整编辑受到底座限制;目前验证的模型/显示日历转换不代表所有历法键盘编辑已完成。
|
||||
- autoComplete 透传和 ISO 输入已验,不宣称每个浏览器提供日期补全建议。默认空占位采用本地今天,跨时区 SSR 传明确 placeholderValue/初始值固定首屏。
|
||||
- Render 函数改为 Vue as/作用域插槽;DateValue 用 shallowRef 存储以保留 TypeScript 私有品牌;Time 不属于 DateValue。
|
||||
|
||||
用户要求此组件完成后暂停:**不继续 Calendar/YearPicker**。下一任务改为文档站整体结构、布局和公共控件对齐,优先使用已经迁移的 HeroUI Vue 组件;缺少的组件保留现有实现。
|
||||
@@ -180,3 +180,11 @@ M18–M20 的标签桥接在 Vue 使用 indicator 注册表与 SSR 直接/原生
|
||||
## SELECT-01(2026-10-23)
|
||||
|
||||
固定 ce90ea3 的 `packages/react/src/components/select/select.tsx`、`packages/styles/components/select.css`、`packages/styles/src/components/select/select.styles.ts`、`icons.tsx` 的 ChevronDown/Close,以及中文 `(pickers)/select.mdx` 和十九个 `demos/cn/select` 预览。CSS/tv/默认图形沿用 Apache-2.0 声明并加 hv- 前缀,方向/宽度/原点适配 Reka 实际状态。Vue 使用现有 ListBox + Popover + 字段协议;异步 React Stately/Collection 改 Fetch + VueUse(文档包显式声明既有 14.4.0),保留数据接口、分页与错误/取消体验。差异与待验收范围见 [SELECT-01](migrations/SELECT-01-select.md)。
|
||||
|
||||
## DATE-01 日期能力审计(2026-10-23)
|
||||
|
||||
固定 ce90ea3 的 date-field / date-input-group / calendar / calendar-year-picker 源码、中文正文和 16/19 预览作为公共实施清单。本轮没有移植日期 CSS 或预览;私有日期值/接受值协议是本库实现,底座夹具使用实际 Reka 2.11.0。组件与测试显式使用 @internationalized/date 3.12.4(Apache-2.0)并保持 external;不读取相邻仓库运行依赖。真实差异与限制见[日期基建决策](decisions/date-calendar-foundation.md)。
|
||||
|
||||
## DATE-02 来源与适配
|
||||
|
||||
移植 ce90ea3 date-field/date-input-group 的 React 部件、CSS、variants、中文正文与全部 17 预览。样式仅加 hv- 前缀及 Vue 状态适配;公开行为与底座差异、原生 ISO 提交、空值拒绝恢复详见 [DATE-02](migrations/DATE-02-date-field.md)。日期库 3.12.4 显式 dependency/external,不依赖上游源码。
|
||||
|
||||
@@ -739,3 +739,11 @@ typecheck、build:docs、build:playground、format、diff-check 与 dist 正反
|
||||
本次定位后焦点修复最终 `pnpm test`:46 文件 / 687 项通过,typecheck 和 build:docs 通过;Prettier/diff 与独立消费回归继续验证。
|
||||
|
||||
与远程 main 的 M33–M34 集成后,完整测试 51 文件 / 720 项通过,typecheck、build:docs 通过。导出/样式/脚本/报告均保留双方增量;Select 文档移除 MDX 专用 [!toc] 标记。
|
||||
|
||||
## DATE-01/02 日期基建与 DateField(2026-10-23)
|
||||
|
||||
- `pnpm test`:**58 文件 / 783 项通过**;typecheck、build:docs、全仓 Prettier 与 git diff --check 通过。文档构建仍有既存 500kB chunk 提示。
|
||||
- DateField 七部件 / DateInputGroup 六部件、17 基线预览、公共约束/受控/空值拒绝/原生提交/reset/动态粒度/locale/IME composing、真正 Node SSR 与实际 jsdom 水合分别验证;详细范围与未完成能力见 [DATE-02](migrations/DATE-02-date-field.md)。
|
||||
- 5174 浏览器重点验证逐段输入、真实 ISO 值、设为今天/清空、秒粒度 + America/Los_Angeles/PST、深浅色、错误样式、代码高亮与 API 表格无横溢出。截图 `/private/tmp/heroui-date-field-review.png`。未做自动逐像素、完整读屏、触屏及全部历法编辑验收。
|
||||
- 两份 tarball 安装至独立 `/private/tmp/heroui-slider-consumer`,DateField ESM/Node SSR/CSS 及 NodeNext/bundler 严格正反类型通过。初次消费发现 Props 未从主入口转出,已补齐并重打包复验;错误值/粒度/变体/范围/segment 反例均实际触发诊断。Select/ListBox/M33–M34 产物消费与 NodeNext 契约回归通过。
|
||||
- Date foundation 中 Calendar 仍仅为私有探针,不能据此标记公共 Calendar 完成。按用户要求暂停 Calendar/YearPicker,接下来先调整文档壳层。
|
||||
|
||||
+5
-4
@@ -15,13 +15,15 @@
|
||||
"build:docs": "pnpm build && pnpm --filter @heroui-vue/docs build",
|
||||
"typecheck": "vue-tsc --noEmit",
|
||||
"test": "vitest run",
|
||||
"test:unit": "vitest run tests/choice-demos.test.ts tests/choice-fields.test.ts tests/fieldset-search-field.test.ts tests/components.test.ts tests/composition.test.ts tests/docs-search.test.ts tests/button-demos.test.ts tests/aligned-components.test.ts tests/surface-link-spinner.test.ts tests/close-button-avatar-skeleton.test.ts tests/separator-kbd-chip.test.ts tests/badge-alert.test.ts tests/input-group.test.ts tests/field-docs-textarea.test.ts tests/field-foundation.test.ts tests/typography-empty-breadcrumbs.test.ts tests/progress-meter.test.ts tests/disclosure-accordion.test.ts tests/overlay-foundation.test.ts tests/modal.test.ts tests/popover-tooltip.test.ts tests/overlay-demos.test.ts tests/scroll-tabs.test.ts tests/button-toggle.test.ts tests/m26-review.probe.test.ts tests/toolbar.test.ts tests/m29-review.probe.test.ts tests/m30-m32-review.probe.test.ts tests/pagination.test.ts tests/header.test.ts tests/input-otp.test.ts tests/number-field-foundation.test.ts tests/number-field.test.ts tests/slider-foundation.test.ts tests/slider.test.ts tests/collection-state.test.ts tests/collection-foundation.test.ts tests/list-box.test.ts tests/alert-dialog.test.ts tests/drawer.test.ts tests/m33-m34-review.probe.test.ts tests/m33-m34-lifecycle-review.probe.test.ts tests/m33-m34-coexist.test.ts tests/select.test.ts",
|
||||
"test:ssr": "vitest run tests/ssr.test.ts tests/input-otp-ssr.test.ts tests/slider-foundation-ssr.test.ts tests/slider-ssr.test.ts tests/collection-foundation-ssr.test.ts tests/list-box-ssr.test.ts tests/select-ssr.test.ts",
|
||||
"test:unit": "vitest run tests/choice-demos.test.ts tests/choice-fields.test.ts tests/fieldset-search-field.test.ts tests/components.test.ts tests/composition.test.ts tests/docs-search.test.ts tests/button-demos.test.ts tests/aligned-components.test.ts tests/surface-link-spinner.test.ts tests/close-button-avatar-skeleton.test.ts tests/separator-kbd-chip.test.ts tests/badge-alert.test.ts tests/input-group.test.ts tests/field-docs-textarea.test.ts tests/field-foundation.test.ts tests/typography-empty-breadcrumbs.test.ts tests/progress-meter.test.ts tests/disclosure-accordion.test.ts tests/overlay-foundation.test.ts tests/modal.test.ts tests/popover-tooltip.test.ts tests/overlay-demos.test.ts tests/scroll-tabs.test.ts tests/button-toggle.test.ts tests/m26-review.probe.test.ts tests/toolbar.test.ts tests/m29-review.probe.test.ts tests/m30-m32-review.probe.test.ts tests/pagination.test.ts tests/header.test.ts tests/input-otp.test.ts tests/number-field-foundation.test.ts tests/number-field.test.ts tests/slider-foundation.test.ts tests/slider.test.ts tests/collection-state.test.ts tests/collection-foundation.test.ts tests/list-box.test.ts tests/alert-dialog.test.ts tests/drawer.test.ts tests/m33-m34-review.probe.test.ts tests/m33-m34-lifecycle-review.probe.test.ts tests/m33-m34-coexist.test.ts tests/select.test.ts tests/date-value.test.ts tests/date-model.test.ts tests/date-foundation.test.ts tests/date-field.test.ts tests/date-field-demos.test.ts",
|
||||
"test:ssr": "vitest run tests/ssr.test.ts tests/input-otp-ssr.test.ts tests/slider-foundation-ssr.test.ts tests/slider-ssr.test.ts tests/collection-foundation-ssr.test.ts tests/list-box-ssr.test.ts tests/select-ssr.test.ts tests/date-foundation-ssr.test.ts tests/date-field-ssr.test.ts",
|
||||
"format": "prettier --check .",
|
||||
"format:fix": "prettier --write .",
|
||||
"dev:playground": "pnpm build && pnpm --filter @heroui-vue/playground dev"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@internationalized/date": "3.12.4",
|
||||
"@types/node": "^22.0.0",
|
||||
"@vitejs/plugin-vue": "^6.0.0",
|
||||
"@vue/server-renderer": "^3.5.44",
|
||||
"@vue/test-utils": "^2.4.6",
|
||||
@@ -32,7 +34,6 @@
|
||||
"vite-plugin-dts": "^4.5.4",
|
||||
"vitest": "^3.2.4",
|
||||
"vue": "^3.5.44",
|
||||
"vue-tsc": "^3.1.0",
|
||||
"@types/node": "^22.0.0"
|
||||
"vue-tsc": "^3.1.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
/* Adapted from HeroUI ce90ea3, Apache-2.0; hv- prefix. */
|
||||
/* Date field styles */
|
||||
.hv-date-field {
|
||||
@apply flex flex-col gap-1;
|
||||
|
||||
&[data-invalid="true"],
|
||||
&[aria-invalid="true"] {
|
||||
[data-slot="description"] {
|
||||
@apply hidden;
|
||||
}
|
||||
}
|
||||
|
||||
[data-slot="label"] {
|
||||
@apply w-fit;
|
||||
}
|
||||
}
|
||||
|
||||
/* Full width modifier */
|
||||
.hv-date-field--full-width {
|
||||
@apply w-full;
|
||||
}
|
||||
@@ -0,0 +1,183 @@
|
||||
/* Adapted from HeroUI ce90ea3, Apache-2.0; hv- prefix. */
|
||||
/* Date input group styles */
|
||||
.hv-date-input-group {
|
||||
@apply inline-flex h-9 items-center overflow-hidden rounded-field border bg-field text-sm text-field-foreground shadow-field outline-none;
|
||||
border-width: var(--border-width-field);
|
||||
border-color: var(--field-border);
|
||||
|
||||
/**
|
||||
* Transitions
|
||||
* CRITICAL: motion-reduce must be AFTER transition for correct override specificity
|
||||
*/
|
||||
transition:
|
||||
background-color 150ms var(--ease-smooth),
|
||||
border-color 150ms var(--ease-smooth),
|
||||
box-shadow 150ms var(--ease-out);
|
||||
@apply motion-reduce:transition-none;
|
||||
|
||||
/* Hover state */
|
||||
@media (hover: hover) {
|
||||
&:hover:not(:focus-within),
|
||||
&[data-hovered="true"]:not([data-focus-within="true"]) {
|
||||
@apply bg-field-hover;
|
||||
border-color: var(--field-border-hover);
|
||||
}
|
||||
}
|
||||
|
||||
/* Focus within state */
|
||||
&[data-focus-within="true"]:not(
|
||||
:has(
|
||||
[data-slot="date-picker-trigger"]:focus,
|
||||
[data-slot="date-picker-trigger"][data-focused="true"],
|
||||
[data-slot="date-range-picker-trigger"]:focus,
|
||||
[data-slot="date-range-picker-trigger"][data-focused="true"]
|
||||
)
|
||||
),
|
||||
&:focus-within:not(
|
||||
:has(
|
||||
[data-slot="date-picker-trigger"]:focus,
|
||||
[data-slot="date-picker-trigger"][data-focused="true"],
|
||||
[data-slot="date-range-picker-trigger"]:focus,
|
||||
[data-slot="date-range-picker-trigger"][data-focused="true"]
|
||||
)
|
||||
) {
|
||||
@apply status-focused-field;
|
||||
}
|
||||
|
||||
/* Invalid state */
|
||||
&[data-invalid="true"] {
|
||||
@apply status-invalid-field;
|
||||
background-color: var(--field-focus);
|
||||
border-color: var(--color-field-border-invalid);
|
||||
}
|
||||
|
||||
/* Disabled state */
|
||||
&[data-disabled="true"],
|
||||
&[aria-disabled="true"] {
|
||||
@apply status-disabled;
|
||||
}
|
||||
}
|
||||
|
||||
.hv-date-input-group__input {
|
||||
@apply flex flex-1 cursor-text items-center gap-px rounded-none border-0 bg-transparent px-3 py-2 text-base shadow-none outline-none sm:text-sm;
|
||||
|
||||
/* Remove border radius on left side when prefix is present */
|
||||
.hv-date-input-group:has([data-slot="date-input-group-prefix"]) & {
|
||||
@apply rounded-s-none ps-2;
|
||||
}
|
||||
|
||||
/* Remove border radius on right side when suffix is present */
|
||||
.hv-date-input-group:has([data-slot="date-input-group-suffix"]) & {
|
||||
@apply rounded-e-none pe-2;
|
||||
}
|
||||
|
||||
.hv-date-input-group:has(.hv-date-range-picker__range-separator) & {
|
||||
&[slot="start"] {
|
||||
@apply flex-none pe-0;
|
||||
}
|
||||
&[slot="end"] {
|
||||
@apply ps-0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Focus state - handled by group */
|
||||
&:focus,
|
||||
&:focus-visible {
|
||||
@apply outline-none;
|
||||
}
|
||||
}
|
||||
|
||||
.hv-date-input-group__input-container {
|
||||
@apply flex flex-1 scrollbar-none items-center;
|
||||
width: fit-content;
|
||||
overflow-x: auto;
|
||||
overflow-y: clip;
|
||||
}
|
||||
|
||||
.hv-date-input-group__segment {
|
||||
@apply inline-block rounded-md px-0.5 text-end text-nowrap outline-none;
|
||||
|
||||
/* Segment separators styling "/" */
|
||||
&[data-type="literal"] {
|
||||
@apply p-0 text-muted;
|
||||
}
|
||||
|
||||
/* Placeholder styling */
|
||||
&[data-placeholder="true"] {
|
||||
@apply text-field-placeholder;
|
||||
}
|
||||
|
||||
/* Focused segment */
|
||||
&:focus,
|
||||
&[data-focused="true"] {
|
||||
@apply bg-accent-soft text-accent-soft-foreground;
|
||||
}
|
||||
|
||||
/* Disabled segment */
|
||||
&[data-disabled="true"] {
|
||||
@apply opacity-50;
|
||||
}
|
||||
|
||||
/* Invalid segment */
|
||||
&[data-invalid="true"] {
|
||||
@apply text-danger;
|
||||
|
||||
/* Focused segment */
|
||||
&:focus,
|
||||
&[data-focused="true"] {
|
||||
@apply bg-danger-soft text-danger-soft-foreground;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.hv-date-input-group__prefix {
|
||||
@apply pointer-events-none shrink-0 text-field-placeholder;
|
||||
@apply ms-3 me-0 flex items-center;
|
||||
}
|
||||
|
||||
.hv-date-input-group__suffix {
|
||||
@apply pointer-events-none shrink-0 text-field-placeholder;
|
||||
@apply me-3 flex items-center;
|
||||
}
|
||||
|
||||
/* Variant property definitions */
|
||||
.hv-date-input-group--primary {
|
||||
/* Default styles */
|
||||
}
|
||||
|
||||
.hv-date-input-group--secondary {
|
||||
@apply shadow-none;
|
||||
background-color: var(--date-input-group-bg);
|
||||
|
||||
--date-input-group-bg: var(--default);
|
||||
--date-input-group-bg-hover: var(--default-hover);
|
||||
--date-input-group-bg-focus: var(--default);
|
||||
|
||||
@media (hover: hover) {
|
||||
&:hover:not(:focus-within),
|
||||
&[data-hovered="true"]:not([data-focus-within="true"]) {
|
||||
background-color: var(--date-input-group-bg-hover);
|
||||
}
|
||||
}
|
||||
|
||||
&:focus-within,
|
||||
&[data-focus-within="true"] {
|
||||
background-color: var(--date-input-group-bg-focus);
|
||||
}
|
||||
|
||||
/* Invalid state */
|
||||
&[data-invalid="true"] {
|
||||
@apply status-invalid-field;
|
||||
border-color: var(--color-field-border-invalid);
|
||||
background-color: var(--date-input-group-bg-focus);
|
||||
}
|
||||
|
||||
[data-slot="date-input-group-input"] {
|
||||
@apply bg-transparent;
|
||||
}
|
||||
}
|
||||
|
||||
/* Full width modifier */
|
||||
.hv-date-input-group--full-width {
|
||||
@apply w-full;
|
||||
}
|
||||
@@ -149,3 +149,6 @@
|
||||
@import "./components/list-box-section.css" layer(components);
|
||||
|
||||
@import "./components/select.css" layer(components);
|
||||
|
||||
@import "./components/date-input-group.css" layer(components);
|
||||
@import "./components/date-field.css" layer(components);
|
||||
|
||||
@@ -1453,3 +1453,31 @@ export const selectVariants = tv({
|
||||
});
|
||||
|
||||
export type SelectVariants = VariantProps<typeof selectVariants>;
|
||||
|
||||
export const dateFieldVariants = tv({
|
||||
base: "hv-date-field",
|
||||
defaultVariants: { fullWidth: false },
|
||||
variants: { fullWidth: { true: "hv-date-field--full-width", false: "" } },
|
||||
});
|
||||
export type DateFieldVariants = VariantProps<typeof dateFieldVariants>;
|
||||
export const dateInputGroupVariants = tv({
|
||||
slots: {
|
||||
base: "hv-date-input-group",
|
||||
input: "hv-date-input-group__input",
|
||||
inputContainer: "hv-date-input-group__input-container",
|
||||
segment: "hv-date-input-group__segment",
|
||||
prefix: "hv-date-input-group__prefix",
|
||||
suffix: "hv-date-input-group__suffix",
|
||||
},
|
||||
defaultVariants: { fullWidth: false, variant: "primary" },
|
||||
variants: {
|
||||
fullWidth: { true: { base: "hv-date-input-group--full-width" }, false: {} },
|
||||
variant: {
|
||||
primary: { base: "hv-date-input-group--primary" },
|
||||
secondary: { base: "hv-date-input-group--secondary" },
|
||||
},
|
||||
},
|
||||
});
|
||||
export type DateInputGroupVariants = VariantProps<
|
||||
typeof dateInputGroupVariants
|
||||
>;
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@heroui-vue/styles": "workspace:*",
|
||||
"@internationalized/date": "3.12.4",
|
||||
"@vueuse/core": "14.4.0",
|
||||
"reka-ui": "^2.11.0"
|
||||
},
|
||||
|
||||
@@ -0,0 +1,383 @@
|
||||
<script lang="ts">
|
||||
import {
|
||||
computed,
|
||||
defineComponent,
|
||||
getCurrentInstance,
|
||||
h,
|
||||
mergeProps,
|
||||
nextTick,
|
||||
onMounted,
|
||||
provide,
|
||||
ref,
|
||||
shallowRef,
|
||||
watch,
|
||||
watchEffect,
|
||||
type PropType,
|
||||
type SlotsType,
|
||||
type VNodeChild,
|
||||
} from "vue";
|
||||
import { DateFieldRoot } from "reka-ui";
|
||||
import {
|
||||
getLocalTimeZone,
|
||||
today,
|
||||
parseDate,
|
||||
parseDateTime,
|
||||
parseZonedDateTime,
|
||||
toCalendar,
|
||||
toCalendarDateTime,
|
||||
type DateValue,
|
||||
} from "@internationalized/date";
|
||||
import { dateFieldVariants } from "@heroui-vue/styles";
|
||||
import { useConfig } from "../../providers/context";
|
||||
import { useAcceptedDateValue } from "../date/model";
|
||||
import { dateForLocale, serializeDateValue } from "../date/value";
|
||||
import EmptyDateBridge from "../date/EmptyDateBridge";
|
||||
import {
|
||||
useChoiceField,
|
||||
useChoiceForm,
|
||||
validationInput,
|
||||
} from "../choice/shared";
|
||||
import { disabledContextKey } from "../field/disabled";
|
||||
import type { ValidationBehavior, ValidateResult } from "../field/context";
|
||||
import { dateFieldKey, type DateSegment } from "./context";
|
||||
import PrimitiveNode from "./PrimitiveNode";
|
||||
import DateSegments from "./DateSegments";
|
||||
export default defineComponent({
|
||||
name: "DateField",
|
||||
inheritAttrs: false,
|
||||
slots: Object as SlotsType<{
|
||||
default?: (state: {
|
||||
value: DateValue | null;
|
||||
isDisabled: boolean;
|
||||
isReadOnly: boolean;
|
||||
isRequired: boolean;
|
||||
isInvalid: boolean;
|
||||
isFocusWithin: boolean;
|
||||
isFocused: boolean;
|
||||
isFocusVisible: boolean;
|
||||
validationErrors: string[];
|
||||
}) => VNodeChild;
|
||||
}>,
|
||||
props: {
|
||||
modelValue: {
|
||||
type: [Object, null] as PropType<DateValue | null>,
|
||||
default: undefined,
|
||||
},
|
||||
value: {
|
||||
type: [Object, null] as PropType<DateValue | null>,
|
||||
default: undefined,
|
||||
},
|
||||
defaultValue: [Object, null] as PropType<DateValue | null>,
|
||||
placeholderValue: [Object, null] as PropType<DateValue | null>,
|
||||
minValue: [Object, null] as PropType<DateValue | null>,
|
||||
maxValue: [Object, null] as PropType<DateValue | null>,
|
||||
isDateUnavailable: Function as PropType<(value: DateValue) => boolean>,
|
||||
granularity: String as PropType<"day" | "hour" | "minute" | "second">,
|
||||
hourCycle: Number as PropType<12 | 24>,
|
||||
hideTimeZone: Boolean,
|
||||
shouldForceLeadingZeros: { type: Boolean, default: undefined },
|
||||
locale: String,
|
||||
dir: String as PropType<"ltr" | "rtl">,
|
||||
fullWidth: Boolean,
|
||||
as: { type: String, default: "div" },
|
||||
id: String,
|
||||
name: String,
|
||||
form: String,
|
||||
isDisabled: Boolean,
|
||||
disabled: Boolean,
|
||||
isReadOnly: Boolean,
|
||||
isRequired: Boolean,
|
||||
isInvalid: Boolean,
|
||||
autoFocus: Boolean,
|
||||
autoComplete: String,
|
||||
validationBehavior: String as PropType<ValidationBehavior>,
|
||||
validate: Function as PropType<(value: DateValue | null) => ValidateResult>,
|
||||
},
|
||||
emits: {
|
||||
"update:modelValue": (_value: DateValue | null) => true,
|
||||
change: (_value: DateValue | null) => true,
|
||||
},
|
||||
setup(props, { attrs, slots, emit, expose }) {
|
||||
const config = useConfig();
|
||||
const instance = getCurrentInstance()!;
|
||||
const accepted = useAcceptedDateValue({
|
||||
value: () =>
|
||||
["modelValue", "model-value"].some((key) =>
|
||||
Object.hasOwn(instance.vnode.props ?? {}, key),
|
||||
)
|
||||
? props.modelValue
|
||||
: props.value,
|
||||
defaultValue: () => props.defaultValue,
|
||||
onChange: (value) => {
|
||||
field.edit();
|
||||
emit("update:modelValue", value);
|
||||
emit("change", value);
|
||||
},
|
||||
disabled: () => field.field.disabled.value,
|
||||
readOnly: () => field.field.readOnly.value,
|
||||
});
|
||||
const field = useChoiceField(props, attrs, {
|
||||
kind: "group",
|
||||
value: accepted.value,
|
||||
satisfied: () => accepted.value.value !== null,
|
||||
requiredMessage: "请填写此字段。",
|
||||
validate: (value) => {
|
||||
if (value && props.minValue && value.compare(props.minValue) < 0)
|
||||
return "日期不能早于最早日期。";
|
||||
if (value && props.maxValue && value.compare(props.maxValue) > 0)
|
||||
return "日期不能晚于最晚日期。";
|
||||
if (value && props.isDateUnavailable?.(value)) return "此日期不可用。";
|
||||
return props.validate?.(value);
|
||||
},
|
||||
});
|
||||
provide(disabledContextKey, field.field.disabled);
|
||||
provide(dateFieldKey, {
|
||||
value: accepted.value,
|
||||
disabled: field.field.disabled,
|
||||
readOnly: field.field.readOnly,
|
||||
required: field.field.required,
|
||||
invalid: field.field.invalid,
|
||||
leadingZeros: () => props.shouldForceLeadingZeros,
|
||||
labelledBy: field.labelledBy,
|
||||
describedBy: field.describedBy,
|
||||
ariaLabel: () => attrs["aria-label"],
|
||||
});
|
||||
const locale = computed(
|
||||
() => props.locale ?? config?.locale.value ?? "en-US",
|
||||
);
|
||||
// Capture a real local date only as the empty edit placeholder. DateValue
|
||||
// models never pass through JS Date or acquire the machine's time zone.
|
||||
const initialPlaceholder = (
|
||||
props.placeholderValue ??
|
||||
props.defaultValue ??
|
||||
accepted.value.value ??
|
||||
today(getLocalTimeZone())
|
||||
).copy();
|
||||
const lastPlaceholder = shallowRef(initialPlaceholder);
|
||||
watch(accepted.value, (value) => {
|
||||
if (value) lastPlaceholder.value = value.copy();
|
||||
});
|
||||
const placeholder = computed(() => {
|
||||
let value = dateForLocale(
|
||||
props.placeholderValue ?? accepted.value.value ?? lastPlaceholder.value,
|
||||
locale.value,
|
||||
);
|
||||
if (
|
||||
props.granularity &&
|
||||
props.granularity !== "day" &&
|
||||
!("hour" in value)
|
||||
)
|
||||
value = toCalendarDateTime(value);
|
||||
return value;
|
||||
});
|
||||
const wire = computed(() =>
|
||||
accepted.wire.value
|
||||
? dateForLocale(accepted.wire.value, locale.value)
|
||||
: null,
|
||||
);
|
||||
const root = ref<HTMLElement>(),
|
||||
native = ref<HTMLInputElement>(),
|
||||
proxy = ref<HTMLInputElement>();
|
||||
const focused = ref(false);
|
||||
const focusVisible = ref(false);
|
||||
const focus = () =>
|
||||
root.value
|
||||
?.querySelector<HTMLElement>(
|
||||
'[data-slot="date-input-group-segment"][tabindex="0"]',
|
||||
)
|
||||
?.focus();
|
||||
function request(value: DateValue | undefined) {
|
||||
const calendar =
|
||||
accepted.value.value?.calendar ??
|
||||
props.defaultValue?.calendar ??
|
||||
props.placeholderValue?.calendar ??
|
||||
initialPlaceholder.calendar;
|
||||
accepted.request(value ? toCalendar(value, calendar) : null);
|
||||
}
|
||||
function restoreNative() {
|
||||
if (native.value)
|
||||
native.value.value = serializeDateValue(accepted.value.value);
|
||||
}
|
||||
useChoiceForm(
|
||||
proxy,
|
||||
() => {
|
||||
accepted.reset();
|
||||
field.reset();
|
||||
},
|
||||
restoreNative,
|
||||
);
|
||||
watchEffect(() => field.validity(proxy.value), { flush: "post" });
|
||||
const signature = computed(
|
||||
() =>
|
||||
`${props.granularity ?? "auto"}|${props.hourCycle ?? "auto"}|${placeholder.value.calendar.identifier}|${"hour" in placeholder.value}`,
|
||||
);
|
||||
watch(signature, () => {
|
||||
const old = root.value?.ownerDocument.activeElement as HTMLElement | null;
|
||||
const part =
|
||||
old && root.value?.contains(old)
|
||||
? old.dataset.rekaDateFieldSegment
|
||||
: undefined;
|
||||
if (part)
|
||||
void nextTick(() => {
|
||||
const current = root.value?.ownerDocument.activeElement;
|
||||
if (current === old || current === root.value?.ownerDocument.body)
|
||||
root.value
|
||||
?.querySelector<HTMLElement>(
|
||||
`[data-reka-date-field-segment="${part}"]`,
|
||||
)
|
||||
?.focus();
|
||||
});
|
||||
});
|
||||
onMounted(() => {
|
||||
if (props.autoFocus) focus();
|
||||
});
|
||||
expose({ element: root, focus });
|
||||
return () => {
|
||||
const state = {
|
||||
value: accepted.value.value,
|
||||
isDisabled: field.field.disabled.value,
|
||||
isReadOnly: field.field.readOnly.value,
|
||||
isRequired: field.field.required.value,
|
||||
isInvalid: field.field.invalid.value,
|
||||
isFocusWithin: focused.value,
|
||||
isFocused: focused.value,
|
||||
isFocusVisible: focusVisible.value,
|
||||
validationErrors: field.field.errors.value,
|
||||
};
|
||||
const raw = slots.default?.(state);
|
||||
const children = field.prepare(
|
||||
Array.isArray(raw) ? raw : raw ? [raw] : [],
|
||||
true,
|
||||
);
|
||||
const overrides = {
|
||||
id: field.field.controlId.value,
|
||||
role: "group",
|
||||
class: dateFieldVariants({ fullWidth: props.fullWidth }),
|
||||
"data-slot": "date-field",
|
||||
"data-disabled": state.isDisabled || undefined,
|
||||
"data-readonly": state.isReadOnly || undefined,
|
||||
"data-invalid": state.isInvalid || undefined,
|
||||
"data-required": state.isRequired || undefined,
|
||||
"data-focus-within": focused.value || undefined,
|
||||
"aria-label": attrs["aria-label"],
|
||||
"aria-labelledby": field.labelledBy(),
|
||||
"aria-describedby": field.describedBy(),
|
||||
"aria-invalid": state.isInvalid || undefined,
|
||||
"aria-required": state.isRequired || undefined,
|
||||
ref: (element: unknown) => {
|
||||
root.value = element as HTMLElement;
|
||||
},
|
||||
onFocusin: (event: FocusEvent) => {
|
||||
focused.value = true;
|
||||
focusVisible.value = (event.target as HTMLElement).matches(
|
||||
":focus-visible",
|
||||
);
|
||||
},
|
||||
onFocusout: (event: FocusEvent) => {
|
||||
if (
|
||||
!(event.currentTarget as HTMLElement).contains(
|
||||
event.relatedTarget as Node | null,
|
||||
)
|
||||
) {
|
||||
focused.value = false;
|
||||
focusVisible.value = false;
|
||||
}
|
||||
},
|
||||
};
|
||||
return h(
|
||||
DateFieldRoot,
|
||||
{
|
||||
key: signature.value,
|
||||
asChild: true,
|
||||
modelValue: wire.value,
|
||||
placeholder: placeholder.value,
|
||||
granularity: props.granularity,
|
||||
hourCycle: props.hourCycle,
|
||||
hideTimeZone: props.hideTimeZone,
|
||||
locale: locale.value,
|
||||
dir: props.dir ?? config?.dir.value,
|
||||
disabled: state.isDisabled,
|
||||
readonly: state.isReadOnly,
|
||||
// The base is nameless and unconstrained: its native input truncates
|
||||
// time and cannot represent zones or non-Gregorian values faithfully.
|
||||
"onUpdate:modelValue": request,
|
||||
},
|
||||
{
|
||||
default: ({
|
||||
segments,
|
||||
}: {
|
||||
segments: Pick<DateSegment, "part" | "value">[];
|
||||
}) =>
|
||||
h(
|
||||
PrimitiveNode,
|
||||
{ as: props.as, consumer: attrs, overrides },
|
||||
{
|
||||
default: () =>
|
||||
h(
|
||||
DateSegments,
|
||||
{ segments },
|
||||
{
|
||||
default: () => [
|
||||
...children,
|
||||
h(EmptyDateBridge, {
|
||||
revision: accepted.emptyRevision.value,
|
||||
}),
|
||||
h("input", {
|
||||
ref: native,
|
||||
type: "text",
|
||||
class: "hv-choice-input",
|
||||
tabindex: -1,
|
||||
"aria-hidden": "true",
|
||||
autoComplete: props.autoComplete ?? "off",
|
||||
readonly: state.isReadOnly,
|
||||
onFocus: focus,
|
||||
onInput: (event: Event) => {
|
||||
if (
|
||||
event.defaultPrevented ||
|
||||
state.isDisabled ||
|
||||
state.isReadOnly
|
||||
) {
|
||||
restoreNative();
|
||||
return;
|
||||
}
|
||||
const text = (event.target as HTMLInputElement)
|
||||
.value;
|
||||
try {
|
||||
request(
|
||||
!text
|
||||
? undefined
|
||||
: text.includes("[")
|
||||
? parseZonedDateTime(text)
|
||||
: text.includes("T")
|
||||
? parseDateTime(text)
|
||||
: parseDate(text),
|
||||
);
|
||||
} catch {
|
||||
restoreNative();
|
||||
}
|
||||
void nextTick(restoreNative);
|
||||
},
|
||||
name: props.name,
|
||||
form: props.form,
|
||||
value: serializeDateValue(accepted.value.value),
|
||||
disabled: state.isDisabled,
|
||||
"data-slot": "date-field-value",
|
||||
}),
|
||||
validationInput(
|
||||
proxy,
|
||||
props,
|
||||
state.isDisabled || state.isReadOnly,
|
||||
field.behavior.value,
|
||||
(event) => field.invalidEvent(event, focus),
|
||||
),
|
||||
],
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
},
|
||||
);
|
||||
};
|
||||
},
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,51 @@
|
||||
<script lang="ts">
|
||||
import {
|
||||
computed,
|
||||
defineComponent,
|
||||
h,
|
||||
inject,
|
||||
mergeProps,
|
||||
provide,
|
||||
type PropType,
|
||||
} from "vue";
|
||||
import { dateInputGroupVariants } from "@heroui-vue/styles";
|
||||
import { dateFieldKey, dateGroupKey } from "./context";
|
||||
export default defineComponent({
|
||||
name: "DateInputGroup",
|
||||
inheritAttrs: false,
|
||||
props: {
|
||||
variant: {
|
||||
type: String as PropType<"primary" | "secondary">,
|
||||
default: "primary",
|
||||
},
|
||||
fullWidth: Boolean,
|
||||
as: { type: String, default: "div" },
|
||||
},
|
||||
setup(props, { attrs, slots }) {
|
||||
const field = inject(dateFieldKey, undefined);
|
||||
const styles = computed(() =>
|
||||
dateInputGroupVariants({
|
||||
variant: props.variant,
|
||||
fullWidth: props.fullWidth,
|
||||
}),
|
||||
);
|
||||
provide(dateGroupKey, styles);
|
||||
return () =>
|
||||
h(
|
||||
props.as,
|
||||
mergeProps(attrs, {
|
||||
class: styles.value.base(),
|
||||
"data-slot": "date-input-group",
|
||||
"data-invalid": field?.invalid.value || undefined,
|
||||
"aria-invalid": field?.invalid.value || undefined,
|
||||
"data-disabled": field?.disabled.value || undefined,
|
||||
"aria-disabled": field?.disabled.value || undefined,
|
||||
}),
|
||||
slots.default?.({
|
||||
isDisabled: !!field?.disabled.value,
|
||||
isInvalid: !!field?.invalid.value,
|
||||
}),
|
||||
);
|
||||
},
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,72 @@
|
||||
<script lang="ts">
|
||||
import {
|
||||
defineComponent,
|
||||
h,
|
||||
inject,
|
||||
mergeProps,
|
||||
type SlotsType,
|
||||
type VNodeChild,
|
||||
} from "vue";
|
||||
import { injectDateFieldRootContext } from "reka-ui";
|
||||
import { dateInputGroupVariants } from "@heroui-vue/styles";
|
||||
import {
|
||||
dateGroupKey,
|
||||
dateSegmentsKey,
|
||||
useDateField,
|
||||
type DateSegment,
|
||||
} from "./context";
|
||||
import DateInputGroupSegment from "./DateInputGroupSegment.vue";
|
||||
export default defineComponent({
|
||||
name: "DateInputGroupInput",
|
||||
inheritAttrs: false,
|
||||
props: { as: { type: String, default: "div" } },
|
||||
slots: Object as SlotsType<{
|
||||
default?: (props: { segment: DateSegment; index: number }) => VNodeChild;
|
||||
}>,
|
||||
setup(props, { attrs, slots }) {
|
||||
const field = useDateField();
|
||||
const base = injectDateFieldRootContext();
|
||||
const styles = inject(dateGroupKey, undefined);
|
||||
const segments = inject(dateSegmentsKey)!;
|
||||
return () =>
|
||||
h(
|
||||
props.as,
|
||||
mergeProps(attrs, {
|
||||
class: (styles?.value ?? dateInputGroupVariants()).input(),
|
||||
"data-slot": "date-input-group-input",
|
||||
}),
|
||||
segments.value.map((part, index) => {
|
||||
const isPlaceholder =
|
||||
part.part in base.segmentValues.value &&
|
||||
base.segmentValues.value[
|
||||
part.part as keyof typeof base.segmentValues.value
|
||||
] === null;
|
||||
let text = part.value;
|
||||
if (
|
||||
!isPlaceholder &&
|
||||
["month", "day", "hour", "minute", "second"].includes(part.part) &&
|
||||
/^\d+$/.test(text)
|
||||
) {
|
||||
if (field.leadingZeros() === true) text = text.padStart(2, "0");
|
||||
else if (field.leadingZeros() === false)
|
||||
text = String(Number(text));
|
||||
}
|
||||
const segment: DateSegment = {
|
||||
...part,
|
||||
type: part.part,
|
||||
text,
|
||||
value: text,
|
||||
isPlaceholder,
|
||||
isEditable: part.part !== "literal" && part.part !== "timeZoneName",
|
||||
};
|
||||
return h(
|
||||
"span",
|
||||
{ key: `${part.part}-${index}`, style: { display: "contents" } },
|
||||
slots.default?.({ segment, index }) ??
|
||||
h(DateInputGroupSegment, { segment }),
|
||||
);
|
||||
}),
|
||||
);
|
||||
},
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,22 @@
|
||||
<script lang="ts">
|
||||
import { defineComponent, h, inject, mergeProps } from "vue";
|
||||
import { dateInputGroupVariants } from "@heroui-vue/styles";
|
||||
import { dateGroupKey } from "./context";
|
||||
export default defineComponent({
|
||||
name: "DateInputGroupInputContainer",
|
||||
inheritAttrs: false,
|
||||
props: { as: { type: String, default: "div" } },
|
||||
setup(props, { attrs, slots }) {
|
||||
const styles = inject(dateGroupKey, undefined);
|
||||
return () =>
|
||||
h(
|
||||
props.as,
|
||||
mergeProps(attrs, {
|
||||
class: (styles?.value ?? dateInputGroupVariants()).inputContainer(),
|
||||
"data-slot": "date-input-group-input-container",
|
||||
}),
|
||||
slots.default?.(),
|
||||
);
|
||||
},
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,22 @@
|
||||
<script lang="ts">
|
||||
import { defineComponent, h, inject, mergeProps } from "vue";
|
||||
import { dateInputGroupVariants } from "@heroui-vue/styles";
|
||||
import { dateGroupKey } from "./context";
|
||||
export default defineComponent({
|
||||
name: "DateInputGroupPrefix",
|
||||
inheritAttrs: false,
|
||||
props: { as: { type: String, default: "div" } },
|
||||
setup(props, { attrs, slots }) {
|
||||
const styles = inject(dateGroupKey, undefined);
|
||||
return () =>
|
||||
h(
|
||||
props.as,
|
||||
mergeProps(attrs, {
|
||||
class: (styles?.value ?? dateInputGroupVariants()).prefix(),
|
||||
"data-slot": "date-input-group-prefix",
|
||||
}),
|
||||
slots.default?.(),
|
||||
);
|
||||
},
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,84 @@
|
||||
<script lang="ts">
|
||||
import { defineComponent, h, inject, type PropType } from "vue";
|
||||
import { DateFieldInput, injectDateFieldRootContext } from "reka-ui";
|
||||
import { dateInputGroupVariants } from "@heroui-vue/styles";
|
||||
import { dateGroupKey, useDateField, type DateSegment } from "./context";
|
||||
import PrimitiveNode from "./PrimitiveNode";
|
||||
import { mergeIds } from "../field/context";
|
||||
export default defineComponent({
|
||||
name: "DateInputGroupSegment",
|
||||
inheritAttrs: false,
|
||||
props: {
|
||||
segment: { type: Object as PropType<DateSegment>, required: true },
|
||||
as: { type: String, default: "span" },
|
||||
},
|
||||
setup(props, { attrs, slots, expose }) {
|
||||
const field = useDateField();
|
||||
const base = injectDateFieldRootContext();
|
||||
const styles = inject(dateGroupKey, undefined);
|
||||
let node: { element?: HTMLElement } | undefined;
|
||||
expose({
|
||||
get element() {
|
||||
return node?.element;
|
||||
},
|
||||
focus: () => node?.element?.focus(),
|
||||
});
|
||||
return () =>
|
||||
h(
|
||||
DateFieldInput,
|
||||
{ part: props.segment.part, asChild: true },
|
||||
{
|
||||
default: () =>
|
||||
h(
|
||||
PrimitiveNode,
|
||||
{
|
||||
ref: (value: unknown) => {
|
||||
node = value as typeof node;
|
||||
},
|
||||
as: props.as,
|
||||
consumer: attrs,
|
||||
overrides: {
|
||||
class: (styles?.value ?? dateInputGroupVariants()).segment(),
|
||||
"data-slot": "date-input-group-segment",
|
||||
"data-type": props.segment.type,
|
||||
"data-placeholder": props.segment.isPlaceholder || undefined,
|
||||
"data-disabled": field.disabled.value || undefined,
|
||||
"data-invalid": field.invalid.value || undefined,
|
||||
"aria-invalid": field.invalid.value || undefined,
|
||||
"aria-required": field.required.value || undefined,
|
||||
...(props.segment.part === "timeZoneName"
|
||||
? { "aria-readonly": true, contenteditable: false }
|
||||
: {}),
|
||||
"aria-describedby": mergeIds(
|
||||
field.describedBy(),
|
||||
attrs["aria-describedby"] as string | undefined,
|
||||
),
|
||||
"aria-labelledby": attrs["aria-labelledby"],
|
||||
...(props.segment.part !== "literal"
|
||||
? {
|
||||
"aria-label":
|
||||
attrs["aria-label"] ??
|
||||
new Intl.DisplayNames(base.locale.value, {
|
||||
type: "dateTimeField",
|
||||
}).of(props.segment.part),
|
||||
}
|
||||
: {}),
|
||||
...(props.segment.isPlaceholder
|
||||
? {
|
||||
"aria-valuenow": undefined,
|
||||
"aria-valuetext": props.segment.text,
|
||||
}
|
||||
: {}),
|
||||
},
|
||||
},
|
||||
{
|
||||
default: () =>
|
||||
slots.default?.({ segment: props.segment }) ??
|
||||
props.segment.text,
|
||||
},
|
||||
),
|
||||
},
|
||||
);
|
||||
},
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,22 @@
|
||||
<script lang="ts">
|
||||
import { defineComponent, h, inject, mergeProps } from "vue";
|
||||
import { dateInputGroupVariants } from "@heroui-vue/styles";
|
||||
import { dateGroupKey } from "./context";
|
||||
export default defineComponent({
|
||||
name: "DateInputGroupSuffix",
|
||||
inheritAttrs: false,
|
||||
props: { as: { type: String, default: "div" } },
|
||||
setup(props, { attrs, slots }) {
|
||||
const styles = inject(dateGroupKey, undefined);
|
||||
return () =>
|
||||
h(
|
||||
props.as,
|
||||
mergeProps(attrs, {
|
||||
class: (styles?.value ?? dateInputGroupVariants()).suffix(),
|
||||
"data-slot": "date-input-group-suffix",
|
||||
}),
|
||||
slots.default?.(),
|
||||
);
|
||||
},
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,20 @@
|
||||
import { computed, defineComponent, provide, type PropType } from "vue";
|
||||
import type { DateFieldInputProps } from "reka-ui";
|
||||
import { dateSegmentsKey } from "./context";
|
||||
export default defineComponent({
|
||||
props: {
|
||||
segments: {
|
||||
type: Array as PropType<
|
||||
{ part: DateFieldInputProps["part"]; value: string }[]
|
||||
>,
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
setup(props, { slots }) {
|
||||
provide(
|
||||
dateSegmentsKey,
|
||||
computed(() => props.segments),
|
||||
);
|
||||
return () => slots.default?.();
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,51 @@
|
||||
import { defineComponent, h, mergeProps, type PropType } from "vue";
|
||||
/** Keep consumer handlers at the real node and before Reka's defaults.
|
||||
* Reka date handlers don't themselves check defaultPrevented. */
|
||||
export default defineComponent({
|
||||
name: "DatePrimitiveNode",
|
||||
inheritAttrs: false,
|
||||
props: {
|
||||
as: { type: String, default: "span" },
|
||||
consumer: Object as PropType<Record<string, unknown>>,
|
||||
overrides: Object as PropType<Record<string, unknown>>,
|
||||
},
|
||||
setup(props, { attrs, slots, expose }) {
|
||||
let element: HTMLElement | undefined;
|
||||
expose({
|
||||
get element() {
|
||||
return element;
|
||||
},
|
||||
});
|
||||
return () => {
|
||||
const ordinary: Record<string, unknown> = {},
|
||||
events: Record<string, unknown> = {};
|
||||
for (const [key, value] of Object.entries(attrs)) {
|
||||
if (/^on[A-Z]/.test(key))
|
||||
events[key] = (event: Event) => {
|
||||
if (event.defaultPrevented) return;
|
||||
for (const handler of Array.isArray(value) ? value : [value]) {
|
||||
if (typeof handler === "function") handler(event);
|
||||
}
|
||||
};
|
||||
else ordinary[key] = value;
|
||||
}
|
||||
return h(
|
||||
props.as,
|
||||
mergeProps(
|
||||
ordinary,
|
||||
props.consumer ?? {},
|
||||
events,
|
||||
props.overrides ?? {},
|
||||
{
|
||||
ref: (node: unknown) => {
|
||||
element = node as HTMLElement | undefined;
|
||||
const receive = props.overrides?.ref;
|
||||
if (typeof receive === "function") receive(element);
|
||||
},
|
||||
},
|
||||
),
|
||||
slots.default?.(),
|
||||
);
|
||||
};
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,37 @@
|
||||
import { inject, type ComputedRef, type InjectionKey } from "vue";
|
||||
import type { DateValue } from "@internationalized/date";
|
||||
import type { DateFieldInputProps } from "reka-ui";
|
||||
import type { dateInputGroupVariants } from "@heroui-vue/styles";
|
||||
export interface DateSegment {
|
||||
part: DateFieldInputProps["part"];
|
||||
type: DateFieldInputProps["part"];
|
||||
value: string;
|
||||
text: string;
|
||||
isPlaceholder: boolean;
|
||||
isEditable: boolean;
|
||||
}
|
||||
export interface DateFieldContext {
|
||||
value: ComputedRef<DateValue | null>;
|
||||
disabled: ComputedRef<boolean>;
|
||||
readOnly: ComputedRef<boolean>;
|
||||
required: ComputedRef<boolean>;
|
||||
invalid: ComputedRef<boolean>;
|
||||
leadingZeros: () => boolean | undefined;
|
||||
labelledBy: () => string | undefined;
|
||||
describedBy: () => string | undefined;
|
||||
ariaLabel: () => unknown;
|
||||
}
|
||||
export const dateFieldKey: InjectionKey<DateFieldContext> =
|
||||
Symbol("hv-date-field");
|
||||
export const dateGroupKey: InjectionKey<
|
||||
ComputedRef<ReturnType<typeof dateInputGroupVariants>>
|
||||
> = Symbol("hv-date-group");
|
||||
export function useDateField() {
|
||||
const value = inject(dateFieldKey, undefined);
|
||||
if (!value) throw new Error("Date input parts require a DateField root.");
|
||||
return value;
|
||||
}
|
||||
|
||||
export const dateSegmentsKey: InjectionKey<
|
||||
ComputedRef<{ part: DateFieldInputProps["part"]; value: string }[]>
|
||||
> = Symbol("hv-date-segments");
|
||||
@@ -0,0 +1,25 @@
|
||||
import { defineComponent, watch } from "vue";
|
||||
import { injectDateFieldRootContext } from "reka-ui";
|
||||
|
||||
/** Reka does not watch equal primitive null values after a rejected edit.
|
||||
* Clear its existing segment refs without replacing DOM, focus or IDs. */
|
||||
export default defineComponent({
|
||||
name: "EmptyDateBridge",
|
||||
props: { revision: { type: Number, required: true } },
|
||||
setup(props) {
|
||||
const base = injectDateFieldRootContext();
|
||||
watch(
|
||||
() => props.revision,
|
||||
() => {
|
||||
base.segmentValues.value = Object.fromEntries(
|
||||
Object.keys(base.segmentValues.value).map((part) => [
|
||||
part,
|
||||
part === "dayPeriod" ? "AM" : null,
|
||||
]),
|
||||
) as typeof base.segmentValues.value;
|
||||
},
|
||||
{ flush: "post" },
|
||||
);
|
||||
return () => null;
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,60 @@
|
||||
import { computed, nextTick, ref } from "vue";
|
||||
import type { DateValue } from "@internationalized/date";
|
||||
import { useChoiceValue } from "../choice/shared";
|
||||
import { copyDateValue, sameDateValue } from "./value";
|
||||
|
||||
/** One accepted model, with a copied wire value to resynchronize editable
|
||||
* Reka segments after a completed proposal. Partial drafts stay in the base. */
|
||||
export function useAcceptedDateValue(options: {
|
||||
value: () => DateValue | null | undefined;
|
||||
defaultValue: () => DateValue | null | undefined;
|
||||
onChange: (value: DateValue | null) => void;
|
||||
disabled?: () => boolean;
|
||||
readOnly?: () => boolean;
|
||||
}) {
|
||||
const model = useChoiceValue<DateValue | null | undefined>(
|
||||
() => copyDateValue(options.value()),
|
||||
() => copyDateValue(options.defaultValue() ?? null),
|
||||
["modelValue", "model-value", "value"],
|
||||
(value) => options.onChange(copyDateValue(value ?? null)),
|
||||
);
|
||||
const revision = ref(0);
|
||||
const emptyRevision = ref(0);
|
||||
let requestId = 0;
|
||||
const value = computed(() => {
|
||||
const copy = copyDateValue(model.value.value ?? null);
|
||||
return copy ? (Object.freeze(copy) as DateValue) : null;
|
||||
});
|
||||
const wire = computed(() => {
|
||||
void revision.value;
|
||||
return copyDateValue(value.value);
|
||||
});
|
||||
function restore() {
|
||||
revision.value++;
|
||||
// Parent props and the base's segment edit both settle before this copy.
|
||||
void nextTick(() => {
|
||||
revision.value++;
|
||||
});
|
||||
}
|
||||
function request(next: DateValue | null | undefined) {
|
||||
if (
|
||||
!options.disabled?.() &&
|
||||
!options.readOnly?.() &&
|
||||
!sameDateValue(value.value, next)
|
||||
)
|
||||
model.request(copyDateValue(next ?? null));
|
||||
restore();
|
||||
const id = ++requestId;
|
||||
if (next != null)
|
||||
void nextTick(() => {
|
||||
if (id === requestId && value.value === null) emptyRevision.value++;
|
||||
});
|
||||
}
|
||||
function reset() {
|
||||
requestId++;
|
||||
model.reset();
|
||||
restore();
|
||||
if (value.value === null) emptyRevision.value++;
|
||||
}
|
||||
return { value, wire, emptyRevision, request, reset };
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
import {
|
||||
DateFormatter,
|
||||
createCalendar,
|
||||
toCalendar,
|
||||
toCalendarDate,
|
||||
type CalendarIdentifier,
|
||||
type DateValue,
|
||||
} from "@internationalized/date";
|
||||
|
||||
/** Private date boundary: preserve calendar/time/zone, never round-trip JS Date. */
|
||||
export function copyDateValue<T extends DateValue | null | undefined>(
|
||||
value: T,
|
||||
): T {
|
||||
return (value == null ? value : value.copy()) as T;
|
||||
}
|
||||
export function dateValueKey(value: DateValue | null | undefined): string {
|
||||
if (value == null) return "empty";
|
||||
const time =
|
||||
"hour" in value
|
||||
? [value.hour, value.minute, value.second, value.millisecond]
|
||||
: [];
|
||||
const zone = "timeZone" in value ? [value.timeZone, value.offset] : [];
|
||||
return JSON.stringify([
|
||||
value.calendar.identifier,
|
||||
value.era,
|
||||
value.year,
|
||||
value.month,
|
||||
value.day,
|
||||
...time,
|
||||
...zone,
|
||||
]);
|
||||
}
|
||||
export function sameDateValue(
|
||||
a: DateValue | null | undefined,
|
||||
b: DateValue | null | undefined,
|
||||
): boolean {
|
||||
return dateValueKey(a) === dateValueKey(b);
|
||||
}
|
||||
export function copyDateValues<T extends DateValue>(values: readonly T[]): T[] {
|
||||
const seen = new Set<string>();
|
||||
return values
|
||||
.filter((value) => {
|
||||
const key = dateValueKey(value);
|
||||
if (seen.has(key)) return false;
|
||||
seen.add(key);
|
||||
return true;
|
||||
})
|
||||
.map(copyDateValue);
|
||||
}
|
||||
/** Full ISO boundary; display granularity must not truncate the accepted model. */
|
||||
export function serializeDateValue(
|
||||
value: DateValue | null | undefined,
|
||||
): string {
|
||||
return value?.toString() ?? "";
|
||||
}
|
||||
export interface CalendarDayRules {
|
||||
minValue?: DateValue;
|
||||
maxValue?: DateValue;
|
||||
isDisabled?: boolean;
|
||||
isDateDisabled?: (value: DateValue) => boolean;
|
||||
isDateUnavailable?: (value: DateValue) => boolean;
|
||||
}
|
||||
export function calendarDayState(
|
||||
value: DateValue,
|
||||
rules: CalendarDayRules = {},
|
||||
) {
|
||||
const day = toCalendarDate(value);
|
||||
const outOfRange = !!(
|
||||
(rules.minValue && day.compare(toCalendarDate(rules.minValue)) < 0) ||
|
||||
(rules.maxValue && day.compare(toCalendarDate(rules.maxValue)) > 0)
|
||||
);
|
||||
const isDisabled = !!(
|
||||
rules.isDisabled ||
|
||||
outOfRange ||
|
||||
rules.isDateDisabled?.(value)
|
||||
);
|
||||
const isUnavailable = !!rules.isDateUnavailable?.(value);
|
||||
return {
|
||||
isDisabled,
|
||||
isUnavailable,
|
||||
isSelectable: !isDisabled && !isUnavailable,
|
||||
};
|
||||
}
|
||||
export interface DateRangeValue<T extends DateValue = DateValue> {
|
||||
start: T | null;
|
||||
end: T | null;
|
||||
}
|
||||
export function copyDateRange<T extends DateValue>(
|
||||
range: DateRangeValue<T>,
|
||||
): DateRangeValue<T> {
|
||||
return { start: copyDateValue(range.start), end: copyDateValue(range.end) };
|
||||
}
|
||||
/** Calendar ranges compare local calendar days; time-field bounds are separate. */
|
||||
export function calendarRangeStatus(
|
||||
range: DateRangeValue,
|
||||
): "empty" | "incomplete" | "inverted" | "valid" {
|
||||
if (!range.start && !range.end) return "empty";
|
||||
if (!range.start || !range.end) return "incomplete";
|
||||
return toCalendarDate(range.start).compare(toCalendarDate(range.end)) > 0
|
||||
? "inverted"
|
||||
: "valid";
|
||||
}
|
||||
|
||||
/** View-calendar conversion is explicit and must not replace the public model. */
|
||||
export function dateForLocale<T extends DateValue>(
|
||||
value: T,
|
||||
locale: string,
|
||||
): T {
|
||||
const identifier = new DateFormatter(locale).resolvedOptions()
|
||||
.calendar as CalendarIdentifier;
|
||||
return toCalendar(value, createCalendar(identifier)) as T;
|
||||
}
|
||||
@@ -749,3 +749,56 @@ export type {
|
||||
SelectClearButtonProps,
|
||||
SelectPopoverProps,
|
||||
} from "./types";
|
||||
|
||||
export {
|
||||
default as DateField,
|
||||
default as DateFieldRoot,
|
||||
} from "./components/date-field/DateField.vue";
|
||||
export {
|
||||
default as DateInputGroup,
|
||||
default as DateFieldGroup,
|
||||
} from "./components/date-field/DateInputGroup.vue";
|
||||
export {
|
||||
default as DateInputGroupInput,
|
||||
default as DateFieldInput,
|
||||
} from "./components/date-field/DateInputGroupInput.vue";
|
||||
export {
|
||||
default as DateInputGroupSegment,
|
||||
default as DateFieldSegment,
|
||||
} from "./components/date-field/DateInputGroupSegment.vue";
|
||||
export {
|
||||
default as DateInputGroupInputContainer,
|
||||
default as DateFieldInputContainer,
|
||||
} from "./components/date-field/DateInputGroupInputContainer.vue";
|
||||
export {
|
||||
default as DateInputGroupPrefix,
|
||||
default as DateFieldPrefix,
|
||||
} from "./components/date-field/DateInputGroupPrefix.vue";
|
||||
export {
|
||||
default as DateInputGroupSuffix,
|
||||
default as DateFieldSuffix,
|
||||
} from "./components/date-field/DateInputGroupSuffix.vue";
|
||||
export type { DateSegment } from "./components/date-field/context";
|
||||
|
||||
export {
|
||||
dateFieldVariants,
|
||||
dateInputGroupVariants,
|
||||
type DateFieldVariants,
|
||||
type DateInputGroupVariants,
|
||||
} from "@heroui-vue/styles";
|
||||
export type {
|
||||
DateFieldProps,
|
||||
DateFieldRootProps,
|
||||
DateFieldGroupProps,
|
||||
DateFieldInputProps,
|
||||
DateFieldSegmentProps,
|
||||
DateFieldInputContainerProps,
|
||||
DateFieldPrefixProps,
|
||||
DateFieldSuffixProps,
|
||||
DateInputGroupProps,
|
||||
DateInputGroupInputProps,
|
||||
DateInputGroupSegmentProps,
|
||||
DateInputGroupInputContainerProps,
|
||||
DateInputGroupPrefixProps,
|
||||
DateInputGroupSuffixProps,
|
||||
} from "./types";
|
||||
|
||||
@@ -616,3 +616,32 @@ export type SelectPopoverProps = InstanceType<
|
||||
(typeof import("./components/select/SelectPopover.vue"))["default"]
|
||||
>["$props"];
|
||||
export type SelectRootProps = SelectProps;
|
||||
|
||||
export type DateFieldProps = InstanceType<
|
||||
(typeof import("./components/date-field/DateField.vue"))["default"]
|
||||
>["$props"];
|
||||
export type DateInputGroupProps = InstanceType<
|
||||
(typeof import("./components/date-field/DateInputGroup.vue"))["default"]
|
||||
>["$props"];
|
||||
export type DateInputGroupInputProps = InstanceType<
|
||||
(typeof import("./components/date-field/DateInputGroupInput.vue"))["default"]
|
||||
>["$props"];
|
||||
export type DateInputGroupSegmentProps = InstanceType<
|
||||
(typeof import("./components/date-field/DateInputGroupSegment.vue"))["default"]
|
||||
>["$props"];
|
||||
export type DateInputGroupInputContainerProps = InstanceType<
|
||||
(typeof import("./components/date-field/DateInputGroupInputContainer.vue"))["default"]
|
||||
>["$props"];
|
||||
export type DateInputGroupPrefixProps = InstanceType<
|
||||
(typeof import("./components/date-field/DateInputGroupPrefix.vue"))["default"]
|
||||
>["$props"];
|
||||
export type DateInputGroupSuffixProps = InstanceType<
|
||||
(typeof import("./components/date-field/DateInputGroupSuffix.vue"))["default"]
|
||||
>["$props"];
|
||||
export type DateFieldRootProps = DateFieldProps;
|
||||
export type DateFieldGroupProps = DateInputGroupProps;
|
||||
export type DateFieldInputProps = DateInputGroupInputProps;
|
||||
export type DateFieldSegmentProps = DateInputGroupSegmentProps;
|
||||
export type DateFieldInputContainerProps = DateInputGroupInputContainerProps;
|
||||
export type DateFieldPrefixProps = DateInputGroupPrefixProps;
|
||||
export type DateFieldSuffixProps = DateInputGroupSuffixProps;
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from "vue";
|
||||
import type { DateValue } from "@internationalized/date";
|
||||
import EmptyDateBridge from "../../src/components/date/EmptyDateBridge";
|
||||
import DateFieldFoundation from "./DateFieldFoundation.vue";
|
||||
import { useAcceptedDateValue } from "../../src/components/date/model";
|
||||
import { serializeDateValue } from "../../src/components/date/value";
|
||||
import { useChoiceForm } from "../../src/components/choice/shared";
|
||||
const props = defineProps<{
|
||||
modelValue?: DateValue | null;
|
||||
defaultValue?: DateValue;
|
||||
defaultPlaceholder?: DateValue;
|
||||
name?: string;
|
||||
disabled?: boolean;
|
||||
readonly?: boolean;
|
||||
}>();
|
||||
const emit = defineEmits<{ "update:modelValue": [value: DateValue | null] }>();
|
||||
const accepted = useAcceptedDateValue({
|
||||
value: () => props.modelValue,
|
||||
defaultValue: () => props.defaultValue,
|
||||
onChange: (value) => emit("update:modelValue", value),
|
||||
disabled: () => !!props.disabled,
|
||||
readOnly: () => !!props.readonly,
|
||||
});
|
||||
const native = ref<HTMLInputElement>();
|
||||
const serialized = computed(() => serializeDateValue(accepted.value.value));
|
||||
useChoiceForm(native, accepted.reset, () => {});
|
||||
</script>
|
||||
<template>
|
||||
<div>
|
||||
<DateFieldFoundation
|
||||
:model-value="accepted.wire.value"
|
||||
:default-placeholder="defaultPlaceholder"
|
||||
:disabled="disabled"
|
||||
:readonly="readonly"
|
||||
@update:model-value="accepted.request"
|
||||
>
|
||||
<EmptyDateBridge :revision="accepted.emptyRevision.value" />
|
||||
</DateFieldFoundation>
|
||||
<input
|
||||
ref="native"
|
||||
type="hidden"
|
||||
:name="name"
|
||||
:value="serialized"
|
||||
:disabled="disabled"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,87 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
CalendarRoot,
|
||||
CalendarHeader,
|
||||
CalendarHeading,
|
||||
CalendarPrev,
|
||||
CalendarNext,
|
||||
CalendarGrid,
|
||||
CalendarGridHead,
|
||||
CalendarGridRow,
|
||||
CalendarHeadCell,
|
||||
CalendarGridBody,
|
||||
CalendarCell,
|
||||
CalendarCellTrigger,
|
||||
type CalendarRootProps,
|
||||
} from "reka-ui";
|
||||
import type { DateValue } from "@internationalized/date";
|
||||
defineOptions({ inheritAttrs: false });
|
||||
withDefaults(
|
||||
defineProps<
|
||||
Pick<
|
||||
CalendarRootProps,
|
||||
| "modelValue"
|
||||
| "defaultValue"
|
||||
| "defaultPlaceholder"
|
||||
| "locale"
|
||||
| "disabled"
|
||||
| "readonly"
|
||||
| "isDateDisabled"
|
||||
| "isDateUnavailable"
|
||||
| "multiple"
|
||||
| "numberOfMonths"
|
||||
| "weekStartsOn"
|
||||
| "minValue"
|
||||
| "maxValue"
|
||||
| "fixedWeeks"
|
||||
>
|
||||
>(),
|
||||
{ modelValue: undefined, locale: "en-US" },
|
||||
);
|
||||
const emit = defineEmits<{
|
||||
"update:modelValue": [value: DateValue | DateValue[] | undefined];
|
||||
}>();
|
||||
</script>
|
||||
<template>
|
||||
<CalendarRoot
|
||||
v-slot="{ grid, weekDays }"
|
||||
v-bind="$attrs"
|
||||
:model-value="modelValue"
|
||||
:default-value="defaultValue"
|
||||
:default-placeholder="defaultPlaceholder"
|
||||
:locale="locale"
|
||||
:disabled="disabled"
|
||||
:readonly="readonly"
|
||||
:is-date-disabled="isDateDisabled"
|
||||
:is-date-unavailable="isDateUnavailable"
|
||||
:multiple="multiple"
|
||||
:number-of-months="numberOfMonths"
|
||||
:week-starts-on="weekStartsOn"
|
||||
:min-value="minValue"
|
||||
:max-value="maxValue"
|
||||
:fixed-weeks="fixedWeeks"
|
||||
@update:model-value="emit('update:modelValue', $event)"
|
||||
>
|
||||
<CalendarHeader>
|
||||
<CalendarPrev aria-label="Previous" />
|
||||
<CalendarHeading />
|
||||
<CalendarNext aria-label="Next" />
|
||||
</CalendarHeader>
|
||||
<CalendarGrid v-for="month in grid" :key="month.value.toString()">
|
||||
<CalendarGridHead>
|
||||
<CalendarGridRow>
|
||||
<CalendarHeadCell v-for="day in weekDays" :key="day">
|
||||
{{ day }}
|
||||
</CalendarHeadCell>
|
||||
</CalendarGridRow>
|
||||
</CalendarGridHead>
|
||||
<CalendarGridBody>
|
||||
<CalendarGridRow v-for="(week, index) in month.rows" :key="index">
|
||||
<CalendarCell v-for="day in week" :key="day.toString()" :date="day">
|
||||
<CalendarCellTrigger :day="day" :month="month.value" />
|
||||
</CalendarCell>
|
||||
</CalendarGridRow>
|
||||
</CalendarGridBody>
|
||||
</CalendarGrid>
|
||||
</CalendarRoot>
|
||||
</template>
|
||||
@@ -0,0 +1,63 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
DateFieldRoot,
|
||||
DateFieldInput,
|
||||
type DateFieldRootProps,
|
||||
} from "reka-ui";
|
||||
import type { DateValue } from "@internationalized/date";
|
||||
defineOptions({ inheritAttrs: false });
|
||||
withDefaults(
|
||||
defineProps<
|
||||
Pick<
|
||||
DateFieldRootProps,
|
||||
| "modelValue"
|
||||
| "defaultValue"
|
||||
| "defaultPlaceholder"
|
||||
| "granularity"
|
||||
| "locale"
|
||||
| "disabled"
|
||||
| "readonly"
|
||||
| "required"
|
||||
| "name"
|
||||
| "minValue"
|
||||
| "maxValue"
|
||||
| "hideTimeZone"
|
||||
| "hourCycle"
|
||||
>
|
||||
>(),
|
||||
{ modelValue: undefined, locale: "en-US" },
|
||||
);
|
||||
const emit = defineEmits<{
|
||||
"update:modelValue": [value: DateValue | undefined];
|
||||
}>();
|
||||
</script>
|
||||
<template>
|
||||
<DateFieldRoot
|
||||
v-slot="{ segments }"
|
||||
v-bind="$attrs"
|
||||
:model-value="modelValue"
|
||||
:default-value="defaultValue"
|
||||
:default-placeholder="defaultPlaceholder"
|
||||
:granularity="granularity"
|
||||
:locale="locale"
|
||||
:disabled="disabled"
|
||||
:readonly="readonly"
|
||||
:required="required"
|
||||
:name="name"
|
||||
:min-value="minValue"
|
||||
:max-value="maxValue"
|
||||
:hide-time-zone="hideTimeZone"
|
||||
:hour-cycle="hourCycle"
|
||||
aria-label="Date audit"
|
||||
@update:model-value="emit('update:modelValue', $event)"
|
||||
>
|
||||
<slot />
|
||||
<DateFieldInput
|
||||
v-for="(segment, index) in segments"
|
||||
:key="`${segment.part}-${index}`"
|
||||
:part="segment.part"
|
||||
>
|
||||
{{ segment.value }}
|
||||
</DateFieldInput>
|
||||
</DateFieldRoot>
|
||||
</template>
|
||||
@@ -32,7 +32,13 @@ export default defineConfig({
|
||||
build: {
|
||||
lib: { entry: "src/index.ts", formats: ["es"], fileName: "index" },
|
||||
rollupOptions: {
|
||||
external: ["vue", "reka-ui", "@heroui-vue/styles", "@vueuse/core"],
|
||||
external: [
|
||||
"vue",
|
||||
"reka-ui",
|
||||
"@heroui-vue/styles",
|
||||
"@vueuse/core",
|
||||
"@internationalized/date",
|
||||
],
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
Generated
+6
@@ -8,6 +8,9 @@ importers:
|
||||
|
||||
.:
|
||||
devDependencies:
|
||||
'@internationalized/date':
|
||||
specifier: 3.12.4
|
||||
version: 3.12.4
|
||||
'@types/node':
|
||||
specifier: ^22.0.0
|
||||
version: 22.20.5
|
||||
@@ -116,6 +119,9 @@ importers:
|
||||
'@heroui-vue/styles':
|
||||
specifier: workspace:*
|
||||
version: link:../styles
|
||||
'@internationalized/date':
|
||||
specifier: 3.12.4
|
||||
version: 3.12.4
|
||||
'@vueuse/core':
|
||||
specifier: 14.4.0
|
||||
version: 14.4.0(vue@3.5.44(typescript@5.9.3))
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { mount, flushPromises } from "@vue/test-utils";
|
||||
import { readFileSync } from "node:fs";
|
||||
const demos = import.meta.glob("../apps/docs/demos/date-field-*.vue", {
|
||||
eager: true,
|
||||
import: "default",
|
||||
});
|
||||
const expected = [
|
||||
"basic",
|
||||
"with-prefix-icon",
|
||||
"with-suffix-icon",
|
||||
"with-prefix-and-suffix",
|
||||
"variants",
|
||||
"on-surface",
|
||||
"with-description",
|
||||
"required",
|
||||
"disabled",
|
||||
"full-width",
|
||||
"invalid",
|
||||
"granularity",
|
||||
"controlled",
|
||||
"form-example",
|
||||
"with-validation",
|
||||
"render-function",
|
||||
"custom-styles",
|
||||
];
|
||||
describe("DateField documentation", () => {
|
||||
it("includes every pinned preview and uses the displayed SFC as its implementation", () => {
|
||||
const md = readFileSync("apps/docs/components/date-field.md", "utf8");
|
||||
expect(
|
||||
[...md.matchAll(/<ComponentPreview name="date-field-([^"]+)"/g)].map(
|
||||
(match) => match[1],
|
||||
),
|
||||
).toEqual(expected);
|
||||
expect(md).not.toContain("[!toc]");
|
||||
expect(Object.keys(demos)).toHaveLength(17);
|
||||
});
|
||||
it("mounts all seventeen examples without warnings or missing date controls", async () => {
|
||||
const warnings: string[] = [];
|
||||
for (const demo of Object.values(demos)) {
|
||||
const w = mount(demo as never, {
|
||||
global: {
|
||||
config: { warnHandler: (message) => warnings.push(message) },
|
||||
},
|
||||
});
|
||||
await flushPromises();
|
||||
expect(w.find('[data-slot="date-field"]').exists()).toBe(true);
|
||||
expect(w.find('[data-slot="date-input-group-segment"]').exists()).toBe(
|
||||
true,
|
||||
);
|
||||
w.unmount();
|
||||
}
|
||||
expect(warnings).toEqual([]);
|
||||
});
|
||||
});
|
||||
it("the controlled example's action buttons update and clear the real date", async () => {
|
||||
const component = demos["../apps/docs/demos/date-field-controlled.vue"];
|
||||
const w = mount(component as never);
|
||||
try {
|
||||
await w.get("button").trigger("click");
|
||||
await flushPromises();
|
||||
expect(
|
||||
(w.get('[data-slot="date-field-value"]').element as HTMLInputElement)
|
||||
.value,
|
||||
).toMatch(/^\d{4}-\d{2}-\d{2}$/);
|
||||
expect(w.get('[data-slot="description"]').text()).not.toContain("(空)");
|
||||
await w.findAll("button")[1].trigger("click");
|
||||
await flushPromises();
|
||||
expect(w.get('[data-slot="description"]').text()).toContain("(空)");
|
||||
expect(w.findAll('[data-placeholder="true"]')).toHaveLength(3);
|
||||
} finally {
|
||||
w.unmount();
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,45 @@
|
||||
// @vitest-environment node
|
||||
import { expect, it } from "vitest";
|
||||
import { createSSRApp, h } from "vue";
|
||||
import { renderToString } from "@vue/server-renderer";
|
||||
import { parseZonedDateTime } from "@internationalized/date";
|
||||
import {
|
||||
DateField,
|
||||
DateFieldGroup,
|
||||
DateFieldInput,
|
||||
Label,
|
||||
Description,
|
||||
} from "../packages/vue/src";
|
||||
it("renders public DateField and complete ISO values on Node with stable, unique field associations", async () => {
|
||||
expect(typeof window).toBe("undefined");
|
||||
const date = parseZonedDateTime(
|
||||
"2024-03-10T01:30:45-08:00[America/Los_Angeles]",
|
||||
);
|
||||
const field = () =>
|
||||
h(
|
||||
DateField,
|
||||
{
|
||||
defaultValue: date,
|
||||
name: "date",
|
||||
granularity: "minute",
|
||||
locale: "en-US",
|
||||
},
|
||||
() => [
|
||||
h(Label, () => "Date"),
|
||||
h(DateFieldGroup, () => h(DateFieldInput)),
|
||||
h(Description, () => "Help"),
|
||||
],
|
||||
);
|
||||
const app = () =>
|
||||
createSSRApp({ render: () => h("form", [field(), field()]) });
|
||||
const html = await renderToString(app());
|
||||
expect(html).toBe(await renderToString(app()));
|
||||
expect(html.match(/name="date"/g)).toHaveLength(2);
|
||||
expect(
|
||||
html.match(/value="2024-03-10T01:30:45-08:00\[America\/Los_Angeles\]"/g),
|
||||
).toHaveLength(2);
|
||||
const ids = [...html.matchAll(/ id="([^"]+)"/g)].map((match) => match[1]);
|
||||
expect(new Set(ids).size).toBe(ids.length);
|
||||
expect(html).toContain("aria-labelledby=");
|
||||
expect(html).toContain("aria-describedby=");
|
||||
});
|
||||
@@ -0,0 +1,331 @@
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import { mount, flushPromises } from "@vue/test-utils";
|
||||
import { createSSRApp, defineComponent, ref } from "vue";
|
||||
import { renderToString } from "@vue/server-renderer";
|
||||
import {
|
||||
CalendarDate,
|
||||
CalendarDateTime,
|
||||
parseZonedDateTime,
|
||||
PersianCalendar,
|
||||
toCalendar,
|
||||
} from "@internationalized/date";
|
||||
import {
|
||||
DateField,
|
||||
DateFieldGroup,
|
||||
DateFieldInput,
|
||||
DateFieldSegment,
|
||||
DateFieldPrefix,
|
||||
Label,
|
||||
Description,
|
||||
FieldError,
|
||||
Fieldset,
|
||||
Form,
|
||||
ConfigProvider,
|
||||
} from "../packages/vue/src";
|
||||
const components = {
|
||||
DateField,
|
||||
DateFieldGroup,
|
||||
DateFieldInput,
|
||||
DateFieldSegment,
|
||||
DateFieldPrefix,
|
||||
Label,
|
||||
Description,
|
||||
FieldError,
|
||||
Fieldset,
|
||||
Form,
|
||||
ConfigProvider,
|
||||
};
|
||||
const content =
|
||||
'<Label>Date</Label><DateFieldGroup><DateFieldInput v-slot="{segment}"><DateFieldSegment :segment="segment" /></DateFieldInput></DateFieldGroup><Description>Help</Description><FieldError/>';
|
||||
const initial = new CalendarDate(2024, 2, 10);
|
||||
const wrappers: ReturnType<typeof mount>[] = [];
|
||||
afterEach(() => {
|
||||
wrappers.splice(0).forEach((w) => w.unmount());
|
||||
document.body.innerHTML = "";
|
||||
});
|
||||
function fixture(template: string, setup = () => ({})) {
|
||||
const w = mount(defineComponent({ components, template, setup }), {
|
||||
attachTo: document.body,
|
||||
});
|
||||
wrappers.push(w);
|
||||
return w;
|
||||
}
|
||||
const part = (w: ReturnType<typeof mount>, type = "day") =>
|
||||
w.get(`[data-type="${type}"]`);
|
||||
const values = (w: ReturnType<typeof mount>) =>
|
||||
new FormData(w.get("form").element as HTMLFormElement).getAll("date");
|
||||
describe("DateField", () => {
|
||||
it("renders separators and shares field state/name/description on the actual group", async () => {
|
||||
const w = fixture(
|
||||
`<form><DateField name="date" :default-value="initial">${content}</DateField></form>`,
|
||||
() => ({ initial }),
|
||||
);
|
||||
expect(w.findAll('[data-type="literal"]')).toHaveLength(2);
|
||||
const root = w.get('[data-slot="date-field"]');
|
||||
expect(root.attributes("aria-labelledby")).toContain(
|
||||
w.get('[data-slot="label"]').attributes("id"),
|
||||
);
|
||||
expect(root.attributes("aria-describedby")).toContain(
|
||||
w.get('[data-slot="description"]').attributes("id"),
|
||||
);
|
||||
expect(values(w)).toEqual(["2024-02-10"]);
|
||||
await part(w).trigger("keydown", { key: "ArrowUp" });
|
||||
await flushPromises();
|
||||
expect(values(w)).toEqual(["2024-02-11"]);
|
||||
expect(part(w).text()).toBe("11");
|
||||
});
|
||||
it("restores rejected nonempty and empty completed proposals with stable DOM/focus", async () => {
|
||||
const value = ref<CalendarDate | null>(null);
|
||||
const w = fixture(
|
||||
`<form><DateField :model-value="value" :placeholder-value="initial" name="date">${content}</DateField></form>`,
|
||||
() => ({ initial, value }),
|
||||
);
|
||||
const el = part(w, "year").element as HTMLElement;
|
||||
el.focus();
|
||||
for (const type of ["month", "day", "year"])
|
||||
await part(w, type).trigger("keydown", { key: "ArrowUp" });
|
||||
await flushPromises();
|
||||
expect(part(w, "year").element).toBe(el);
|
||||
expect(document.activeElement).toBe(el);
|
||||
expect(part(w).attributes("data-placeholder")).toBe("true");
|
||||
expect(values(w)).toEqual([""]);
|
||||
const field = w.getComponent(DateField);
|
||||
value.value = initial;
|
||||
await flushPromises();
|
||||
await part(w).trigger("keydown", { key: "ArrowUp" });
|
||||
await flushPromises();
|
||||
expect(part(w).text()).toBe("10");
|
||||
expect(values(w)).toEqual(["2024-02-10"]);
|
||||
});
|
||||
it("keeps time precision and the named zone at day granularity", async () => {
|
||||
const value = ref(
|
||||
parseZonedDateTime("2024-03-10T01:30:45.123-08:00[America/Los_Angeles]"),
|
||||
);
|
||||
const w = fixture(
|
||||
`<form><DateField v-model="value" name="date" granularity="day">${content}</DateField></form>`,
|
||||
() => ({ value }),
|
||||
);
|
||||
expect(w.find('[data-type="hour"]').exists()).toBe(false);
|
||||
await part(w).trigger("keydown", { key: "ArrowUp" });
|
||||
await flushPromises();
|
||||
expect(value.value.timeZone).toBe("America/Los_Angeles");
|
||||
expect(value.value.second).toBe(45);
|
||||
expect(value.value.millisecond).toBe(123);
|
||||
expect(values(w)).toEqual([value.value.toString()]);
|
||||
});
|
||||
it("preserves the model calendar while editing in the locale calendar", async () => {
|
||||
const value = ref(toCalendar(initial, new PersianCalendar()));
|
||||
const w = fixture(
|
||||
`<form><DateField v-model="value" locale="en-US" name="date">${content}</DateField></form>`,
|
||||
() => ({ value }),
|
||||
);
|
||||
expect(part(w, "year").text()).toBe("2024");
|
||||
await part(w).trigger("keydown", { key: "ArrowUp" });
|
||||
await flushPromises();
|
||||
expect(value.value.calendar.identifier).toBe("persian");
|
||||
expect(values(w)).toEqual(["2024-02-11"]);
|
||||
});
|
||||
it("uses provider locale and updates segment order", async () => {
|
||||
const locale = ref("en-US");
|
||||
const w = fixture(
|
||||
`<ConfigProvider :locale="locale"><DateField :default-value="initial">${content}</DateField></ConfigProvider>`,
|
||||
() => ({ locale, initial }),
|
||||
);
|
||||
expect(
|
||||
w
|
||||
.findAll('[data-slot="date-input-group-segment"]')[0]
|
||||
.attributes("data-type"),
|
||||
).toBe("month");
|
||||
locale.value = "zh-CN";
|
||||
await flushPromises();
|
||||
expect(
|
||||
w
|
||||
.findAll('[data-slot="date-input-group-segment"]')[0]
|
||||
.attributes("data-type"),
|
||||
).toBe("year");
|
||||
});
|
||||
it("resets values and partial drafts; respects cancelled reset", async () => {
|
||||
const w = fixture(
|
||||
`<form><DateField name="date" :default-value="initial">${content}</DateField></form>`,
|
||||
() => ({ initial }),
|
||||
);
|
||||
await part(w).trigger("keydown", { key: "ArrowUp" });
|
||||
await flushPromises();
|
||||
(w.get("form").element as HTMLFormElement).reset();
|
||||
await flushPromises();
|
||||
expect(values(w)).toEqual(["2024-02-10"]);
|
||||
expect(part(w).text()).toBe("10");
|
||||
});
|
||||
it("validates required, range and custom constraints with FieldError and native invalid focus", async () => {
|
||||
const w = fixture(
|
||||
`<form><DateField name="date" is-required :placeholder-value="initial">${content}</DateField></form>`,
|
||||
() => ({ initial }),
|
||||
);
|
||||
const input = w.get(".hv-choice-validation").element as HTMLInputElement;
|
||||
expect(input.checkValidity()).toBe(false);
|
||||
await flushPromises();
|
||||
expect(w.get('[data-slot="date-field"]').attributes("aria-invalid")).toBe(
|
||||
"true",
|
||||
);
|
||||
expect(w.get('[data-slot="field-error"]').text()).toContain("请填写");
|
||||
expect(document.activeElement).toBe(part(w, "month").element);
|
||||
});
|
||||
it("supports aria validation and server errors with accepted edit dismissal", async () => {
|
||||
const errors = ref({ date: "Server error" });
|
||||
const w = fixture(
|
||||
`<Form :validation-errors="errors" validation-behavior="aria"><DateField :default-value="initial" name="date">${content}</DateField></Form>`,
|
||||
() => ({ initial, errors }),
|
||||
);
|
||||
expect(w.get('[data-slot="field-error"]').text()).toContain("Server error");
|
||||
expect(
|
||||
(
|
||||
w.get(".hv-choice-validation").element as HTMLInputElement
|
||||
).checkValidity(),
|
||||
).toBe(true);
|
||||
await part(w).trigger("keydown", { key: "ArrowUp" });
|
||||
await flushPromises();
|
||||
expect(w.find('[data-slot="field-error"]').exists()).toBe(false);
|
||||
});
|
||||
it("readonly submits and fieldset disabled omits; neither edits", async () => {
|
||||
const w = fixture(
|
||||
`<form><Fieldset disabled><DateField name="date" :default-value="initial">${content}</DateField></Fieldset></form>`,
|
||||
() => ({ initial }),
|
||||
);
|
||||
expect(values(w)).toEqual([]);
|
||||
expect(part(w).attributes("contenteditable")).toBe("false");
|
||||
await part(w).trigger("keydown", { key: "ArrowUp" });
|
||||
expect(w.getComponent(DateField).emitted("change")).toBeUndefined();
|
||||
});
|
||||
it("honors segment cancellation and explicit stop before the base navigation", async () => {
|
||||
const w = fixture(
|
||||
`<form><DateField :default-value="initial" name="date" @keydown.prevent><DateFieldGroup><DateFieldInput v-slot="{segment}"><DateFieldSegment :segment="segment" @keydown.stop.prevent/></DateFieldInput></DateFieldGroup></DateField></form>`,
|
||||
() => ({ initial }),
|
||||
);
|
||||
const el = part(w).element as HTMLElement;
|
||||
el.focus();
|
||||
await part(w).trigger("keydown", { key: "ArrowUp" });
|
||||
await flushPromises();
|
||||
expect(values(w)).toEqual(["2024-02-10"]);
|
||||
part(w).element.dispatchEvent(
|
||||
new KeyboardEvent("keydown", {
|
||||
key: "ArrowRight",
|
||||
bubbles: true,
|
||||
cancelable: true,
|
||||
}),
|
||||
);
|
||||
expect(document.activeElement).toBe(el);
|
||||
});
|
||||
it("updates granularity/hourCycle without dropping precision, supports leading zeros", async () => {
|
||||
const value = ref(new CalendarDateTime(2024, 2, 3, 13, 4, 5));
|
||||
const granularity = ref<"day" | "second">("day");
|
||||
const cycle = ref<12 | 24>(12);
|
||||
const w = fixture(
|
||||
`<form><DateField v-model="value" :granularity="granularity" :hour-cycle="cycle" should-force-leading-zeros name="date">${content}</DateField></form>`,
|
||||
() => ({ value, granularity, cycle }),
|
||||
);
|
||||
expect(part(w).text()).toBe("03");
|
||||
granularity.value = "second";
|
||||
cycle.value = 24;
|
||||
await flushPromises();
|
||||
expect(part(w, "hour").text()).toBe("13");
|
||||
expect(part(w, "second").text()).toBe("05");
|
||||
expect(values(w)).toEqual(["2024-02-03T13:04:05"]);
|
||||
});
|
||||
it("hydrates explicit date content with unique IDs and stable nodes", async () => {
|
||||
const component = defineComponent({
|
||||
components,
|
||||
setup: () => ({ initial }),
|
||||
template: `<DateField :default-value="initial">${content}</DateField>`,
|
||||
});
|
||||
const host = document.createElement("div");
|
||||
host.innerHTML = await renderToString(createSSRApp(component));
|
||||
document.body.append(host);
|
||||
const before = host.querySelector('[data-type="day"]');
|
||||
const warnings: string[] = [];
|
||||
const app = createSSRApp(component);
|
||||
app.config.warnHandler = (message) => warnings.push(message);
|
||||
app.mount(host);
|
||||
await flushPromises();
|
||||
try {
|
||||
expect(warnings).toEqual([]);
|
||||
expect(host.querySelector('[data-type="day"]')).toBe(before);
|
||||
} finally {
|
||||
app.unmount();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it("applies min/max and unavailable constraints to the shared native validator", async () => {
|
||||
const w = fixture(
|
||||
`<form><DateField name="date" :default-value="initial" :min-value="initial.add({days:1})" validation-behavior="aria">${content}</DateField></form>`,
|
||||
() => ({ initial }),
|
||||
);
|
||||
expect(w.get('[data-slot="field-error"]').text()).toContain("不能早于");
|
||||
await part(w).trigger("keydown", { key: "ArrowUp" });
|
||||
await flushPromises();
|
||||
expect(w.find('[data-slot="field-error"]').exists()).toBe(false);
|
||||
});
|
||||
it("keeps read-only submission and blocks edits without invalid constraints", async () => {
|
||||
const w = fixture(
|
||||
`<form><DateField name="date" :default-value="initial" is-read-only is-required>${content}</DateField></form>`,
|
||||
() => ({ initial }),
|
||||
);
|
||||
expect(values(w)).toEqual(["2024-02-10"]);
|
||||
await part(w).trigger("keydown", { key: "ArrowUp" });
|
||||
expect(w.getComponent(DateField).emitted("change")).toBeUndefined();
|
||||
expect(part(w).attributes("contenteditable")).toBe("false");
|
||||
expect(
|
||||
(w.get(".hv-choice-validation").element as HTMLInputElement).disabled,
|
||||
).toBe(true);
|
||||
});
|
||||
it("uses value alias, gives explicit modelValue priority and accepts explicit undefined empty", () => {
|
||||
const value = ref<CalendarDate | undefined>(undefined);
|
||||
const w = fixture(
|
||||
`<form><DateField name="date" :model-value="value" :value="initial" :default-value="initial" :placeholder-value="initial">${content}</DateField></form>`,
|
||||
() => ({ value, initial }),
|
||||
);
|
||||
expect(values(w)).toEqual([""]);
|
||||
expect(part(w).attributes("data-placeholder")).toBe("true");
|
||||
});
|
||||
it("preserves accepted controlled values on reset and honors prevented reset", async () => {
|
||||
const value = ref(initial);
|
||||
const w = fixture(
|
||||
`<form @reset.prevent><DateField name="date" v-model="value">${content}</DateField></form>`,
|
||||
() => ({ value, initial }),
|
||||
);
|
||||
await part(w).trigger("keydown", { key: "ArrowUp" });
|
||||
await flushPromises();
|
||||
(w.get("form").element as HTMLFormElement).reset();
|
||||
await flushPromises();
|
||||
expect(part(w).text()).toBe("11");
|
||||
expect(values(w)).toEqual(["2024-02-11"]);
|
||||
});
|
||||
it("uses one externally associated ISO value and restores after native autofill rejection", async () => {
|
||||
const w = fixture(
|
||||
`<div><form id="external"/><DateField form="external" name="date" :model-value="initial">${content}</DateField></div>`,
|
||||
() => ({ initial }),
|
||||
);
|
||||
const input = w.get('[data-slot="date-field-value"]');
|
||||
await input.setValue("2024-02-12");
|
||||
await flushPromises();
|
||||
expect(values(w)).toEqual(["2024-02-10"]);
|
||||
expect((input.element as HTMLInputElement).value).toBe("2024-02-10");
|
||||
expect(w.getComponent(DateField).emitted("change")).toHaveLength(1);
|
||||
});
|
||||
it("keeps IME composition keys out of the accepted model", async () => {
|
||||
const w = fixture(
|
||||
`<form><DateField name="date" :default-value="initial">${content}</DateField></form>`,
|
||||
() => ({ initial }),
|
||||
);
|
||||
part(w).element.dispatchEvent(
|
||||
new KeyboardEvent("keydown", {
|
||||
key: "2",
|
||||
isComposing: true,
|
||||
bubbles: true,
|
||||
cancelable: true,
|
||||
}),
|
||||
);
|
||||
await flushPromises();
|
||||
expect(values(w)).toEqual(["2024-02-10"]);
|
||||
expect(part(w).text()).toBe("10");
|
||||
});
|
||||
@@ -0,0 +1,63 @@
|
||||
// @vitest-environment node
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { createSSRApp, h } from "vue";
|
||||
import { renderToString } from "@vue/server-renderer";
|
||||
import { CalendarDate, parseZonedDateTime } from "@internationalized/date";
|
||||
import Field from "../packages/vue/tests/fixtures/DateFieldFoundation.vue";
|
||||
import Calendar from "../packages/vue/tests/fixtures/CalendarFoundation.vue";
|
||||
import Accepted from "../packages/vue/tests/fixtures/AcceptedDateFieldFoundation.vue";
|
||||
const initial = new CalendarDate(2024, 2, 10);
|
||||
describe("date foundation actual node SSR", () => {
|
||||
it("renders full segmented date without browser globals", async () => {
|
||||
expect(typeof window).toBe("undefined");
|
||||
const html = await renderToString(
|
||||
createSSRApp(Field, {
|
||||
defaultValue: initial,
|
||||
locale: "en-US",
|
||||
name: "date",
|
||||
}),
|
||||
);
|
||||
expect(html.match(/role="spinbutton"/g)).toHaveLength(3);
|
||||
expect(html).toContain('value="2024-02-10"');
|
||||
expect(html).toContain('aria-label="Date audit"');
|
||||
});
|
||||
it("renders leap month cells and selected date on the server", async () => {
|
||||
const html = await renderToString(
|
||||
createSSRApp(Calendar, {
|
||||
defaultValue: initial,
|
||||
defaultPlaceholder: initial,
|
||||
locale: "en-US",
|
||||
}),
|
||||
);
|
||||
expect(html).toContain('data-value="2024-02-29"');
|
||||
expect(html).toContain('data-selected="true"');
|
||||
// Installed CalendarGrid uses application, not grid; public ARIA needs explicit review.
|
||||
expect(html).toContain('role="application"');
|
||||
expect(html).toContain('role="gridcell"');
|
||||
});
|
||||
it("keeps SSR IDs stable and independent across same-page instances", async () => {
|
||||
const app = () =>
|
||||
createSSRApp({
|
||||
render: () =>
|
||||
h("main", [
|
||||
h(Field, { defaultValue: initial }),
|
||||
h(Field, { defaultValue: initial }),
|
||||
]),
|
||||
});
|
||||
const first = await renderToString(app());
|
||||
expect(first).toBe(await renderToString(app()));
|
||||
const ids = [...first.matchAll(/ id="([^"]+)"/g)].map((m) => m[1]);
|
||||
expect(new Set(ids).size).toBe(ids.length);
|
||||
});
|
||||
it("serializes the adapted complete zone-bearing model on SSR", async () => {
|
||||
const value = parseZonedDateTime(
|
||||
"2024-03-10T01:30:45-08:00[America/Los_Angeles]",
|
||||
);
|
||||
const html = await renderToString(
|
||||
createSSRApp(Accepted, { defaultValue: value, name: "date" }),
|
||||
);
|
||||
expect(html).toContain(
|
||||
'type="hidden" name="date" value="2024-03-10T01:30:45-08:00[America/Los_Angeles]"',
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,227 @@
|
||||
import { afterEach, describe, it, expect } from "vitest";
|
||||
import { mount, flushPromises } from "@vue/test-utils";
|
||||
import { defineComponent, ref } from "vue";
|
||||
import {
|
||||
CalendarDate,
|
||||
CalendarDateTime,
|
||||
parseZonedDateTime,
|
||||
toCalendar,
|
||||
PersianCalendar,
|
||||
} from "@internationalized/date";
|
||||
import DateFieldFoundation from "../packages/vue/tests/fixtures/DateFieldFoundation.vue";
|
||||
import CalendarFoundation from "../packages/vue/tests/fixtures/CalendarFoundation.vue";
|
||||
const wrappers: ReturnType<typeof mount>[] = [];
|
||||
afterEach(async () => {
|
||||
wrappers.splice(0).forEach((w) => w.unmount());
|
||||
await flushPromises();
|
||||
document.body.innerHTML = "";
|
||||
});
|
||||
function field(template: string, setup = () => ({})) {
|
||||
const w = mount(
|
||||
defineComponent({ components: { DateFieldFoundation }, template, setup }),
|
||||
{ attachTo: document.body },
|
||||
);
|
||||
wrappers.push(w);
|
||||
return w;
|
||||
}
|
||||
const initial = new CalendarDate(2024, 2, 10);
|
||||
const segment = (w: ReturnType<typeof mount>, part: string) =>
|
||||
w.get<HTMLElement>(`[data-reka-date-field-segment="${part}"]`);
|
||||
const day = (w: ReturnType<typeof mount>, value: string) =>
|
||||
w.get<HTMLElement>(
|
||||
`[data-reka-calendar-cell-trigger][data-value="${value}"]:not([data-outside-view])`,
|
||||
);
|
||||
function calendar(props: Record<string, unknown> = {}) {
|
||||
const w = mount(CalendarFoundation, {
|
||||
props: { defaultPlaceholder: initial, ...props },
|
||||
attachTo: document.body,
|
||||
});
|
||||
wrappers.push(w);
|
||||
return w;
|
||||
}
|
||||
describe("installed Reka DateField capability probes (not public acceptance)", () => {
|
||||
it("edits a day while retaining CalendarDate type and native date serialization", async () => {
|
||||
const w = field(
|
||||
'<form><DateFieldFoundation :default-value="initial" name="date"/></form>',
|
||||
() => ({ initial }),
|
||||
);
|
||||
await segment(w, "day").trigger("keydown", { key: "ArrowUp" });
|
||||
await flushPromises();
|
||||
const emitted = w
|
||||
.getComponent(DateFieldFoundation)
|
||||
.emitted("update:modelValue")!
|
||||
.at(-1)![0] as CalendarDate;
|
||||
expect(emitted).toBeInstanceOf(CalendarDate);
|
||||
expect(emitted.toString()).toBe("2024-02-11");
|
||||
expect(
|
||||
new FormData(w.get("form").element as HTMLFormElement).get("date"),
|
||||
).toBe("2024-02-11");
|
||||
});
|
||||
it("documents that raw DateField reset does not restore displayed segments", async () => {
|
||||
const w = field(
|
||||
'<form><DateFieldFoundation :default-value="initial" name="date"/></form>',
|
||||
() => ({ initial }),
|
||||
);
|
||||
await segment(w, "day").trigger("keydown", { key: "ArrowUp" });
|
||||
(w.get("form").element as HTMLFormElement).reset();
|
||||
await flushPromises();
|
||||
expect(segment(w, "day").text()).toBe("11");
|
||||
});
|
||||
it("documents controlled rejection leaving optimistic segment text", async () => {
|
||||
const w = field('<DateFieldFoundation :model-value="initial"/>', () => ({
|
||||
initial,
|
||||
}));
|
||||
await segment(w, "day").trigger("keydown", { key: "ArrowUp" });
|
||||
await flushPromises();
|
||||
expect(segment(w, "day").text()).toBe("11");
|
||||
expect(w.get("input").element.value).toBe("2024-02-10");
|
||||
});
|
||||
it("retains seconds in the emitted datetime but truncates native minute submission", async () => {
|
||||
const value = new CalendarDateTime(2024, 2, 10, 13, 14, 45, 123);
|
||||
const w = field(
|
||||
'<form><DateFieldFoundation :default-value="value" granularity="minute" name="date"/></form>',
|
||||
() => ({ value }),
|
||||
);
|
||||
await segment(w, "day").trigger("keydown", { key: "ArrowUp" });
|
||||
const next = w
|
||||
.getComponent(DateFieldFoundation)
|
||||
.emitted("update:modelValue")!
|
||||
.at(-1)![0] as CalendarDateTime;
|
||||
expect(next.second).toBe(45);
|
||||
expect(next.millisecond).toBe(123);
|
||||
expect(
|
||||
new FormData(w.get("form").element as HTMLFormElement).get("date"),
|
||||
).toBe("2024-02-11T13:14");
|
||||
});
|
||||
it("documents native datetime-local losing zone metadata", () => {
|
||||
const value = parseZonedDateTime(
|
||||
"2024-03-10T01:30-08:00[America/Los_Angeles]",
|
||||
);
|
||||
const w = field(
|
||||
'<DateFieldFoundation :default-value="value" name="date"/>',
|
||||
() => ({ value }),
|
||||
);
|
||||
expect(w.get("input").element.value).toBe("2024-03-10T01:30");
|
||||
expect(w.text()).toContain("PST");
|
||||
});
|
||||
it("documents alternate-calendar native fields not using ISO Gregorian serialization", () => {
|
||||
const value = toCalendar(initial, new PersianCalendar());
|
||||
const w = field(
|
||||
'<DateFieldFoundation :default-value="value" locale="fa-IR-u-ca-persian" name="date"/>',
|
||||
() => ({ value }),
|
||||
);
|
||||
expect(w.get("input").element.value).not.toBe(value.toString());
|
||||
});
|
||||
it("supports native required and disabled omission but readonly remains submitted", () => {
|
||||
const required = field(
|
||||
'<form><DateFieldFoundation required name="date" :default-placeholder="initial"/></form>',
|
||||
() => ({ initial }),
|
||||
);
|
||||
expect(
|
||||
required.get<HTMLInputElement>("input").element.checkValidity(),
|
||||
).toBe(false);
|
||||
const readonly = field(
|
||||
'<form><DateFieldFoundation readonly name="date" :default-value="initial"/></form>',
|
||||
() => ({ initial }),
|
||||
);
|
||||
expect(segment(readonly, "day").attributes("contenteditable")).toBe(
|
||||
"false",
|
||||
);
|
||||
expect(
|
||||
new FormData(readonly.get("form").element as HTMLFormElement).get("date"),
|
||||
).toBe("2024-02-10");
|
||||
const disabled = field(
|
||||
'<form><DateFieldFoundation disabled name="date" :default-value="initial"/></form>',
|
||||
() => ({ initial }),
|
||||
);
|
||||
expect(
|
||||
new FormData(disabled.get("form").element as HTMLFormElement).has("date"),
|
||||
).toBe(false);
|
||||
});
|
||||
it("updates segment ordering and content when locale changes", async () => {
|
||||
const locale = ref("en-US");
|
||||
const w = field(
|
||||
'<DateFieldFoundation :locale="locale" :default-value="initial"/>',
|
||||
() => ({ locale, initial }),
|
||||
);
|
||||
const parts = () =>
|
||||
w
|
||||
.findAll('[role="spinbutton"]')
|
||||
.map((e) => e.attributes("data-reka-date-field-segment"));
|
||||
expect(parts()).toEqual(["month", "day", "year"]);
|
||||
locale.value = "zh-CN";
|
||||
await flushPromises();
|
||||
expect(parts()).toEqual(["year", "month", "day"]);
|
||||
});
|
||||
});
|
||||
describe("installed Reka Calendar capability probes (not public acceptance)", () => {
|
||||
it("renders leap-month dates, skips disabled days and focuses unavailable days", async () => {
|
||||
const w = calendar({
|
||||
defaultValue: initial,
|
||||
isDateDisabled: (value: CalendarDate) => value.day === 11,
|
||||
isDateUnavailable: (value: CalendarDate) => value.day === 12,
|
||||
});
|
||||
expect(day(w, "2024-02-29").element.textContent).toContain("29");
|
||||
day(w, "2024-02-10").element.focus();
|
||||
await day(w, "2024-02-10").trigger("keydown", {
|
||||
key: "ArrowRight",
|
||||
code: "ArrowRight",
|
||||
});
|
||||
await flushPromises();
|
||||
expect(document.activeElement).toBe(day(w, "2024-02-12").element);
|
||||
await day(w, "2024-02-12").trigger("click");
|
||||
expect(w.emitted("update:modelValue")).toBeUndefined();
|
||||
});
|
||||
it("keeps a controlled rejected selection visually accepted only by the parent", async () => {
|
||||
const w = calendar({ modelValue: initial });
|
||||
await day(w, "2024-02-13").trigger("click");
|
||||
await day(w, "2024-02-13").trigger("click");
|
||||
expect(w.emitted("update:modelValue")).toHaveLength(2);
|
||||
expect(day(w, "2024-02-10").attributes("data-selected")).toBe("true");
|
||||
expect(day(w, "2024-02-13").attributes("data-selected")).toBeUndefined();
|
||||
});
|
||||
it("supports multiple dates at runtime despite the scalar emit declaration", async () => {
|
||||
const w = calendar({ multiple: true, modelValue: [initial] });
|
||||
await day(w, "2024-02-13").trigger("click");
|
||||
const next = w.emitted("update:modelValue")!.at(-1)![0] as CalendarDate[];
|
||||
expect(Array.isArray(next)).toBe(true);
|
||||
expect(next.map((v) => v.toString())).toEqual(["2024-02-10", "2024-02-13"]);
|
||||
});
|
||||
it("respects min/max and allows readonly navigation without selection", async () => {
|
||||
const w = calendar({
|
||||
readonly: true,
|
||||
minValue: initial,
|
||||
maxValue: initial.add({ days: 5 }),
|
||||
});
|
||||
expect(day(w, "2024-02-09").attributes("data-disabled")).toBeDefined();
|
||||
await day(w, "2024-02-13").trigger("click");
|
||||
expect(w.emitted("update:modelValue")).toBeUndefined();
|
||||
});
|
||||
it("documents cancellation happening after the internal keyboard focus movement", async () => {
|
||||
const w = calendar({
|
||||
defaultValue: initial,
|
||||
onKeydown: (event: KeyboardEvent) => event.preventDefault(),
|
||||
});
|
||||
day(w, "2024-02-10").element.focus();
|
||||
await day(w, "2024-02-10").trigger("keydown", {
|
||||
key: "ArrowRight",
|
||||
code: "ArrowRight",
|
||||
});
|
||||
await flushPromises();
|
||||
expect(document.activeElement).toBe(day(w, "2024-02-11").element);
|
||||
});
|
||||
it("supports two month grids and fixed six-week views", () => {
|
||||
const w = calendar({ numberOfMonths: 2, fixedWeeks: true });
|
||||
expect(w.findAll("table")).toHaveLength(2);
|
||||
expect(w.findAll("tbody tr")).toHaveLength(12);
|
||||
});
|
||||
});
|
||||
|
||||
it("records that an explicit Gregorian placeholder keeps a Gregorian month grid under an Indian locale", () => {
|
||||
const w = calendar({ defaultValue: initial, locale: "hi-IN-u-ca-indian" });
|
||||
const current = w.findAll(
|
||||
"[data-reka-calendar-cell-trigger]:not([data-outside-view])",
|
||||
);
|
||||
expect(current[0].attributes("data-value")).toBe("2024-02-01");
|
||||
expect(current).toHaveLength(29);
|
||||
});
|
||||
@@ -0,0 +1,192 @@
|
||||
import { afterEach, describe, it, expect } from "vitest";
|
||||
import { mount, flushPromises } from "@vue/test-utils";
|
||||
import { createSSRApp, defineComponent, ref } from "vue";
|
||||
import { renderToString } from "@vue/server-renderer";
|
||||
import { CalendarDate, parseZonedDateTime } from "@internationalized/date";
|
||||
import Field from "../packages/vue/tests/fixtures/AcceptedDateFieldFoundation.vue";
|
||||
const wrappers: ReturnType<typeof mount>[] = [];
|
||||
afterEach(() => {
|
||||
wrappers.splice(0).forEach((w) => w.unmount());
|
||||
document.body.innerHTML = "";
|
||||
});
|
||||
const initial = new CalendarDate(2024, 2, 10);
|
||||
function fixture(template: string, setup = () => ({})) {
|
||||
const w = mount(defineComponent({ components: { Field }, template, setup }), {
|
||||
attachTo: document.body,
|
||||
});
|
||||
wrappers.push(w);
|
||||
return w;
|
||||
}
|
||||
const day = (w: ReturnType<typeof mount>) =>
|
||||
w.get('[data-reka-date-field-segment="day"]');
|
||||
const data = (w: ReturnType<typeof mount>) =>
|
||||
new FormData(w.get("form").element as HTMLFormElement).getAll("date");
|
||||
describe("private accepted date wire adapter", () => {
|
||||
it("restores rejected segments and emits identical retries without native value drift", async () => {
|
||||
const w = fixture(
|
||||
'<form><Field :model-value="initial" name="date"/></form>',
|
||||
() => ({ initial }),
|
||||
);
|
||||
await day(w).trigger("keydown", { key: "ArrowUp" });
|
||||
await flushPromises();
|
||||
expect(day(w).text()).toBe("10");
|
||||
expect(data(w)).toEqual(["2024-02-10"]);
|
||||
await day(w).trigger("keydown", { key: "ArrowUp" });
|
||||
await flushPromises();
|
||||
const events = w.getComponent(Field).emitted("update:modelValue")!;
|
||||
expect(events.map((args) => (args[0] as CalendarDate).toString())).toEqual([
|
||||
"2024-02-11",
|
||||
"2024-02-11",
|
||||
]);
|
||||
expect(initial.day).toBe(10);
|
||||
});
|
||||
it("accepts parent replacements and updates full native submission once", async () => {
|
||||
const value = ref(initial);
|
||||
const w = fixture(
|
||||
'<form><Field v-model="value" name="date"/></form>',
|
||||
() => ({ value }),
|
||||
);
|
||||
await day(w).trigger("keydown", { key: "ArrowUp" });
|
||||
await flushPromises();
|
||||
expect(day(w).text()).toBe("11");
|
||||
expect(data(w)).toEqual(["2024-02-11"]);
|
||||
value.value = initial.add({ days: 10 });
|
||||
await flushPromises();
|
||||
expect(day(w).text()).toBe("20");
|
||||
});
|
||||
it("resets uncontrolled values and displayed segments without synthetic change events", async () => {
|
||||
const w = fixture(
|
||||
'<form><Field :default-value="initial" name="date"/></form>',
|
||||
() => ({ initial }),
|
||||
);
|
||||
await day(w).trigger("keydown", { key: "ArrowUp" });
|
||||
await flushPromises();
|
||||
(w.get("form").element as HTMLFormElement).reset();
|
||||
await flushPromises();
|
||||
expect(day(w).text()).toBe("10");
|
||||
expect(data(w)).toEqual(["2024-02-10"]);
|
||||
expect(w.getComponent(Field).emitted("update:modelValue")).toHaveLength(1);
|
||||
});
|
||||
it("keeps accepted parent values on controlled reset", async () => {
|
||||
const value = ref(initial);
|
||||
const w = fixture(
|
||||
'<form><Field v-model="value" name="date"/></form>',
|
||||
() => ({ value }),
|
||||
);
|
||||
value.value = initial.add({ days: 2 });
|
||||
await flushPromises();
|
||||
(w.get("form").element as HTMLFormElement).reset();
|
||||
await flushPromises();
|
||||
expect(day(w).text()).toBe("12");
|
||||
expect(data(w)).toEqual(["2024-02-12"]);
|
||||
});
|
||||
it("honors cancelled reset", async () => {
|
||||
const w = fixture(
|
||||
'<form @reset.prevent><Field :default-value="initial" name="date"/></form>',
|
||||
() => ({ initial }),
|
||||
);
|
||||
await day(w).trigger("keydown", { key: "ArrowUp" });
|
||||
await flushPromises();
|
||||
(w.get("form").element as HTMLFormElement).reset();
|
||||
await flushPromises();
|
||||
expect(day(w).text()).toBe("11");
|
||||
});
|
||||
it("submits complete ZonedDateTime including seconds and time zone", () => {
|
||||
const value = parseZonedDateTime(
|
||||
"2024-03-10T01:30:45-08:00[America/Los_Angeles]",
|
||||
);
|
||||
const w = fixture(
|
||||
'<form><Field :default-value="value" name="date"/></form>',
|
||||
() => ({ value }),
|
||||
);
|
||||
expect(data(w)).toEqual([value.toString()]);
|
||||
});
|
||||
it("treats explicit undefined as controlled empty rather than defaultValue", () => {
|
||||
const w = fixture(
|
||||
'<form><Field :model-value="undefined" :default-value="initial" :default-placeholder="initial" name="date"/></form>',
|
||||
() => ({ initial }),
|
||||
);
|
||||
expect(day(w).attributes("data-placeholder")).toBeDefined();
|
||||
expect(data(w)).toEqual([""]);
|
||||
});
|
||||
it("blocks readonly edits and keeps the accepted submission", async () => {
|
||||
const w = fixture(
|
||||
'<form><Field readonly :default-value="initial" name="date"/></form>',
|
||||
() => ({ initial }),
|
||||
);
|
||||
await day(w).trigger("keydown", { key: "ArrowUp" });
|
||||
expect(data(w)).toEqual(["2024-02-10"]);
|
||||
expect(w.getComponent(Field).emitted("update:modelValue")).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
it("omits disabled native values", () => {
|
||||
const w = fixture(
|
||||
'<form><Field disabled :default-value="initial" name="date"/></form>',
|
||||
() => ({ initial }),
|
||||
);
|
||||
expect(data(w)).toEqual([]);
|
||||
});
|
||||
it("hydrates the accepted date and segment identities without mismatch", async () => {
|
||||
const Component = defineComponent({
|
||||
components: { Field },
|
||||
setup: () => ({ initial }),
|
||||
template: '<Field :default-value="initial" name="date"/>',
|
||||
});
|
||||
const host = document.createElement("div");
|
||||
host.innerHTML = await renderToString(createSSRApp(Component));
|
||||
document.body.append(host);
|
||||
const before = host.querySelector('[data-reka-date-field-segment="day"]');
|
||||
const warnings: string[] = [];
|
||||
const app = createSSRApp(Component);
|
||||
app.config.warnHandler = (message) => warnings.push(message);
|
||||
app.mount(host);
|
||||
await flushPromises();
|
||||
try {
|
||||
expect(warnings).toEqual([]);
|
||||
expect(host.querySelector('[data-reka-date-field-segment="day"]')).toBe(
|
||||
before,
|
||||
);
|
||||
expect(before?.textContent).toBe("10");
|
||||
} finally {
|
||||
app.unmount();
|
||||
}
|
||||
});
|
||||
|
||||
it("preserves partial drafts but clears a completed rejected empty proposal without losing focus", async () => {
|
||||
const w = fixture(
|
||||
'<form><Field :model-value="null" :default-placeholder="initial" name="date"/></form>',
|
||||
() => ({ initial }),
|
||||
);
|
||||
const month = () => w.get('[data-reka-date-field-segment="month"]');
|
||||
const year = () => w.get('[data-reka-date-field-segment="year"]');
|
||||
await month().trigger("keydown", { key: "ArrowUp" });
|
||||
await flushPromises();
|
||||
expect(month().text()).toBe("2");
|
||||
expect(data(w)).toEqual([""]);
|
||||
await day(w).trigger("keydown", { key: "ArrowUp" });
|
||||
(year().element as HTMLElement).focus();
|
||||
const focused = year().element;
|
||||
await year().trigger("keydown", { key: "ArrowUp" });
|
||||
await flushPromises();
|
||||
expect(w.getComponent(Field).emitted("update:modelValue")).toHaveLength(1);
|
||||
expect(month().attributes("data-placeholder")).toBeDefined();
|
||||
expect(day(w).attributes("data-placeholder")).toBeDefined();
|
||||
expect(year().attributes("data-placeholder")).toBeDefined();
|
||||
expect(document.activeElement).toBe(focused);
|
||||
for (const part of [month(), day(w), year()])
|
||||
await part.trigger("keydown", { key: "ArrowUp" });
|
||||
await flushPromises();
|
||||
expect(w.getComponent(Field).emitted("update:modelValue")).toHaveLength(2);
|
||||
});
|
||||
it("clears an incomplete uncontrolled draft on reset", async () => {
|
||||
const w = fixture(
|
||||
'<form><Field :default-placeholder="initial" name="date"/></form>',
|
||||
() => ({ initial }),
|
||||
);
|
||||
await day(w).trigger("keydown", { key: "ArrowUp" });
|
||||
expect(day(w).text()).toBe("10");
|
||||
(w.get("form").element as HTMLFormElement).reset();
|
||||
await flushPromises();
|
||||
expect(day(w).attributes("data-placeholder")).toBeDefined();
|
||||
});
|
||||
@@ -0,0 +1,107 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import {
|
||||
CalendarDate,
|
||||
CalendarDateTime,
|
||||
parseZonedDateTime,
|
||||
toCalendar,
|
||||
PersianCalendar,
|
||||
} from "@internationalized/date";
|
||||
import {
|
||||
dateForLocale,
|
||||
copyDateValue,
|
||||
dateValueKey,
|
||||
sameDateValue,
|
||||
copyDateValues,
|
||||
serializeDateValue,
|
||||
calendarDayState,
|
||||
copyDateRange,
|
||||
calendarRangeStatus,
|
||||
} from "../packages/vue/src/components/date/value";
|
||||
const day = new CalendarDate(2024, 2, 29);
|
||||
describe("private calendar date boundary", () => {
|
||||
it("copies dates without mutating caller or losing date class", () => {
|
||||
const copy = copyDateValue(day);
|
||||
expect(copy).not.toBe(day);
|
||||
expect(copy).toBeInstanceOf(CalendarDate);
|
||||
expect(copy.add({ years: 1 }).toString()).toBe("2025-02-28");
|
||||
expect(day.toString()).toBe("2024-02-29");
|
||||
});
|
||||
it("keeps null/undefined empty and distinguishes date from midnight datetime", () => {
|
||||
expect(copyDateValue(null)).toBeNull();
|
||||
expect(copyDateValue(undefined)).toBeUndefined();
|
||||
expect(sameDateValue(null, undefined)).toBe(true);
|
||||
expect(sameDateValue(day, new CalendarDateTime(2024, 2, 29))).toBe(false);
|
||||
});
|
||||
it("retains sub-minute precision independently from display granularity", () => {
|
||||
const value = new CalendarDateTime(2024, 2, 29, 13, 14, 15, 123);
|
||||
expect(serializeDateValue(copyDateValue(value))).toBe(
|
||||
"2024-02-29T13:14:15.123",
|
||||
);
|
||||
});
|
||||
it("retains DST offset, zone and wall-clock value", () => {
|
||||
const value = parseZonedDateTime(
|
||||
"2024-03-10T01:30-08:00[America/Los_Angeles]",
|
||||
);
|
||||
const copy = copyDateValue(value);
|
||||
expect(copy.timeZone).toBe(value.timeZone);
|
||||
expect(copy.offset).toBe(-28800000);
|
||||
expect(copy.add({ hours: 1 }).hour).toBe(3);
|
||||
expect(serializeDateValue(copy)).toContain("-08:00[America/Los_Angeles]");
|
||||
});
|
||||
it("keeps alternate calendar identity even when ISO serialization is equal", () => {
|
||||
const persian = toCalendar(day, new PersianCalendar());
|
||||
expect(persian.toString()).toBe(day.toString());
|
||||
expect(sameDateValue(day, persian)).toBe(false);
|
||||
expect(copyDateValue(persian).calendar.identifier).toBe("persian");
|
||||
});
|
||||
it("deduplicates copied values without sharing mutable date objects", () => {
|
||||
const values = copyDateValues([day, day.copy(), day.add({ days: 1 })]);
|
||||
expect(values).toHaveLength(2);
|
||||
expect(values[0]).not.toBe(day);
|
||||
expect(dateValueKey(values[0])).toBe(dateValueKey(day));
|
||||
});
|
||||
it("keeps unavailable distinct from disabled calendar days", () => {
|
||||
expect(calendarDayState(day, { isDateUnavailable: () => true })).toEqual({
|
||||
isDisabled: false,
|
||||
isUnavailable: true,
|
||||
isSelectable: false,
|
||||
});
|
||||
expect(calendarDayState(day, { isDateDisabled: () => true })).toEqual({
|
||||
isDisabled: true,
|
||||
isUnavailable: false,
|
||||
isSelectable: false,
|
||||
});
|
||||
});
|
||||
it("compares calendar bounds by local day including equivalent alternate calendars", () => {
|
||||
expect(
|
||||
calendarDayState(toCalendar(day, new PersianCalendar()), {
|
||||
minValue: day,
|
||||
maxValue: day,
|
||||
}).isSelectable,
|
||||
).toBe(true);
|
||||
expect(
|
||||
calendarDayState(day, { minValue: day.add({ days: 1 }) }).isDisabled,
|
||||
).toBe(true);
|
||||
});
|
||||
it("copies ranges and preserves incomplete drafts", () => {
|
||||
const range = copyDateRange({ start: day, end: null });
|
||||
expect(range.start).not.toBe(day);
|
||||
expect(calendarRangeStatus(range)).toBe("incomplete");
|
||||
expect(calendarRangeStatus({ start: null, end: null })).toBe("empty");
|
||||
expect(
|
||||
calendarRangeStatus({ start: day, end: day.subtract({ days: 1 }) }),
|
||||
).toBe("inverted");
|
||||
expect(calendarRangeStatus({ start: day, end: day })).toBe("valid");
|
||||
});
|
||||
});
|
||||
|
||||
it("converts the calendar for locale display without altering the incoming model or instant", () => {
|
||||
const original = parseZonedDateTime(
|
||||
"2024-03-10T01:30-08:00[America/Los_Angeles]",
|
||||
);
|
||||
const indian = dateForLocale(original, "hi-IN-u-ca-indian");
|
||||
expect(indian.calendar.identifier).toBe("indian");
|
||||
expect(indian.timeZone).toBe(original.timeZone);
|
||||
expect(indian.toString()).toBe(original.toString());
|
||||
expect(original.calendar.identifier).toBe("gregory");
|
||||
});
|
||||
@@ -21,3 +21,5 @@ LISTBOX-01 增加 `consume-list-box.mjs` / `list-box-contract.ts`。同样复制
|
||||
M33–M34 使用 consume-m33-m34.mjs / m33-m34-contract.ts;同样复制到独立 tarball 消费工程,分别运行 node 与两种解析模式的 tsc。包括所有公开部件、真正 node SSR、CSS 关键帧与策略/尺寸/方向的正反类型检查。集成验证目录为 /private/tmp/heroui-m33-consumer,不复用其他并行任务的临时产物。
|
||||
|
||||
SELECT-01 增加 `consume-select.mjs` / `select-contract.ts`。新 tarball 安装后运行 ESM/SSR/CSS 脚本,两种模块解析模式都纳入类型正反例;数字/字符串/空 key、六部件、validate 与事件载荷推断不应退化。保留旧组件消费回归。
|
||||
|
||||
DATE-02 增加 `consume-date-field.mjs` / `date-field-contract.ts`。独立消费者显式安装 `@internationalized/date@3.12.4`,运行完整 ISO 时区提交/SSR/样式检查,分别用 NodeNext 与 bundler 验证 DateValue、粒度、变体、范围和 segment 的正反类型,不从源码 alias 取公共类型。
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { createSSRApp, h } from "vue";
|
||||
import { renderToString } from "@vue/server-renderer";
|
||||
import { parseZonedDateTime } from "@internationalized/date";
|
||||
import * as c from "@heroui-vue/components";
|
||||
import { readFile } from "node:fs/promises";
|
||||
for (const key of [
|
||||
"DateField",
|
||||
"DateFieldRoot",
|
||||
"DateFieldGroup",
|
||||
"DateFieldInput",
|
||||
"DateFieldSegment",
|
||||
"DateFieldPrefix",
|
||||
"DateFieldSuffix",
|
||||
"DateFieldInputContainer",
|
||||
"DateInputGroup",
|
||||
"DateInputGroupInput",
|
||||
"DateInputGroupSegment",
|
||||
"DateInputGroupInputContainer",
|
||||
"DateInputGroupPrefix",
|
||||
"DateInputGroupSuffix",
|
||||
])
|
||||
assert.ok(c[key], key);
|
||||
const date = parseZonedDateTime(
|
||||
"2024-03-10T01:30:45-08:00[America/Los_Angeles]",
|
||||
);
|
||||
const html = await renderToString(
|
||||
createSSRApp({
|
||||
render: () =>
|
||||
h(
|
||||
c.DateField,
|
||||
{ defaultValue: date, granularity: "minute", name: "date" },
|
||||
() => [
|
||||
h(c.Label, () => "Date"),
|
||||
h(c.DateFieldGroup, () => h(c.DateFieldInput)),
|
||||
h(c.Description, () => "Help"),
|
||||
],
|
||||
),
|
||||
}),
|
||||
);
|
||||
assert.ok(
|
||||
html.includes('value="2024-03-10T01:30:45-08:00[America/Los_Angeles]"'),
|
||||
);
|
||||
assert.equal((html.match(/name="date"/g) || []).length, 1);
|
||||
assert.ok(html.includes("aria-labelledby="));
|
||||
assert.ok(html.includes("aria-describedby="));
|
||||
const css = await readFile(
|
||||
import.meta.resolve("@heroui-vue/styles/css").replace("file://", ""),
|
||||
"utf8",
|
||||
);
|
||||
for (const name of [
|
||||
"hv-date-field",
|
||||
"hv-date-input-group",
|
||||
"hv-date-input-group__segment",
|
||||
"hv-date-input-group--secondary",
|
||||
])
|
||||
assert.ok(css.includes(name), name);
|
||||
console.log("DateField tarball ESM/SSR/CSS: passed");
|
||||
@@ -0,0 +1,55 @@
|
||||
import {
|
||||
DateField,
|
||||
DateFieldGroup,
|
||||
DateFieldInput,
|
||||
DateFieldSegment,
|
||||
DateInputGroup,
|
||||
type DateFieldProps,
|
||||
type DateFieldGroupProps,
|
||||
type DateFieldSegmentProps,
|
||||
type DateSegment,
|
||||
} from "@heroui-vue/components";
|
||||
import { parseDate } from "@internationalized/date";
|
||||
const date = parseDate("2024-02-10");
|
||||
const props: DateFieldProps = {
|
||||
modelValue: date,
|
||||
granularity: "minute",
|
||||
hourCycle: 24,
|
||||
placeholderValue: date,
|
||||
validate: (value) => (value ? value.toString() : "Missing"),
|
||||
};
|
||||
const group: DateFieldGroupProps = { variant: "secondary", fullWidth: true };
|
||||
// @ts-expect-error DateValue is not a date string
|
||||
const wrongDate: DateFieldProps = { modelValue: "2024-02-10" };
|
||||
// @ts-expect-error no milliseconds granularity
|
||||
const wrongGranularity: DateFieldProps = { granularity: "millisecond" };
|
||||
// @ts-expect-error no arbitrary variants
|
||||
const wrongVariant: DateFieldGroupProps = { variant: "outline" };
|
||||
// @ts-expect-error a DateField is not a range
|
||||
const wrongRange: DateFieldProps = { modelValue: [date, date] };
|
||||
const segment: DateSegment = {
|
||||
part: "day",
|
||||
type: "day",
|
||||
text: "10",
|
||||
value: "10",
|
||||
isEditable: true,
|
||||
isPlaceholder: false,
|
||||
};
|
||||
const segmentProps: DateFieldSegmentProps = { segment };
|
||||
// @ts-expect-error DateSegment has real properties
|
||||
const wrongSegment: DateFieldSegmentProps = { segment: "day" };
|
||||
void [
|
||||
DateField,
|
||||
DateFieldGroup,
|
||||
DateFieldInput,
|
||||
DateFieldSegment,
|
||||
DateInputGroup,
|
||||
props,
|
||||
group,
|
||||
segmentProps,
|
||||
wrongDate,
|
||||
wrongGranularity,
|
||||
wrongVariant,
|
||||
wrongRange,
|
||||
wrongSegment,
|
||||
];
|
||||
Reference in New Issue
Block a user