Compare commits
4 Commits
0b89f02745
...
2c6d871354
| Author | SHA1 | Date | |
|---|---|---|---|
| 2c6d871354 | |||
| 462044c3b8 | |||
| 1029444a98 | |||
| 2e3fdd4800 |
@@ -288,8 +288,8 @@ Calendar 保留固定基线的主要属性与部件,以 Vue 模型、具名部
|
|||||||
### Related packages
|
### Related packages
|
||||||
|
|
||||||
- [`@internationalized/date`](https://react-aria.adobe.com/internationalized/date/) — 所有日期组件使用的日期类型(`CalendarDate`、`CalendarDateTime`、`ZonedDateTime`)与工具
|
- [`@internationalized/date`](https://react-aria.adobe.com/internationalized/date/) — 所有日期组件使用的日期类型(`CalendarDate`、`CalendarDateTime`、`ZonedDateTime`)与工具
|
||||||
- 本库 `ConfigProvider` — 覆盖子树的 locale
|
- 本库 `ConfigProvider` — 覆盖子树的 locale 与布局方向
|
||||||
- 本库 `ConfigProvider` — 统一 locale 与布局方向
|
- 本库 `useLocale()` — 读取当前 `ConfigProvider` 的 `locale` / `dir`(未包裹时回退 `en-US` / `ltr`,与组件继承链一致),供 `startOfWeek`、`isWeekend`、`DateFormatter` 等本地化计算使用
|
||||||
|
|
||||||
## Vue 模型、DOM 与当前差异
|
## Vue 模型、DOM 与当前差异
|
||||||
|
|
||||||
|
|||||||
@@ -348,6 +348,7 @@ DateRangePicker 继承固定基线的双端点日期字段、范围日历与弹
|
|||||||
|
|
||||||
- [`@internationalized/date`](https://react-aria.adobe.com/internationalized/date/) — 所有日期组件使用的日期类型(`CalendarDate`、`CalendarDateTime`、`ZonedDateTime`)与工具
|
- [`@internationalized/date`](https://react-aria.adobe.com/internationalized/date/) — 所有日期组件使用的日期类型(`CalendarDate`、`CalendarDateTime`、`ZonedDateTime`)与工具
|
||||||
- 本库 `ConfigProvider` — 为子树覆盖 locale、书写方向与 Portal 目标
|
- 本库 `ConfigProvider` — 为子树覆盖 locale、书写方向与 Portal 目标
|
||||||
|
- 本库 `useLocale()` — 读取当前 `ConfigProvider` 的 `locale` / `dir`(未包裹时回退 `en-US` / `ltr`),供 `DateFormatter`、`startOfWeek`、`isWeekend` 等本地化计算使用
|
||||||
|
|
||||||
## 相关组件
|
## 相关组件
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import {
|
|||||||
CalendarCellIndicator,
|
CalendarCellIndicator,
|
||||||
Button,
|
Button,
|
||||||
Description,
|
Description,
|
||||||
|
useLocale,
|
||||||
} from "@heroui-vue/components";
|
} from "@heroui-vue/components";
|
||||||
import { shallowRef, ref } from "vue";
|
import { shallowRef, ref } from "vue";
|
||||||
import {
|
import {
|
||||||
@@ -24,8 +25,9 @@ const selectedDate = shallowRef<DateValue | null>(null);
|
|||||||
const booking = ref("");
|
const booking = ref("");
|
||||||
const now = today(getLocalTimeZone());
|
const now = today(getLocalTimeZone());
|
||||||
const bookedDates = [5, 6, 12, 13, 14, 20];
|
const bookedDates = [5, 6, 12, 13, 14, 20];
|
||||||
|
const { locale } = useLocale();
|
||||||
const isDateUnavailable = (date: DateValue) =>
|
const isDateUnavailable = (date: DateValue) =>
|
||||||
isWeekend(date, "en-US") || bookedDates.includes(date.day);
|
isWeekend(date, locale.value) || bookedDates.includes(date.day);
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<div class="flex flex-col items-center gap-4">
|
<div class="flex flex-col items-center gap-4">
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import {
|
|||||||
Button,
|
Button,
|
||||||
ButtonGroup,
|
ButtonGroup,
|
||||||
Description,
|
Description,
|
||||||
|
useLocale,
|
||||||
} from "@heroui-vue/components";
|
} from "@heroui-vue/components";
|
||||||
import { shallowRef } from "vue";
|
import { shallowRef } from "vue";
|
||||||
import {
|
import {
|
||||||
@@ -24,6 +25,7 @@ import {
|
|||||||
} from "@internationalized/date";
|
} from "@internationalized/date";
|
||||||
const value = shallowRef<DateValue | null>(null);
|
const value = shallowRef<DateValue | null>(null);
|
||||||
const focusedDate = shallowRef<DateValue>(parseDate("2025-12-25"));
|
const focusedDate = shallowRef<DateValue>(parseDate("2025-12-25"));
|
||||||
|
const { locale } = useLocale();
|
||||||
function jump(date: DateValue) {
|
function jump(date: DateValue) {
|
||||||
value.value = date;
|
value.value = date;
|
||||||
focusedDate.value = date;
|
focusedDate.value = date;
|
||||||
@@ -33,7 +35,7 @@ function jump(date: DateValue) {
|
|||||||
<div class="flex flex-col items-center gap-4">
|
<div class="flex flex-col items-center gap-4">
|
||||||
<ButtonGroup full-width size="sm" variant="tertiary">
|
<ButtonGroup full-width size="sm" variant="tertiary">
|
||||||
<Button @click="jump(today(getLocalTimeZone()))">今天</Button>
|
<Button @click="jump(today(getLocalTimeZone()))">今天</Button>
|
||||||
<Button @click="jump(startOfWeek(today(getLocalTimeZone()), 'en-US'))">
|
<Button @click="jump(startOfWeek(today(getLocalTimeZone()), locale))">
|
||||||
本周
|
本周
|
||||||
</Button>
|
</Button>
|
||||||
<Button @click="jump(startOfMonth(today(getLocalTimeZone())))">
|
<Button @click="jump(startOfMonth(today(getLocalTimeZone())))">
|
||||||
@@ -60,7 +62,24 @@ function jump(date: DateValue) {
|
|||||||
</CalendarGrid>
|
</CalendarGrid>
|
||||||
</Calendar>
|
</Calendar>
|
||||||
<Description class="text-center">
|
<Description class="text-center">
|
||||||
{{ value ? `已选择:${value.toString()}` : "未选择日期" }}
|
已选日期:{{ value ? value.toString() : "(未选)" }}
|
||||||
</Description>
|
</Description>
|
||||||
|
<div class="flex gap-2">
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
variant="secondary"
|
||||||
|
@click="jump(today(getLocalTimeZone()))"
|
||||||
|
>
|
||||||
|
设为今天
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
variant="secondary"
|
||||||
|
@click="jump(parseDate('2025-12-25'))"
|
||||||
|
>
|
||||||
|
设为圣诞节
|
||||||
|
</Button>
|
||||||
|
<Button size="sm" variant="tertiary" @click="value = null">清空</Button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -9,10 +9,17 @@ import {
|
|||||||
CalendarGridBody,
|
CalendarGridBody,
|
||||||
CalendarHeaderCell,
|
CalendarHeaderCell,
|
||||||
CalendarCell,
|
CalendarCell,
|
||||||
|
Description,
|
||||||
} from "@heroui-vue/components";
|
} from "@heroui-vue/components";
|
||||||
|
import { getLocalTimeZone, today } from "@internationalized/date";
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<Calendar aria-label="活动日期" is-disabled>
|
<div class="flex flex-col items-center gap-4">
|
||||||
|
<Calendar
|
||||||
|
aria-label="活动日期"
|
||||||
|
is-disabled
|
||||||
|
:default-value="today(getLocalTimeZone())"
|
||||||
|
>
|
||||||
<CalendarHeader>
|
<CalendarHeader>
|
||||||
<CalendarHeading />
|
<CalendarHeading />
|
||||||
<CalendarNavButton slot="previous" />
|
<CalendarNavButton slot="previous" />
|
||||||
@@ -27,4 +34,6 @@ import {
|
|||||||
</CalendarGridBody>
|
</CalendarGridBody>
|
||||||
</CalendarGrid>
|
</CalendarGrid>
|
||||||
</Calendar>
|
</Calendar>
|
||||||
|
<Description class="text-center">日历已禁用</Description>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -9,14 +9,16 @@ import {
|
|||||||
CalendarGridBody,
|
CalendarGridBody,
|
||||||
CalendarHeaderCell,
|
CalendarHeaderCell,
|
||||||
CalendarCell,
|
CalendarCell,
|
||||||
|
Description,
|
||||||
} from "@heroui-vue/components";
|
} from "@heroui-vue/components";
|
||||||
import { parseDate } from "@internationalized/date";
|
import { getLocalTimeZone, today } from "@internationalized/date";
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
|
<div class="flex flex-col items-center gap-4">
|
||||||
<Calendar
|
<Calendar
|
||||||
aria-label="活动日期"
|
aria-label="活动日期"
|
||||||
is-read-only
|
is-read-only
|
||||||
:default-value="parseDate('2025-02-14')"
|
:default-value="today(getLocalTimeZone())"
|
||||||
>
|
>
|
||||||
<CalendarHeader>
|
<CalendarHeader>
|
||||||
<CalendarHeading />
|
<CalendarHeading />
|
||||||
@@ -32,4 +34,6 @@ import { parseDate } from "@internationalized/date";
|
|||||||
</CalendarGridBody>
|
</CalendarGridBody>
|
||||||
</CalendarGrid>
|
</CalendarGrid>
|
||||||
</Calendar>
|
</Calendar>
|
||||||
|
<Description class="text-center">日历为只读</Description>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -10,9 +10,11 @@ import {
|
|||||||
CalendarHeaderCell,
|
CalendarHeaderCell,
|
||||||
CalendarCell,
|
CalendarCell,
|
||||||
Description,
|
Description,
|
||||||
|
useLocale,
|
||||||
} from "@heroui-vue/components";
|
} from "@heroui-vue/components";
|
||||||
import { isWeekend, type DateValue } from "@internationalized/date";
|
import { isWeekend, type DateValue } from "@internationalized/date";
|
||||||
const isDateUnavailable = (date: DateValue) => isWeekend(date, "en-US");
|
const { locale } = useLocale();
|
||||||
|
const isDateUnavailable = (date: DateValue) => isWeekend(date, locale.value);
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<div class="flex flex-col items-center gap-4">
|
<div class="flex flex-col items-center gap-4">
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ import {
|
|||||||
TimeFieldGroup,
|
TimeFieldGroup,
|
||||||
TimeFieldInput,
|
TimeFieldInput,
|
||||||
TimeFieldSegment,
|
TimeFieldSegment,
|
||||||
|
useLocale,
|
||||||
} from "@heroui-vue/components";
|
} from "@heroui-vue/components";
|
||||||
import {
|
import {
|
||||||
DateFormatter,
|
DateFormatter,
|
||||||
@@ -61,6 +62,7 @@ const granularity = ref<Granularity>("minute");
|
|||||||
const hourCycle = ref<HourCycle>(12);
|
const hourCycle = ref<HourCycle>(12);
|
||||||
const hideTimeZone = ref(false);
|
const hideTimeZone = ref(false);
|
||||||
const shouldForceLeadingZeros = ref(false);
|
const shouldForceLeadingZeros = ref(false);
|
||||||
|
const { locale } = useLocale();
|
||||||
const cycle = computed(() => (hourCycle.value === 24 ? 24 : 12) as 12 | 24);
|
const cycle = computed(() => (hourCycle.value === 24 ? 24 : 12) as 12 | 24);
|
||||||
const timeGranularity = computed(() =>
|
const timeGranularity = computed(() =>
|
||||||
granularity.value !== "day" ? granularity.value : undefined,
|
granularity.value !== "day" ? granularity.value : undefined,
|
||||||
@@ -78,14 +80,17 @@ const defaultValue = computed<DateRange>(() => {
|
|||||||
start: parseZonedDateTime(`2026-02-03T08:45:00[${localTimeZone}]`),
|
start: parseZonedDateTime(`2026-02-03T08:45:00[${localTimeZone}]`),
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
const dateFormatter = new DateFormatter("zh-CN", {
|
const dateFormatter = computed(
|
||||||
|
() =>
|
||||||
|
new DateFormatter(locale.value, {
|
||||||
day: "numeric",
|
day: "numeric",
|
||||||
month: "short",
|
month: "short",
|
||||||
year: "numeric",
|
year: "numeric",
|
||||||
});
|
}),
|
||||||
|
);
|
||||||
function formatDate(range: DateRange) {
|
function formatDate(range: DateRange) {
|
||||||
const localTimeZone = getLocalTimeZone();
|
const localTimeZone = getLocalTimeZone();
|
||||||
return dateFormatter.formatRange(
|
return dateFormatter.value.formatRange(
|
||||||
range.start.toDate(localTimeZone),
|
range.start.toDate(localTimeZone),
|
||||||
range.end.toDate(localTimeZone),
|
range.end.toDate(localTimeZone),
|
||||||
);
|
);
|
||||||
@@ -102,7 +107,7 @@ const hourCycleOptions: { label: string; value: HourCycle }[] = [
|
|||||||
];
|
];
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<div class="flex w-full flex-col gap-4">
|
<div class="flex w-full min-w-0 flex-col gap-4 overflow-x-auto">
|
||||||
<DateRangePicker
|
<DateRangePicker
|
||||||
:key="granularity"
|
:key="granularity"
|
||||||
class="w-max min-w-80"
|
class="w-max min-w-80"
|
||||||
@@ -132,9 +137,11 @@ const hourCycleOptions: { label: string; value: HourCycle }[] = [
|
|||||||
</DateRangePickerTrigger>
|
</DateRangePickerTrigger>
|
||||||
</DateFieldSuffix>
|
</DateFieldSuffix>
|
||||||
</DateFieldGroup>
|
</DateFieldGroup>
|
||||||
<!-- Portaled content keeps an auto-sized wrapper; the pinned example's
|
<!-- The baseline fills the viewport; reserve the popover's 12px
|
||||||
w-full maps to the 252px calendar plus the popover's 24px padding. -->
|
collision padding on both sides so its contents stay reachable. -->
|
||||||
<DateRangePickerPopover class="flex w-[276px] flex-col gap-3">
|
<DateRangePickerPopover
|
||||||
|
class="flex w-[calc(100vw-24px)] flex-col gap-3"
|
||||||
|
>
|
||||||
<RangeCalendar aria-label="出行日期" class="w-full">
|
<RangeCalendar aria-label="出行日期" class="w-full">
|
||||||
<RangeCalendarHeader>
|
<RangeCalendarHeader>
|
||||||
<CalendarYearPickerTrigger>
|
<CalendarYearPickerTrigger>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
固定上游公共组件清单;状态、差异和验证范围逐组件记录,不以单项测试通过声明整库完整兼容。
|
固定上游公共组件清单;状态、差异和验证范围逐组件记录,不以单项测试通过声明整库完整兼容。
|
||||||
|
|
||||||
| 组件 | 状态 | 当前能力 / 差异 |
|
| 组件 | 状态 | 当前能力 / 差异 |
|
||||||
| -------------------- | ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
| -------------------- | ---------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||||
| accordion | 验证中(M23) | Accordion/Item/Heading/Trigger/Panel/Body/Indicator;10/10 基线例;surface/hideSeparator;复用组键协议 |
|
| accordion | 验证中(M23) | Accordion/Item/Heading/Trigger/Panel/Body/Indicator;10/10 基线例;surface/hideSeparator;复用组键协议 |
|
||||||
| alert-dialog | 验证中(M33) | 11 部件;role=alertdialog;默认不误关;14/14 基线例;Reka Dialog 底座 |
|
| alert-dialog | 验证中(M33) | 11 部件;role=alertdialog;默认不误关;14/14 基线例;Reka Dialog 底座 |
|
||||||
| autocomplete | 已迁移(有已知差异) | Autocomplete 七部件;24/24 基线例;触发器单一 Tab 入口 + 弹层内搜索框虚拟焦点、受控开关/文本、多选 Value 用作用域插槽;见 B02 报告 |
|
| autocomplete | 已迁移(有已知差异) | Autocomplete 七部件;24/24 基线例;触发器单一 Tab 入口 + 弹层内搜索框虚拟焦点、受控开关/文本、多选 Value 用作用域插槽;见 B02 报告 |
|
||||||
@@ -279,7 +279,7 @@ ComboBox/Autocomplete的正式组合、原30项返修和本轮定位/ref/ARIA/lo
|
|||||||
|
|
||||||
公开 DateRangePicker/Root、Trigger、TriggerIndicator、RangeSeparator、Popover、dateRangePickerVariants 及 Props/RenderProps/state/time 类型;起止输入复用 DateFieldGroup/Input/InputContainer/Segment/Suffix,端点为可类型检查的 `endpoint` prop;日历复用 RangeCalendar 与 CalendarYearPicker 具名部件。固定源中文 10 个预览、API/插槽/状态表与导航已接入;Picker 拥有唯一完整范围接受值、双端点字段校验、两个命名提交值和 reset,未显式绑定的内嵌 RangeCalendar 继承范围、上下界、不可用、禁用/只读/无效、locale/dir 与非连续策略。
|
公开 DateRangePicker/Root、Trigger、TriggerIndicator、RangeSeparator、Popover、dateRangePickerVariants 及 Props/RenderProps/state/time 类型;起止输入复用 DateFieldGroup/Input/InputContainer/Segment/Suffix,端点为可类型检查的 `endpoint` prop;日历复用 RangeCalendar 与 CalendarYearPicker 具名部件。固定源中文 10 个预览、API/插槽/状态表与导航已接入;Picker 拥有唯一完整范围接受值、双端点字段校验、两个命名提交值和 reset,未显式绑定的内嵌 RangeCalendar 继承范围、上下界、不可用、禁用/只读/无效、locale/dir 与非连续策略。
|
||||||
|
|
||||||
不完整范围、第一下日历点击和空值时间草稿都不提交;清空两端提交 null,清空一端在关闭/外部替换/reset 时回到接受状态。受控拒绝后可重试,日历修改保留两端各自的日期类、时间、时区与历法,字段编辑保留不可显示精度。固定源 `slot="start"/"end"` 映射为 `endpoint` prop;格式选项的 `w-full` 弹层宽度映射为 252px 日历加 24px 内边距。真实浏览器、定向回归和最终 tarball 验证见 [任务结果](tasks/results/DATE-RANGE-PICKER.md)。
|
不完整范围、第一下日历点击和空值时间草稿都不提交;清空两端提交 null,清空一端在关闭/外部替换/reset 时回到接受状态。受控拒绝后可重试,日历修改保留两端各自的日期类、时间、时区与历法,字段编辑保留不可显示精度。固定源 `slot="start"/"end"` 映射为 `endpoint` prop;格式选项沿用基线的宽弹层布局,但在示例内显式预留两侧各 12px 碰撞边距,避免视口溢出;字段超宽时由该示例的横向滚动容器承接,保持触发器可达。不改写库级 `w-full` 百分比含义。真实浏览器、定向回归和最终 tarball 验证见 [任务结果](tasks/results/DATE-RANGE-PICKER.md)。
|
||||||
|
|
||||||
## FORM 正式迁移(2026-10-27)
|
## FORM 正式迁移(2026-10-27)
|
||||||
|
|
||||||
|
|||||||
@@ -13,3 +13,7 @@
|
|||||||
- HD-02 独立复核 HEAD d9536ea:暂不验收,待 HD02-R1;搜索/数量/时间异步回调须保留提交快照,三例均已复现。详细证据与回归要求见同一结果表。未改实施代码、未合 main、未 push;工作区释放,继续当前任务分支修复。
|
- HD-02 独立复核 HEAD d9536ea:暂不验收,待 HD02-R1;搜索/数量/时间异步回调须保留提交快照,三例均已复现。详细证据与回归要求见同一结果表。未改实施代码、未合 main、未 push;工作区释放,继续当前任务分支修复。
|
||||||
|
|
||||||
- HD-02 已验收:HD02-R1 修复 b0f32796cb42ea211c5daacbe1eec8273b0a1a32;全量110文件1623项、类型、文档构建、m35-m36最终tarball通过。按用户授权合入 main 并推送 origin/main;工作区释放。下一任务 HD-03-DATE-DEMOS,未自动启动;保留5173/5174。
|
- HD-02 已验收:HD02-R1 修复 b0f32796cb42ea211c5daacbe1eec8273b0a1a32;全量110文件1623项、类型、文档构建、m35-m36最终tarball通过。按用户授权合入 main 并推送 origin/main;工作区释放。下一任务 HD-03-DATE-DEMOS,未自动启动;保留5173/5174。
|
||||||
|
- HD-03-DATE-DEMOS已实施待复核,工作区释放;分支task/hd-03-date-demos,起点0b89f02745f86b3c2066a7f4ea9bb3d49bbbd3e2,实施2e3fdd4800320ec863e080cb8c968e7d1b46edaa。
|
||||||
|
- [结果](results/HD-03-DATE-DEMOS.md)逐条核销:calendar disabled/read-only 默认今天与说明、controlled 今天/圣诞节/清空与反馈文案;新增公开 useLocale() 并接通 booking/unavailable/format-options 的 startOfWeek/isWeekend/DateFormatter(4 项 zh-CN/en-US 动态切换回归,周末规则含 ar-EG 翻转证据);format-options 弹层按基线恢复 w-full 视口宽效果(官方渲染桌面/窄屏实证 + Reka 塌缩根因 + date-range-picker.css 适配规则,1280/768/375 实测同构);全量110文件1627项、typecheck、build:docs、date-range-picker/api-root-aliases/calendar 最终tarball通过。遗留:375 下基线演示内容超宽致触发器不可达(两端同病,详见结果)。
|
||||||
|
|
||||||
|
- HD-03 已验收:独立复核发现宽度适配作用域与窄屏触发器两项P2,由集成人修复462044c3b8af938c2c8b67c32c12e4b112413b3d,详见同一结果表。全量110文件1627项、类型、文档构建、date-range-picker/api-root-aliases/calendar最终tarball通过。按用户授权合入main并推送origin/main;工作区释放,下一项HD-04-DOCS未启动,保留5173/5174。
|
||||||
|
|||||||
@@ -1,16 +1,17 @@
|
|||||||
<!-- task-metadata
|
<!-- task-metadata
|
||||||
{"base":"db5670f4e1efe0e6ef7433002de5fb0a4a284f84","upstream":"ce90ea3ab49d58f6c428f71bfd6fe8ae2a87b960","status":"pending","requires":["docs/tasks/HD-QUEUE.md"],"sources":["apps/docs/src/demos/cn/calendar/controlled.tsx"],"checks":["pnpm exec vitest run tests/calendar-demos.test.ts tests/date-range-picker-demos.test.ts","pnpm typecheck"]}
|
{"base":"db5670f4e1efe0e6ef7433002de5fb0a4a284f84","upstream":"ce90ea3ab49d58f6c428f71bfd6fe8ae2a87b960","status":"accepted","requires":["docs/tasks/HD-QUEUE.md"],"sources":["apps/docs/src/demos/cn/calendar/controlled.tsx"],"checks":["pnpm exec vitest run tests/calendar-demos.test.ts tests/date-range-picker-demos.test.ts","pnpm typecheck"]}
|
||||||
-->
|
-->
|
||||||
|
|
||||||
# HD-03-DATE-DEMOS:日历示例与 locale 继承
|
# HD-03-DATE-DEMOS:日历示例与 locale 继承
|
||||||
|
|
||||||
优先级:P1。证据范围:审计组 10;详见 [清单入口](HD-QUEUE.md) 和其中证据链接。
|
优先级:P1。证据范围:审计组 10;详见 [清单入口](HD-QUEUE.md) 和其中证据链接。
|
||||||
|
|
||||||
## 执行范围
|
## 执行范围
|
||||||
|
|
||||||
- [ ] 恢复 calendar-disabled/read-only 的默认今天与说明;controlled 的今天/圣诞节/清空按钮和反馈文案。
|
- [x] 恢复 calendar-disabled/read-only 的默认今天与说明;controlled 的今天/圣诞节/清空按钮和反馈文案。
|
||||||
- [ ] calendar-controlled/booking-calendar/unavailable-dates 的 startOfWeek/isWeekend 与 date-range-picker-format-options 的 DateFormatter 使用当前 ConfigProvider locale,不写死 en-US/zh-CN。
|
- [x] calendar-controlled/booking-calendar/unavailable-dates 的 startOfWeek/isWeekend 与 date-range-picker-format-options 的 DateFormatter 使用当前 ConfigProvider locale,不写死 en-US/zh-CN。
|
||||||
- [ ] 核对 format-options 弹层:上游 w-full,Vue w-[276px];按真实锚点和内容布局恢复基线效果,不能仅替换类名后宣布通过。
|
- [x] 核对 format-options 弹层:上游 w-full,Vue w-[276px];按真实锚点和内容布局恢复基线效果,不能仅替换类名后宣布通过。
|
||||||
- [ ] 不因 Tabler 或 DateValue 类型的合理 Vue 映射改回 React 写法。
|
- [x] 不因 Tabler 或 DateValue 类型的合理 Vue 映射改回 React 写法。
|
||||||
|
|
||||||
## 用户可见通过条件
|
## 用户可见通过条件
|
||||||
|
|
||||||
@@ -26,4 +27,3 @@
|
|||||||
结果写到 `docs/tasks/results/HD-03-DATE-DEMOS.md`,逐条记录改动或“无需修改”的证据及限制;只在本卡元数据更新状态。核实后无需修改是有效结论,不为凑修复量重写底座。普通实施提交自己的分支,不合 main、不 push、不派发其他会话。
|
结果写到 `docs/tasks/results/HD-03-DATE-DEMOS.md`,逐条记录改动或“无需修改”的证据及限制;只在本卡元数据更新状态。核实后无需修改是有效结论,不为凑修复量重写底座。普通实施提交自己的分支,不合 main、不 push、不派发其他会话。
|
||||||
|
|
||||||
仅浏览器客户端;不开发或运行 SSR/水合/Nuxt 服务端、逐像素自动对比、完整读屏或真机矩阵专项。
|
仅浏览器客户端;不开发或运行 SSR/水合/Nuxt 服务端、逐像素自动对比、完整读屏或真机矩阵专项。
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,95 @@
|
|||||||
|
# HD-03-DATE-DEMOS 结果记录
|
||||||
|
|
||||||
|
- 任务卡:[HD-03-DATE-DEMOS](../HD-03-DATE-DEMOS.md);固定上游 `ce90ea3ab49d58f6c428f71bfd6fe8ae2a87b960`(`heroui/apps/docs/src/demos/cn/*`)。
|
||||||
|
- 分支 task/hd-03-date-demos;起点 0b89f02745f86b3c2066a7f4ea9bb3d49bbbd3e2(含 HD-02 集成与 HD02-R1 修复的最新 main);实施 2e3fdd4800320ec863e080cb8c968e7d1b46edaa;记录提交为本文件所在提交。主会话实施/自测,未合 main、未 push。
|
||||||
|
- 保留项未动:DateValue 公共模型(上游示例用 CalendarDate)、Tabler 图标映射、`endpoint` 等底座适配与前轮成果。
|
||||||
|
|
||||||
|
## 范围 1:calendar-disabled/read-only/controlled 基线内容
|
||||||
|
|
||||||
|
| 项 | 基线(cn 源) | 处理与证据 |
|
||||||
|
| ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||||
|
| calendar-disabled | 外层 `flex flex-col items-center gap-4`、`defaultValue={today(getLocalTimeZone())}`、`<Description class="text-center">日历已禁用</Description>` | 全部恢复(原为裸 Calendar)。浏览器实测(Playwright 1280×720):说明"日历已禁用"在场,35 个日期按钮全部 disabled。 |
|
||||||
|
| calendar-read-only | 同结构 + "日历为只读" + `today()` 默认值 | 恢复(原用固定 `parseDate('2025-02-14')` 且无文案)。实测:说明在场,强制点击日期不产生选中(`data-selected` 计数不变)。 |
|
||||||
|
| calendar-controlled | 第二排 `flex gap-2` 按钮 `设为今天(size=sm secondary)/设为圣诞节(sm secondary)/清空(sm tertiary)`;Description 文案 `已选日期:{value?value.toString():"(未选)"}` | 按钮行与文案全部恢复。实测点击序列:初始"已选日期:(未选)"→设为今天=2026-10-28→设为圣诞节=2025-12-25→清空=(未选)→本周=2026-10-25→今天=2026-10-28,与 `today()/parseDate('2025-12-25')` 逐一相符。 |
|
||||||
|
|
||||||
|
## 范围 2:locale 继承(不写死 en-US/zh-CN)
|
||||||
|
|
||||||
|
**缺口与公共 API**:上游示例用 react-aria-components 的公开 `useLocale()`;Vue 侧 `useConfig`/`configContextKey` 未导出,消费者/演示无法读取当前 ConfigProvider locale(startOfWeek/isWeekend/DateFormatter 都需要它)。最小新增:`useLocale()`(packages/vue/src/providers/context.ts),返回与组件继承链一致的 `locale`/`dir`(ConfigProvider → `en-US`/`ltr` 回退,同 calendar view.ts 的解析链),`@heroui-vue/components` 导出;calendar.md / date-range-picker.md 相关包小节补记(顺带合并 calendar.md 重复的 ConfigProvider 行——审计 10 的轻微项)。
|
||||||
|
|
||||||
|
| 示例 | 原实现 | 现实现 |
|
||||||
|
| -------------------------------- | -------------------------------------- | ---------------------------------------------------------------- |
|
||||||
|
| calendar-controlled | `startOfWeek(today(…), 'en-US')` | `startOfWeek(today(…), locale)`(useLocale) |
|
||||||
|
| calendar-booking-calendar | `isWeekend(date, "en-US")` | `isWeekend(date, locale.value)` |
|
||||||
|
| calendar-unavailable-dates | `isWeekend(date, "en-US")` | `isWeekend(date, locale.value)` |
|
||||||
|
| date-range-picker-format-options | 模块级 `new DateFormatter("zh-CN", …)` | `computed(() => new DateFormatter(locale.value, …))`,随配置重算 |
|
||||||
|
|
||||||
|
**回归(tests/calendar-demos.test.ts 3 项 + tests/date-range-picker-demos.test.ts 1 项,均动态切换 ConfigProvider locale)**:
|
||||||
|
|
||||||
|
1. 周起点:zh-CN/en-US 下点"本周"分别落到 `startOfWeek(today, 'zh-CN')`(周一 2026-10-26)与 `startOfWeek(today, 'en-US')`(周日 2026-10-25),运行时切换后同一按钮落点随之改变(两结果必然不同,断言显式验证)。
|
||||||
|
2. 周末禁用:`calendar-unavailable-dates` 的单元格 `data-unavailable` 与 `isWeekend(date, 当前 locale)` 逐格相等(en-US、zh-CN 两配置都覆盖);另以 ar-EG(周五/周六周末)验证规则真实翻转(周五六变不可用、周日变可用)。**事实说明**:CLDR 中 zh-CN 与 en-US 的周末同为周六/日,两者的"周末禁用规则"没有可观察差异;真正的规则变化需 ar-EG 类 locale——测试如实覆盖 zh-CN/en-US 并补充 ar-EG 证据。
|
||||||
|
3. booking-calendar:预订日(5/6/12/13/14/20)始终不可用,周末随 locale;ar-EG 下非预订周日恢复可用。
|
||||||
|
4. 格式:format-options 弹层"已选:"行按 ConfigProvider locale 渲染(与 `DateFormatter(locale).formatRange` 实算逐字一致),zh-CN ↔ en-US 往返切换各断言含/不含(zh-CN "2026/2/3 – 2026/2/10" vs en-US "Feb 3 – 10, 2026")。
|
||||||
|
|
||||||
|
## 范围 3:format-options 弹层宽度(核对机制,非换类名)
|
||||||
|
|
||||||
|
**基线效果的实证**(固定源机制 + 官方文档渲染旁证,基线判定仍以固定源为准):
|
||||||
|
|
||||||
|
- 固定源链条:`composeTwRenderProps` 的 `cx` 仅拼接不消解类冲突(本地复算确认),`.date-range-picker__popover` 的 `@apply w-fit` 在 components 层、demo 的 `w-full` 在 utilities 层且后出(构建产物中 `.w-full` 在 `.w-fit` 之后)→ **w-full 生效**;RAC Popover 的包裹层是 `display: contents`,弹层元素自身 `position: absolute`(useOverlayPosition 内联样式)→ 包含块=初始包含块(视口)→ **弹层=视口宽**。
|
||||||
|
- 官方文档实测(Playwright 1280×720 / 375×667,截图存档):弹层 `cssWidth` 分别 1280px、375px = 视口宽;`left:12px`(containerPadding 钳制,右缘同有 12px 溢出);内部日历恒 252px(`.range-calendar` 的 `w-63 max-w-63`)、时间行拉伸全宽。
|
||||||
|
- 我们的链条:Reka 定位包裹层 `[data-reka-popper-content-wrapper]` 按内容收缩(`min-width: max-content`),demo 类并到弹层根元素;实测把 `w-[276px]` 换成字面 `w-full` 会**循环塌缩**(弹层 187px、日历被压到 163px)——这就是"不能只替换类名"的原因。原 `w-[276px]` 只对默认内容等效 276px,窄屏会截断,且与基线的全宽效果不同。
|
||||||
|
|
||||||
|
**修复**:demo 类恢复基线 `flex w-full flex-col gap-3`(示例源码与固定源逐字一致),`packages/styles/components/date-range-picker.css` 增加适配规则 `.hv-date-range-picker__popover.w-full { width: 100vw !important }`(`!important` 与 dropdown 静态包裹层适配同因:要越过 utilities 层级),把 w-full 映射到与上游同一"定位边界=视口"语义。compatibility.md 的旧映射记录("w-full 映射为 252px 日历加 24px 内边距")已更正。
|
||||||
|
|
||||||
|
**真实浏览器核对(Playwright 无头 Chrome,1280/768/375)**:
|
||||||
|
|
||||||
|
| 视口 | 弹层 rect(x,y,w,h) | 计算宽 | 日历 | 取值操作 |
|
||||||
|
| -------- | -------------------- | ------ | ----------- | -------------------------------- |
|
||||||
|
| 1280×720 | [12, 37, 1280, 380] | 1280px | [24,…,252] | 真实鼠标点击单元格,"已选"变化 ✓ |
|
||||||
|
| 768×900 | [12, 127, 768, 380] | 768px | [24,…,252] | ✓ |
|
||||||
|
| 375×667 | [111, 12, 375, 378] | 375px | [123,…,252] | ✓ |
|
||||||
|
|
||||||
|
与基线同构:视口宽弹层、252px 日历、时间行拉伸、x=12 边界钳制(含基线自身的 12px 右缘溢出特性,桌面/平板逐一复现)。截图对照官方渲染(同为全宽板+252px 日历+拉伸时间行)。
|
||||||
|
|
||||||
|
## 范围 4:保留适配
|
||||||
|
|
||||||
|
DateValue 公共模型(上游示例 CalendarDate→DateValue 保留)、Tabler 图标(custom-icons 的 IconArrowLeft/Right 保留)、`endpoint` 端点映射、Reka data-side/定位变量等均未回改;前轮 HD-01/HD-02 成果未动。
|
||||||
|
|
||||||
|
## 检查与验证
|
||||||
|
|
||||||
|
- `node scripts/task-check.mjs HD-03-DATE-DEMOS`(head 0b89f02、最低 base 满足)✅
|
||||||
|
- 卡内最低 checks:`vitest run tests/calendar-demos.test.ts tests/date-range-picker-demos.test.ts`(17 项)✅、`pnpm typecheck` ✅
|
||||||
|
- 全量回归 `pnpm exec vitest run`:110 文件 / 1627 项(新增 4 项 locale 回归)✅
|
||||||
|
- `pnpm build:docs` ✅;prettier ✅
|
||||||
|
- 公共 API/styles 变化按最终 tarball 验证:`check-package.mjs date-range-picker`(新增 CSS 适配规则 `.hv-date-range-picker__popover.w-full` 入契约)、`api-root-aliases`(`useLocale` 导出入契约)、`calendar` ✅
|
||||||
|
- 真实浏览器:今天/设为今天/设为圣诞节/清空/本周/今天反馈逐条实测;禁用(35 格全禁用+说明)、只读(点击不选中+说明);弹层桌面/平板/窄屏宽度、可见性与点击取值(见上表;另存 calendar-controlled / format-options 各视口截图)
|
||||||
|
|
||||||
|
## 未完成与限制
|
||||||
|
|
||||||
|
1. **窄屏(375)触发器可达性**:固定源示例内容本身超宽(`w-max min-w-80` 字段渲染 485px 分段 + `min-w-[529px]` 行,均为基线类;官方文档同场景实测字段 543px),两端都被裁——官方预览容器(overflow-x:hidden)可程序滚动到触发器,我们的文档页在更高层裁剪、无处滚动,故 375 下触发器在视口外(x=486),弹层锚点随之偏移(x=111,右缘裁掉 111px;基线同场景为 x=12、裁 12px)。弹层本身=视口宽、内容不挤压(252px 日历完整),点击取值可操作(程序化开合后真实点击验证)。此为基线演示内容与文档壳的窄屏边界,不在本卡改基线类;如需根治应由文档壳/预览容器承接横向滚动(转 HD-04 或文档壳任务)。
|
||||||
|
2. **默认 locale 口径**:无 ConfigProvider 时本库链回退 `en-US`(API 表已记载"ConfigProvider 或 en-US"),上游 `useLocale` 默认为浏览器 locale——故默认文档渲染(英文月/周名、"Feb 3 – 10, 2026")与官方站(浏览器 locale)不同;这是既有库级口径,本卡未改(改则影响全部日期组件)。`useLocale()` 与组件链保持一致,配置切换行为一致(测试覆盖)。
|
||||||
|
3. 基线 `w-full` 全宽弹层在桌面上观感粗放(官方渲染同样如此,截图对照);按"恢复基线效果"如实复刻,如集成人判定该 demo 类为上游笔误、拟改回 fit-content(276px 自适应),仅需回退一条 CSS 适配规则并把 demo 类换回 `w-fit` 系——两种取向的证据均已留在本记录。
|
||||||
|
4. 浏览器工具限制(沿用既知):桌面窗口不可见致应用内浏览器无法截图/键位注入受限;本次浏览器验证改用 scratchpad 的 `playwright-core` + 系统 Chrome 无头(真实鼠标点击、可控视口、截图),不依赖仓库锁文件(仓库未新增依赖)。REA `capture_browser_scenario` 在本环境 cleanup 失败不可用(记录备查)。
|
||||||
|
5. 审计组 10 中未列入本卡的相邻项(记录不消失):date-field-full-width 的 `max-w-full`、date-field-granularity 的 `flex-wrap` 布局类(与 HD-02 的宽度守卫处理同族,需统一口径的任务处理);date-picker/date-range-picker 触发器 `data-focus-visible` 鼠标置位(待核实项);granularity 默认值三处口径;visibleYears"或 20"、年份部件 format 类型、全局 CSS 示例颜色等文档事实项(HD-04)。
|
||||||
|
|
||||||
|
|
||||||
|
## 独立复核、修复与集成验收(2026-10-28)
|
||||||
|
|
||||||
|
复核实施 HEAD `1029444a98fc48a31e826c2ba9a25ecb30c715fb`(实现 `2e3fdd4800320ec863e080cb8c968e7d1b46edaa`)。用户授权少量问题直接修复后合并 push;集成人修复提交 **`462044c3b8af938c2c8b67c32c12e4b112413b3d`**。
|
||||||
|
|
||||||
|
| ID | 分类 | 发现与处理 | 验证结论 |
|
||||||
|
| --- | --- | --- | --- |
|
||||||
|
| HD03-R1 | P2,宽度适配作用域 | 新增库级 `.hv-date-range-picker__popover.w-full { width:100vw !important }` 将调用方通用百分比工具类强制解释为视口宽,并阻止普通宽度覆盖;不应为单一示例改变全库语义。已撤回此规则及仅为该规则新增的 CSS 存在性契约。宽弹层行为限定在 format-options SFC,显式使用 `w-[calc(100vw-24px)]`:保留基线宽布局、252px 日历和拉伸时间行,同时修正上游自身越过视口右边界的问题。 | 1280 视口:弹层 x=12、w=1256、right=1268;768:x=12、w=744、right=756;375:x=12、w=351、right=363,日历 w=252。均自然定位、无程序化打开,无左右裁断。 |
|
||||||
|
| HD03-R2 | P2,原任务窄屏验收遗漏 | 修复前 375px 下触发器 x=486,超出视口且无可滚动祖先;原记录将此延期到 HD-04 不满足本卡“窄屏可操作”的验收条件。已在该示例根容器增加 min-w-0/overflow-x-auto,保留内层基线尺寸与内容,宽内容由局部横向滚动承接,不修改公共文档壳。 | 375 下真实 locator click 会自然滚动至触发器(实测 x=314、right=338)并打开;文档 scrollWidth=375。真实点击 2月4日、8日后关闭,命名输入分别为 2026-02-04T08:45:00+08:00[Asia/Shanghai]、2026-02-08T18:45:00+08:00[Asia/Shanghai],时间保留。 |
|
||||||
|
|
||||||
|
**本节覆盖原范围3的库级宽度适配结论,以及原限制1/3中的延期/可选回退方案;两项均关闭。** 与上游的明确差异是:宽弹层预留实际碰撞边距,超宽输入可局部滚动,以保证本卡要求的窄屏可操作性,不复制上游的边缘溢出问题。
|
||||||
|
|
||||||
|
其余复核:
|
||||||
|
|
||||||
|
- locale 实现与固定源逐项核对;公开 `useLocale()` 与现有组件配置链一致,响应式 locale/dir、en-US/ltr 回退合理,未更改既有全库默认 locale。
|
||||||
|
- locale 四项动态回归通过:本周 en-US/zh-CN 周起点、禁用周末(含 ar-EG 真正翻转的规则)、预订日期与周末组合、格式化往返切换。
|
||||||
|
- 真实浏览器 5173:圣诞节反馈 2025-12-25、设为今天 2026-10-28、清空为(未选);禁用日历 35 个日期均 disabled;只读日历选中今天后点击29日,仍选中28日。浏览器可正常截图、真实点击和键盘 Esc,未遇原限制4所述状态;本次未使用外部 Playwright/REA。临时 viewport 已 reset。
|
||||||
|
- 最终实现全量 **110 文件 / 1627 项通过**;`pnpm typecheck`、`pnpm build:docs` 通过,仅既有 chunk 大小警告;修改代码 Prettier 与 `git diff --check` 通过。
|
||||||
|
- 最终 tarball `node scripts/check-package.mjs date-range-picker api-root-aliases calendar` 三契约通过,覆盖 ESM/CSS 与该脚本配置的类型检查。离线首次因缺少 TypeScript tarball 失败,联网运行后成功;未将安装失败计为通过。
|
||||||
|
- 无新增共享内核/API 改动;保留实施方新增 useLocale 导出和四条行为回归。本轮为局部演示布局修复,以真实浏览器几何和操作验证,不新增镜像 CSS 字符串测试。
|
||||||
|
|
||||||
|
结论:**HD-03 accepted**,按用户授权合入 main 并推送 origin/main。原相邻文档/焦点事项仍按 HD-04/HD-06 范围处理;无未关闭的本卡复核项。现有5173/5174服务保留。
|
||||||
@@ -438,6 +438,7 @@ export {
|
|||||||
type UseOverlayStateOptions,
|
type UseOverlayStateOptions,
|
||||||
} from "./composables/useOverlayState";
|
} from "./composables/useOverlayState";
|
||||||
export { default as ConfigProvider } from "./providers/ConfigProvider.vue";
|
export { default as ConfigProvider } from "./providers/ConfigProvider.vue";
|
||||||
|
export { useLocale } from "./providers/context";
|
||||||
export type { ConfigProviderProps } from "./types";
|
export type { ConfigProviderProps } from "./types";
|
||||||
|
|
||||||
export { default as Modal } from "./components/modal/Modal";
|
export { default as Modal } from "./components/modal/Modal";
|
||||||
@@ -817,9 +818,7 @@ export {
|
|||||||
default as DateInputGroup,
|
default as DateInputGroup,
|
||||||
default as DateFieldGroup,
|
default as DateFieldGroup,
|
||||||
} from "./components/date-field/DateInputGroup.vue";
|
} from "./components/date-field/DateInputGroup.vue";
|
||||||
export {
|
export { default as DateInputGroupRoot } from "./components/date-field/DateInputGroup.vue";
|
||||||
default as DateInputGroupRoot,
|
|
||||||
} from "./components/date-field/DateInputGroup.vue";
|
|
||||||
export {
|
export {
|
||||||
default as DateInputGroupInput,
|
default as DateInputGroupInput,
|
||||||
default as DateFieldInput,
|
default as DateFieldInput,
|
||||||
@@ -1437,12 +1436,8 @@ export {
|
|||||||
default as ColorPicker,
|
default as ColorPicker,
|
||||||
default as ColorPickerRoot,
|
default as ColorPickerRoot,
|
||||||
} from "./components/color-picker/ColorPicker.vue";
|
} from "./components/color-picker/ColorPicker.vue";
|
||||||
export {
|
export { default as ColorPickerTrigger } from "./components/color-picker/ColorPickerTrigger.vue";
|
||||||
default as ColorPickerTrigger,
|
export { default as ColorPickerPopover } from "./components/color-picker/ColorPickerPopover.vue";
|
||||||
} from "./components/color-picker/ColorPickerTrigger.vue";
|
|
||||||
export {
|
|
||||||
default as ColorPickerPopover,
|
|
||||||
} from "./components/color-picker/ColorPickerPopover.vue";
|
|
||||||
export type * from "./components/color-picker/types";
|
export type * from "./components/color-picker/types";
|
||||||
export { colorPickerVariants } from "@heroui-vue/styles";
|
export { colorPickerVariants } from "@heroui-vue/styles";
|
||||||
export type { ColorPickerVariants } from "@heroui-vue/styles";
|
export type { ColorPickerVariants } from "@heroui-vue/styles";
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { inject, type ComputedRef, type InjectionKey } from "vue";
|
import { computed, inject, type ComputedRef, type InjectionKey } from "vue";
|
||||||
|
|
||||||
export interface ConfigContext {
|
export interface ConfigContext {
|
||||||
dir: ComputedRef<"ltr" | "rtl">;
|
dir: ComputedRef<"ltr" | "rtl">;
|
||||||
@@ -9,3 +9,17 @@ export const configContextKey: InjectionKey<ConfigContext> =
|
|||||||
export function useConfig() {
|
export function useConfig() {
|
||||||
return inject(configContextKey, undefined);
|
return inject(configContextKey, undefined);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Locale/direction of the active `ConfigProvider`, mirroring the components'
|
||||||
|
* inheritance chain (`ConfigProvider` → `en-US` / `ltr`). Consumers use it for
|
||||||
|
* locale-dependent computations outside the components, such as
|
||||||
|
* `startOfWeek`/`isWeekend` or a `DateFormatter`, the way upstream demos use
|
||||||
|
* react-aria-components' `useLocale()`.
|
||||||
|
*/
|
||||||
|
export function useLocale() {
|
||||||
|
const config = useConfig();
|
||||||
|
return {
|
||||||
|
locale: computed(() => config?.locale.value ?? "en-US"),
|
||||||
|
dir: computed(() => config?.dir.value ?? "ltr"),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,11 +1,31 @@
|
|||||||
import { afterEach, expect, it, vi } from "vitest";
|
import { afterEach, expect, it, vi } from "vitest";
|
||||||
import { mount, flushPromises } from "@vue/test-utils";
|
import { mount, flushPromises } from "@vue/test-utils";
|
||||||
import { defineComponent, h, type Component } from "vue";
|
import { defineComponent, h, ref, type Component, type Ref } from "vue";
|
||||||
|
import {
|
||||||
|
getDayOfWeek,
|
||||||
|
getLocalTimeZone,
|
||||||
|
isWeekend,
|
||||||
|
startOfMonth,
|
||||||
|
startOfWeek,
|
||||||
|
today,
|
||||||
|
} from "@internationalized/date";
|
||||||
|
import { ConfigProvider } from "../packages/vue/src";
|
||||||
const demos = import.meta.glob("../apps/docs/demos/calendar-*.vue", {
|
const demos = import.meta.glob("../apps/docs/demos/calendar-*.vue", {
|
||||||
eager: true,
|
eager: true,
|
||||||
import: "default",
|
import: "default",
|
||||||
}) as Record<string, Component>;
|
}) as Record<string, Component>;
|
||||||
const wrappers: ReturnType<typeof mount>[] = [];
|
const wrappers: ReturnType<typeof mount>[] = [];
|
||||||
|
function mountInLocale(locale: Ref<string>, name: string) {
|
||||||
|
const demo = demos[`../apps/docs/demos/${name}.vue`];
|
||||||
|
const w = mount(
|
||||||
|
defineComponent({
|
||||||
|
render: () => h(ConfigProvider, { locale: locale.value }, () => h(demo!)),
|
||||||
|
}),
|
||||||
|
{ attachTo: document.body },
|
||||||
|
);
|
||||||
|
wrappers.push(w);
|
||||||
|
return w;
|
||||||
|
}
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
wrappers.splice(0).forEach((w) => w.unmount());
|
wrappers.splice(0).forEach((w) => w.unmount());
|
||||||
document.body.innerHTML = "";
|
document.body.innerHTML = "";
|
||||||
@@ -30,3 +50,107 @@ it("mounts all nineteen baseline demos together without duplicate IDs or Vue war
|
|||||||
expect(new Set(ids).size).toBe(ids.length);
|
expect(new Set(ids).size).toBe(ids.length);
|
||||||
expect(warn).not.toHaveBeenCalled();
|
expect(warn).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("the 本周 jump uses the active ConfigProvider locale and follows runtime switches", async () => {
|
||||||
|
const locale = ref("en-US");
|
||||||
|
mountInLocale(locale, "calendar-controlled");
|
||||||
|
await flushPromises();
|
||||||
|
const weekButton = () =>
|
||||||
|
[...document.querySelectorAll("button")].find(
|
||||||
|
(b) => b.textContent?.trim() === "本周",
|
||||||
|
)!;
|
||||||
|
const picked = () =>
|
||||||
|
document.body.textContent!.match(/已选日期:(\d{4}-\d{2}-\d{2})/)?.[1];
|
||||||
|
weekButton().click();
|
||||||
|
await flushPromises();
|
||||||
|
const enStart = startOfWeek(today(getLocalTimeZone()), "en-US").toString();
|
||||||
|
expect(enStart).toBe(
|
||||||
|
startOfWeek(today(getLocalTimeZone()), "en-US").toString(),
|
||||||
|
);
|
||||||
|
expect(picked()).toBe(enStart);
|
||||||
|
locale.value = "zh-CN";
|
||||||
|
await flushPromises();
|
||||||
|
weekButton().click();
|
||||||
|
await flushPromises();
|
||||||
|
const zhStart = startOfWeek(today(getLocalTimeZone()), "zh-CN").toString();
|
||||||
|
// The two locales disagree on the first day of the week (Sunday vs Monday),
|
||||||
|
// so the same action must land on different days after the switch.
|
||||||
|
expect(zhStart).not.toBe(enStart);
|
||||||
|
expect(picked()).toBe(zhStart);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("weekend disabling follows the active locale, including weekend-rule changes", async () => {
|
||||||
|
const base = startOfWeek(today(getLocalTimeZone()), "en-US");
|
||||||
|
const day = (offset: number) => base.add({ days: offset }).toString();
|
||||||
|
const friday = day(5),
|
||||||
|
saturday = day(6),
|
||||||
|
sunday = day(0);
|
||||||
|
const flags = () =>
|
||||||
|
Object.fromEntries(
|
||||||
|
[friday, saturday, sunday].map((date) => [
|
||||||
|
date,
|
||||||
|
!!document
|
||||||
|
.querySelector(`[data-date="${date}"]`)
|
||||||
|
?.getAttribute("data-unavailable"),
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
const locale = ref("en-US");
|
||||||
|
mountInLocale(locale, "calendar-unavailable-dates");
|
||||||
|
await flushPromises();
|
||||||
|
// en-US/zh-CN share the Sat–Sun weekend (CLDR); the flags must equal the
|
||||||
|
// locale rule either way.
|
||||||
|
expect(flags()).toEqual({
|
||||||
|
[friday]: isWeekend(base.add({ days: 5 }), "en-US"),
|
||||||
|
[saturday]: isWeekend(base.add({ days: 6 }), "en-US"),
|
||||||
|
[sunday]: isWeekend(base.add({ days: 0 }), "en-US"),
|
||||||
|
});
|
||||||
|
expect(flags()[saturday]).toBe(true);
|
||||||
|
expect(flags()[sunday]).toBe(true);
|
||||||
|
expect(flags()[friday]).toBe(false);
|
||||||
|
locale.value = "zh-CN";
|
||||||
|
await flushPromises();
|
||||||
|
expect(flags()).toEqual({
|
||||||
|
[friday]: isWeekend(base.add({ days: 5 }), "zh-CN"),
|
||||||
|
[saturday]: isWeekend(base.add({ days: 6 }), "zh-CN"),
|
||||||
|
[sunday]: isWeekend(base.add({ days: 0 }), "zh-CN"),
|
||||||
|
});
|
||||||
|
// ar-EG has a Friday–Saturday weekend: the same cells must flip.
|
||||||
|
locale.value = "ar-EG";
|
||||||
|
await flushPromises();
|
||||||
|
expect(flags()).toEqual({
|
||||||
|
[friday]: true,
|
||||||
|
[saturday]: true,
|
||||||
|
[sunday]: false,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("the booking calendar combines locale weekends with the booked days", async () => {
|
||||||
|
const booked = [5, 6, 12, 13, 14, 20];
|
||||||
|
const monthStart = startOfMonth(today(getLocalTimeZone()));
|
||||||
|
const days = Array.from({ length: 31 }, (_, i) =>
|
||||||
|
monthStart.add({ days: i }),
|
||||||
|
).filter((d) => d.month === monthStart.month);
|
||||||
|
const iso = (d: (typeof days)[number]) => d.toString();
|
||||||
|
const unavailable = (d: (typeof days)[number]) =>
|
||||||
|
!!document
|
||||||
|
.querySelector(`[data-date="${iso(d)}"]`)
|
||||||
|
?.getAttribute("data-unavailable");
|
||||||
|
const sunday = days.find(
|
||||||
|
(d) => !booked.includes(d.day) && getDayOfWeek(d, "en-US", "sun") === 0,
|
||||||
|
)!;
|
||||||
|
const arWorkingDay = days.find(
|
||||||
|
(d) => booked.includes(d.day) && !isWeekend(d, "ar-EG"),
|
||||||
|
)!;
|
||||||
|
const locale = ref("en-US");
|
||||||
|
mountInLocale(locale, "calendar-booking-calendar");
|
||||||
|
await flushPromises();
|
||||||
|
// Booked days stay unavailable whatever the weekend rule is.
|
||||||
|
expect(unavailable(arWorkingDay)).toBe(true);
|
||||||
|
// The locale weekend applies on top of the booked days.
|
||||||
|
expect(unavailable(sunday)).toBe(true);
|
||||||
|
locale.value = "ar-EG";
|
||||||
|
await flushPromises();
|
||||||
|
// Sunday becomes a working day under ar-EG and is not booked here.
|
||||||
|
expect(unavailable(sunday)).toBe(false);
|
||||||
|
expect(unavailable(arWorkingDay)).toBe(true);
|
||||||
|
});
|
||||||
|
|||||||
@@ -1,7 +1,14 @@
|
|||||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||||
import { mount, flushPromises } from "@vue/test-utils";
|
import { mount, flushPromises } from "@vue/test-utils";
|
||||||
|
import { defineComponent, h, ref } from "vue";
|
||||||
import { readFileSync } from "node:fs";
|
import { readFileSync } from "node:fs";
|
||||||
import { getLocalTimeZone, today } from "@internationalized/date";
|
import {
|
||||||
|
DateFormatter,
|
||||||
|
getLocalTimeZone,
|
||||||
|
parseZonedDateTime,
|
||||||
|
today,
|
||||||
|
} from "@internationalized/date";
|
||||||
|
import { ConfigProvider } from "../packages/vue/src";
|
||||||
const demos = import.meta.glob("../apps/docs/demos/date-range-picker-*.vue", {
|
const demos = import.meta.glob("../apps/docs/demos/date-range-picker-*.vue", {
|
||||||
eager: true,
|
eager: true,
|
||||||
import: "default",
|
import: "default",
|
||||||
@@ -300,4 +307,41 @@ describe("DateRangePicker documentation", () => {
|
|||||||
expect(validation.checkValidity()).toBe(true);
|
expect(validation.checkValidity()).toBe(true);
|
||||||
expect(w.find('[data-slot="field-error"]').exists()).toBe(false);
|
expect(w.find('[data-slot="field-error"]').exists()).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("format options formats the range with the active locale and follows runtime switches", async () => {
|
||||||
|
const tz = getLocalTimeZone();
|
||||||
|
const start = parseZonedDateTime(`2026-02-03T08:45:00[${tz}]`).toDate();
|
||||||
|
const end = parseZonedDateTime(`2026-02-10T18:45:00[${tz}]`).toDate();
|
||||||
|
const formatted = (loc: string) =>
|
||||||
|
new DateFormatter(loc, {
|
||||||
|
day: "numeric",
|
||||||
|
month: "short",
|
||||||
|
year: "numeric",
|
||||||
|
}).formatRange(start, end);
|
||||||
|
expect(formatted("zh-CN")).not.toBe(formatted("en-US"));
|
||||||
|
const locale = ref("zh-CN");
|
||||||
|
const demo =
|
||||||
|
demos["../apps/docs/demos/date-range-picker-format-options.vue"];
|
||||||
|
const w = mount(
|
||||||
|
defineComponent({
|
||||||
|
render: () =>
|
||||||
|
h(ConfigProvider, { locale: locale.value }, () => h(demo as never)),
|
||||||
|
}),
|
||||||
|
{ attachTo: document.body },
|
||||||
|
);
|
||||||
|
wrappers.push(w);
|
||||||
|
await flushPromises();
|
||||||
|
await open(w);
|
||||||
|
expect(document.body.textContent).toContain("已选:");
|
||||||
|
expect(document.body.textContent).toContain(formatted("zh-CN"));
|
||||||
|
locale.value = "en-US";
|
||||||
|
await flushPromises();
|
||||||
|
expect(document.body.textContent).toContain(formatted("en-US"));
|
||||||
|
expect(document.body.textContent).not.toContain(formatted("zh-CN"));
|
||||||
|
// The same range renders with the new locale again after a switch back.
|
||||||
|
locale.value = "zh-CN";
|
||||||
|
await flushPromises();
|
||||||
|
expect(document.body.textContent).toContain(formatted("zh-CN"));
|
||||||
|
expect(document.body.textContent).not.toContain(formatted("en-US"));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -584,6 +584,7 @@
|
|||||||
},
|
},
|
||||||
"api-root-aliases": {
|
"api-root-aliases": {
|
||||||
"exports": [
|
"exports": [
|
||||||
|
"useLocale",
|
||||||
"Accordion",
|
"Accordion",
|
||||||
"AccordionRoot",
|
"AccordionRoot",
|
||||||
"Alert",
|
"Alert",
|
||||||
|
|||||||
Reference in New Issue
Block a user