fix(demos): inherit ConfigProvider locale and restore the format-options popover width

HD-03 scope, all against heroui ce90ea3 cn sources:

- calendar-disabled/read-only: restore the today() default value and the
  baseline description lines (日历已禁用 / 日历为只读) inside the
  flex flex-col items-center wrapper
- calendar-controlled: restore the second button row (设为今天/设为圣诞节/
  清空) and the baseline feedback wording (已选日期:…(未选))
- locale inheritance: add a public useLocale() accessor (the components'
  ConfigProvider → en-US/ltr chain) and use it for startOfWeek in
  calendar-controlled, isWeekend in booking-calendar/unavailable-dates and
  the DateFormatter in date-range-picker-format-options instead of the
  hardcoded 'en-US' / 'zh-CN' literals
- date-range-picker-format-options: restore the pinned w-full popover class;
  the pinned source positions the popover against the initial containing
  block (full viewport width — verified on the reference docs at desktop and
  narrow), while Reka's shrink-to-fit positioning wrapper collapses the same
  class. A scoped adapter rule (.hv-date-range-picker__popover.w-full →
  100vw, layering-safe like the dropdown static-wrapper adapter) restores
  the baseline effect: viewport-wide popover, 252px calendar, stretched
  time rows, identical boundary clamping

- tests: locale dynamic-switching regressions covering zh-CN/en-US for week
  start, weekend rules (with ar-EG flipping the weekend for a observable
  rule change) and range formatting; full suite 110 files / 1627 tests,
  typecheck, build:docs and the date-range-picker / api-root-aliases /
  calendar tarball contracts pass
This commit is contained in:
maoyingjie
2026-10-28 16:35:26 +08:00
parent 0b89f02745
commit 2e3fdd4800
15 changed files with 382 additions and 147 deletions
+45 -1
View File
@@ -1,7 +1,14 @@
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { mount, flushPromises } from "@vue/test-utils";
import { defineComponent, h, ref } from "vue";
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", {
eager: true,
import: "default",
@@ -300,4 +307,41 @@ describe("DateRangePicker documentation", () => {
expect(validation.checkValidity()).toBe(true);
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"));
});
});