merge: integrate reviewed M30-M32 with NumberField Slider and migration lessons
This commit is contained in:
@@ -0,0 +1,130 @@
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import { mount } from "@vue/test-utils";
|
||||
import { defineComponent, h, nextTick } from "vue";
|
||||
import Foundation from "../packages/vue/tests/fixtures/NumberFieldFoundation.vue";
|
||||
|
||||
// Capability probes for installed Reka, not acceptance tests for a public NumberField.
|
||||
const wrappers: ReturnType<typeof mount>[] = [];
|
||||
afterEach(() => {
|
||||
wrappers.splice(0).forEach((wrapper) => wrapper.unmount());
|
||||
document.body.innerHTML = "";
|
||||
});
|
||||
|
||||
describe("NumberField foundation: installed Reka capabilities and adapter gaps", () => {
|
||||
it("steps decimal values and clamps to bounds", async () => {
|
||||
const wrapper = mount(Foundation, {
|
||||
props: { defaultValue: 0.2, step: 0.1, min: 0, max: 0.3 },
|
||||
attachTo: document.body,
|
||||
});
|
||||
wrappers.push(wrapper);
|
||||
await wrapper
|
||||
.get('[role="spinbutton"]')
|
||||
.trigger("keydown", { key: "ArrowUp" });
|
||||
expect(wrapper.get('[role="spinbutton"]').attributes("aria-valuenow")).toBe(
|
||||
"0.3",
|
||||
);
|
||||
expect(
|
||||
(
|
||||
wrapper.get('button[aria-label="Increase"]')
|
||||
.element as HTMLButtonElement
|
||||
).disabled,
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("formats locale text while submitting one canonical numeric value", async () => {
|
||||
const wrapper = mount(
|
||||
defineComponent({
|
||||
render: () =>
|
||||
h("form", {}, [
|
||||
h(Foundation, {
|
||||
defaultValue: 1234.5,
|
||||
locale: "de-DE",
|
||||
name: "quantity",
|
||||
}),
|
||||
]),
|
||||
}),
|
||||
{ attachTo: document.body },
|
||||
);
|
||||
wrappers.push(wrapper);
|
||||
await nextTick();
|
||||
expect(
|
||||
(wrapper.get('[role="spinbutton"]').element as HTMLInputElement).value,
|
||||
).toBe("1.234,5");
|
||||
expect(
|
||||
new FormData(wrapper.get("form").element).getAll("quantity"),
|
||||
).toEqual(["1234.5"]);
|
||||
});
|
||||
|
||||
it("omits a disabled value from native FormData", async () => {
|
||||
const wrapper = mount(
|
||||
defineComponent({
|
||||
render: () =>
|
||||
h("form", {}, [
|
||||
h(Foundation, {
|
||||
defaultValue: 4,
|
||||
disabled: true,
|
||||
name: "quantity",
|
||||
}),
|
||||
]),
|
||||
}),
|
||||
{ attachTo: document.body },
|
||||
);
|
||||
wrappers.push(wrapper);
|
||||
await nextTick();
|
||||
expect(new FormData(wrapper.get("form").element).has("quantity")).toBe(
|
||||
false,
|
||||
);
|
||||
});
|
||||
|
||||
it("allows an initially empty controlled parent to reject a step", async () => {
|
||||
const wrapper = mount(Foundation, {
|
||||
props: { modelValue: null },
|
||||
attachTo: document.body,
|
||||
});
|
||||
wrappers.push(wrapper);
|
||||
await wrapper
|
||||
.get('[role="spinbutton"]')
|
||||
.trigger("keydown", { key: "ArrowUp" });
|
||||
expect(wrapper.emitted("update:modelValue")?.[0]).toEqual([0]);
|
||||
expect(
|
||||
wrapper.get('[role="spinbutton"]').attributes("aria-valuenow"),
|
||||
).toBeUndefined();
|
||||
expect(
|
||||
(wrapper.get('[role="spinbutton"]').element as HTMLInputElement).value,
|
||||
).toBe("");
|
||||
});
|
||||
|
||||
it("records the raw Home/End readonly gap for the library adapter", async () => {
|
||||
const wrapper = mount(Foundation, {
|
||||
props: { defaultValue: 2, readonly: true, min: 0, max: 5 },
|
||||
attachTo: document.body,
|
||||
});
|
||||
wrappers.push(wrapper);
|
||||
await wrapper.get('[role="spinbutton"]').trigger("keydown", { key: "End" });
|
||||
// This is an upstream capability audit: the future public component must block this.
|
||||
expect(wrapper.emitted("update:modelValue")?.[0]).toEqual([5]);
|
||||
});
|
||||
|
||||
it("records that raw Reka does not reset its numeric state with the native form", async () => {
|
||||
const wrapper = mount(
|
||||
defineComponent({
|
||||
render: () =>
|
||||
h("form", {}, [h(Foundation, { defaultValue: 2, name: "quantity" })]),
|
||||
}),
|
||||
{ attachTo: document.body },
|
||||
);
|
||||
wrappers.push(wrapper);
|
||||
await wrapper
|
||||
.get('[role="spinbutton"]')
|
||||
.trigger("keydown", { key: "ArrowUp" });
|
||||
expect(wrapper.get('[role="spinbutton"]').attributes("aria-valuenow")).toBe(
|
||||
"3",
|
||||
);
|
||||
wrapper.get("form").element.reset();
|
||||
await nextTick();
|
||||
// The library will own reset coordination; this asserts the installed baseline only.
|
||||
expect(wrapper.get('[role="spinbutton"]').attributes("aria-valuenow")).toBe(
|
||||
"3",
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,361 @@
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { mount, flushPromises } from "@vue/test-utils";
|
||||
import { defineComponent, ref, nextTick, createSSRApp, h } from "vue";
|
||||
import { renderToString } from "@vue/server-renderer";
|
||||
import {
|
||||
NumberField,
|
||||
NumberFieldGroup,
|
||||
NumberFieldInput,
|
||||
NumberFieldIncrementButton,
|
||||
NumberFieldDecrementButton,
|
||||
Label,
|
||||
Description,
|
||||
FieldError,
|
||||
Fieldset,
|
||||
Form,
|
||||
} from "../packages/vue/src";
|
||||
|
||||
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: {
|
||||
NumberField,
|
||||
NumberFieldGroup,
|
||||
NumberFieldInput,
|
||||
NumberFieldIncrementButton,
|
||||
NumberFieldDecrementButton,
|
||||
Label,
|
||||
Description,
|
||||
FieldError,
|
||||
Fieldset,
|
||||
Form,
|
||||
},
|
||||
template,
|
||||
setup,
|
||||
}),
|
||||
{ attachTo: document.body },
|
||||
);
|
||||
wrappers.push(w);
|
||||
return w;
|
||||
}
|
||||
const parts =
|
||||
"<Label>Quantity</Label><NumberFieldGroup><NumberFieldDecrementButton/><NumberFieldInput/><NumberFieldIncrementButton/></NumberFieldGroup><Description>Choose quantity</Description><FieldError/>";
|
||||
|
||||
describe("NumberField public contracts", () => {
|
||||
it("repeats a held step and clears timers on cancellation and unmount", async () => {
|
||||
vi.useFakeTimers();
|
||||
try {
|
||||
const w = fixture(
|
||||
`<NumberField :default-value="0">${parts}</NumberField>`,
|
||||
);
|
||||
const button = w.get('[data-slot="number-field-increment-button"]');
|
||||
await button.trigger("pointerdown", { button: 0, pointerId: 1 });
|
||||
await vi.advanceTimersByTimeAsync(460);
|
||||
expect(w.get('[role="spinbutton"]').attributes("aria-valuenow")).toBe(
|
||||
"2",
|
||||
);
|
||||
await button.trigger("pointercancel");
|
||||
await vi.advanceTimersByTimeAsync(1000);
|
||||
expect(w.get('[role="spinbutton"]').attributes("aria-valuenow")).toBe(
|
||||
"2",
|
||||
);
|
||||
expect(vi.getTimerCount()).toBe(0);
|
||||
await button.trigger("pointerdown", { button: 0, pointerId: 2 });
|
||||
w.unmount();
|
||||
wrappers.splice(wrappers.indexOf(w), 1);
|
||||
expect(vi.getTimerCount()).toBe(0);
|
||||
} finally {
|
||||
vi.useRealTimers();
|
||||
}
|
||||
});
|
||||
it("hydrates control IDs and description associations without mismatches", async () => {
|
||||
const app = defineComponent({
|
||||
render: () =>
|
||||
h(NumberField, { defaultValue: 2 }, () => [
|
||||
h(Label, {}, () => "Amount"),
|
||||
h(NumberFieldGroup, {}, () => [h(NumberFieldInput)]),
|
||||
h(Description, {}, () => "Help"),
|
||||
]),
|
||||
});
|
||||
const html = await renderToString(createSSRApp(app));
|
||||
const container = document.createElement("div");
|
||||
container.innerHTML = html;
|
||||
document.body.append(container);
|
||||
const warnings: unknown[][] = [];
|
||||
const warn = vi.spyOn(console, "warn").mockImplementation((...args) => {
|
||||
warnings.push(args);
|
||||
});
|
||||
const client = createSSRApp(app);
|
||||
try {
|
||||
client.mount(container);
|
||||
await nextTick();
|
||||
const input = container.querySelector('input[role="spinbutton"]')!;
|
||||
expect(container.querySelector("label")?.htmlFor).toBe(input.id);
|
||||
expect(
|
||||
container.querySelector(
|
||||
`[id="${input.getAttribute("aria-describedby")}"]`,
|
||||
),
|
||||
).toBeTruthy();
|
||||
expect(warnings).toEqual([]);
|
||||
} finally {
|
||||
client.unmount();
|
||||
warn.mockRestore();
|
||||
}
|
||||
});
|
||||
it("updates ARIA/class attributes and controlled ownership as props are added and removed", async () => {
|
||||
const attributes = ref<Record<string, unknown>>({});
|
||||
const w = fixture(
|
||||
`<NumberField :default-value="2" v-bind="attributes">${parts}</NumberField>`,
|
||||
() => ({ attributes }),
|
||||
);
|
||||
for (const [index, label] of ["First", "Second"].entries()) {
|
||||
attributes.value = {
|
||||
"aria-label": label,
|
||||
class: "custom-root",
|
||||
modelValue: 7,
|
||||
};
|
||||
await nextTick();
|
||||
expect(w.get('[role="spinbutton"]').attributes("aria-label")).toBe(label);
|
||||
expect(w.get('[data-slot="number-field"]').classes()).toContain(
|
||||
"custom-root",
|
||||
);
|
||||
await w.get('[role="spinbutton"]').trigger("keydown", { key: "ArrowUp" });
|
||||
expect(w.get('[role="spinbutton"]').attributes("aria-valuenow")).toBe(
|
||||
"7",
|
||||
);
|
||||
attributes.value = {};
|
||||
await nextTick();
|
||||
expect(
|
||||
w.get('[role="spinbutton"]').attributes("aria-label"),
|
||||
).toBeUndefined();
|
||||
await w.get('[role="spinbutton"]').trigger("keydown", { key: "ArrowUp" });
|
||||
expect(w.get('[role="spinbutton"]').attributes("aria-valuenow")).toBe(
|
||||
String(3 + index),
|
||||
);
|
||||
}
|
||||
});
|
||||
it("compiles and mounts all 17 baseline examples without Vue warnings", async () => {
|
||||
const warnings: unknown[][] = [];
|
||||
const warn = vi.spyOn(console, "warn").mockImplementation((...args) => {
|
||||
warnings.push(args);
|
||||
});
|
||||
try {
|
||||
const names = [
|
||||
"basic",
|
||||
"variants",
|
||||
"on-surface",
|
||||
"with-description",
|
||||
"required",
|
||||
"disabled",
|
||||
"full-width",
|
||||
"validation",
|
||||
"controlled",
|
||||
"with-step",
|
||||
"with-format-options",
|
||||
"form-example",
|
||||
"with-validation",
|
||||
"custom-icons",
|
||||
"with-chevrons",
|
||||
"render-function",
|
||||
"custom-styles",
|
||||
];
|
||||
for (const name of names) {
|
||||
const module = await import(
|
||||
`../apps/docs/demos/number-field-${name}.vue`
|
||||
);
|
||||
const wrapper = mount(module.default, { attachTo: document.body });
|
||||
try {
|
||||
await nextTick();
|
||||
expect(wrapper.findAll('[role="spinbutton"]').length).toBeGreaterThan(
|
||||
0,
|
||||
);
|
||||
} finally {
|
||||
wrapper.unmount();
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
warn.mockRestore();
|
||||
}
|
||||
expect(warnings).toEqual([]);
|
||||
});
|
||||
it("steps decimals once and honors bounds and canonical FormData", async () => {
|
||||
const w = fixture(
|
||||
`<form><NumberField :default-value="0.2" :step="0.1" :min-value="0" :max-value="0.3" name="quantity">${parts}</NumberField></form>`,
|
||||
);
|
||||
await w.get('[data-slot="number-field-increment-button"]').trigger("click");
|
||||
expect(w.get('[role="spinbutton"]').attributes("aria-valuenow")).toBe(
|
||||
"0.3",
|
||||
);
|
||||
expect(
|
||||
(
|
||||
w.get('[data-slot="number-field-increment-button"]')
|
||||
.element as HTMLButtonElement
|
||||
).disabled,
|
||||
).toBe(true);
|
||||
expect(new FormData(w.get("form").element).getAll("quantity")).toEqual([
|
||||
"0.3",
|
||||
]);
|
||||
});
|
||||
it("keeps empty controlled state when a parent rejects a step", async () => {
|
||||
const update = vi.fn();
|
||||
const w = fixture(
|
||||
`<NumberField :model-value="null" @update:model-value="update">${parts}</NumberField>`,
|
||||
() => ({ update }),
|
||||
);
|
||||
await w.get('[role="spinbutton"]').trigger("keydown", { key: "ArrowUp" });
|
||||
expect(update).toHaveBeenCalledWith(0);
|
||||
expect(
|
||||
(w.get('[role="spinbutton"]').element as HTMLInputElement).value,
|
||||
).toBe("");
|
||||
expect(
|
||||
w.get('[role="spinbutton"]').attributes("aria-valuenow"),
|
||||
).toBeUndefined();
|
||||
});
|
||||
it("restores controlled text after rejected typing and clearing", async () => {
|
||||
const w = fixture(`<NumberField :model-value="4">${parts}</NumberField>`);
|
||||
const input = w.get('input[role="spinbutton"]');
|
||||
for (const text of ["9", ""]) {
|
||||
await input.setValue(text);
|
||||
await input.trigger("blur");
|
||||
await flushPromises();
|
||||
expect((input.element as HTMLInputElement).value).toBe("4");
|
||||
}
|
||||
});
|
||||
it("blocks readonly Home End wheel click and typing", async () => {
|
||||
const update = vi.fn();
|
||||
const w = fixture(
|
||||
`<NumberField :default-value="2" :min-value="0" :max-value="5" is-read-only @change="update">${parts}</NumberField>`,
|
||||
() => ({ update }),
|
||||
);
|
||||
const input = w.get('[role="spinbutton"]');
|
||||
for (const key of [
|
||||
"Home",
|
||||
"End",
|
||||
"ArrowUp",
|
||||
"ArrowDown",
|
||||
"PageUp",
|
||||
"PageDown",
|
||||
])
|
||||
await input.trigger("keydown", { key });
|
||||
await input.setValue("9");
|
||||
await input.trigger("blur");
|
||||
await flushPromises();
|
||||
await w.get('[data-slot="number-field-increment-button"]').trigger("click");
|
||||
expect(update).not.toHaveBeenCalled();
|
||||
expect((input.element as HTMLInputElement).value).toBe("2");
|
||||
});
|
||||
it("respects cancelled keyboard and button activation events", async () => {
|
||||
const w = fixture(
|
||||
`<NumberField :default-value="2"><NumberFieldInput @keydown.prevent/><NumberFieldIncrementButton @click.prevent/></NumberField>`,
|
||||
);
|
||||
await w.get('[role="spinbutton"]').trigger("keydown", { key: "ArrowUp" });
|
||||
await w.get("button").trigger("click");
|
||||
expect(w.get('[role="spinbutton"]').attributes("aria-valuenow")).toBe("2");
|
||||
});
|
||||
it("resets noncontrolled values and preserves cancelled reset", async () => {
|
||||
const w = fixture(
|
||||
`<form><NumberField :default-value="2" name="quantity">${parts}</NumberField></form>`,
|
||||
);
|
||||
const input = w.get('[role="spinbutton"]');
|
||||
await input.trigger("keydown", { key: "ArrowUp" });
|
||||
w.get("form").element.reset();
|
||||
await flushPromises();
|
||||
expect(input.attributes("aria-valuenow")).toBe("2");
|
||||
expect((input.element as HTMLInputElement).value).toBe("2");
|
||||
expect(new FormData(w.get("form").element).get("quantity")).toBe("2");
|
||||
w.get("form").element.addEventListener("reset", (e) => e.preventDefault());
|
||||
await input.trigger("keydown", { key: "ArrowUp" });
|
||||
w.get("form").element.reset();
|
||||
await flushPromises();
|
||||
expect(input.attributes("aria-valuenow")).toBe("3");
|
||||
});
|
||||
it("controlled reset preserves both visible and submitted parent value", async () => {
|
||||
const w = fixture(
|
||||
`<form><NumberField :model-value="8" :default-value="2" name="quantity">${parts}</NumberField></form>`,
|
||||
);
|
||||
w.get("form").element.reset();
|
||||
await flushPromises();
|
||||
expect(
|
||||
(w.get('[role="spinbutton"]').element as HTMLInputElement).value,
|
||||
).toBe("8");
|
||||
expect(new FormData(w.get("form").element).get("quantity")).toBe("8");
|
||||
});
|
||||
it("uses locale display and a single invariant submission value", async () => {
|
||||
const w = fixture(
|
||||
`<form><NumberField :default-value="1234.5" locale="de-DE" name="amount">${parts}</NumberField></form>`,
|
||||
);
|
||||
expect(
|
||||
(w.get('[role="spinbutton"]').element as HTMLInputElement).value,
|
||||
).toBe("1.234,5");
|
||||
expect(new FormData(w.get("form").element).getAll("amount")).toEqual([
|
||||
"1234.5",
|
||||
]);
|
||||
});
|
||||
it("inherits Fieldset disabled and omits values", async () => {
|
||||
const w = fixture(
|
||||
`<form><Fieldset disabled><NumberField :default-value="2" name="quantity">${parts}</NumberField></Fieldset></form>`,
|
||||
);
|
||||
expect(
|
||||
(w.get('[role="spinbutton"]').element as HTMLInputElement).disabled,
|
||||
).toBe(true);
|
||||
expect(new FormData(w.get("form").element).has("quantity")).toBe(false);
|
||||
});
|
||||
it("associates Label and multiple descriptions and removes stale references", async () => {
|
||||
const show = ref(true);
|
||||
const w = fixture(
|
||||
`<NumberField><Label>Amount</Label><NumberFieldGroup><NumberFieldInput id="amount" aria-describedby="external"/></NumberFieldGroup><Description v-if="show" id="help">Help</Description></NumberField>`,
|
||||
() => ({ show }),
|
||||
);
|
||||
expect(w.get("label").attributes("for")).toBe("amount");
|
||||
expect(w.get("input").attributes("aria-describedby")).toContain("help");
|
||||
show.value = false;
|
||||
await nextTick();
|
||||
expect(w.get("input").attributes("aria-describedby")).toBe("external");
|
||||
});
|
||||
it("blocks native invalid submit and surfaces FieldError", async () => {
|
||||
const submit = vi.fn();
|
||||
const w = fixture(
|
||||
`<Form @submit="submit"><NumberField is-required>${parts}</NumberField><button type="submit">Submit</button></Form>`,
|
||||
() => ({ submit }),
|
||||
);
|
||||
await w.get("form").trigger("submit");
|
||||
expect(submit).not.toHaveBeenCalled();
|
||||
expect(w.get('[data-slot="field-error"]').text()).toContain("请填写");
|
||||
expect(document.activeElement).toBe(w.get('[role="spinbutton"]').element);
|
||||
});
|
||||
it("aria validation exposes errors without blocking submission", async () => {
|
||||
const submit = vi.fn();
|
||||
const w = fixture(
|
||||
`<Form @submit.prevent="submit"><NumberField validation-behavior="aria" is-required>${parts}</NumberField></Form>`,
|
||||
() => ({ submit }),
|
||||
);
|
||||
await w.get("form").trigger("submit");
|
||||
expect(submit).toHaveBeenCalledTimes(1);
|
||||
expect(w.get('[role="spinbutton"]').attributes("aria-invalid")).toBe(
|
||||
"true",
|
||||
);
|
||||
});
|
||||
it("renders SSR associations before descriptions and explicit leaf IDs", async () => {
|
||||
const html = await renderToString(
|
||||
createSSRApp({
|
||||
render: () =>
|
||||
h(NumberField, {}, () => [
|
||||
h(Label, {}, () => "SSR"),
|
||||
h(NumberFieldGroup, {}, () =>
|
||||
h(NumberFieldInput, { id: "ssr-number" }),
|
||||
),
|
||||
h(Description, {}, () => "Help"),
|
||||
]),
|
||||
}),
|
||||
);
|
||||
expect(html).toContain('for="ssr-number"');
|
||||
const described = html.match(/aria-describedby="([^"]+)"/)?.[1];
|
||||
expect(described).toBeTruthy();
|
||||
expect(html).toContain(`id="${described}"`);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,17 @@
|
||||
# 独立打包消费用例
|
||||
|
||||
`consume-slider.mjs` 和 `slider-contract.ts` 应复制到工作区之外的全新 Vue 工程运行,依赖安装使用 `pnpm pack` 生成的两个 tarball,不设置指向源码的 paths/alias。private 样式包通过 pnpm overrides 指向本地样式 tarball。
|
||||
|
||||
库构建与打包后,在消费工程执行:
|
||||
|
||||
```sh
|
||||
node consume-slider.mjs
|
||||
pnpm exec tsc --noEmit --strict --skipLibCheck --module nodenext --moduleResolution nodenext --target es2022 slider-contract.ts
|
||||
pnpm exec tsc --noEmit --strict --skipLibCheck --module esnext --moduleResolution bundler --target es2022 slider-contract.ts
|
||||
```
|
||||
|
||||
`@ts-expect-error` 必须实际生效;出现 unused 指令是失败,不得删除反例。数字字段的 validate 参数也必须保留推断类型。`skipLibCheck` 只略过依赖内部诊断,不略过这些消费端反例。
|
||||
|
||||
SLIDER-01 已在 `/private/tmp/heroui-slider-consumer` 完成上述检查,临时契约文件名为 `contract.ts`。默认工作区 typecheck 仍使用源码 alias,所以不能代替此独立产物检查。
|
||||
|
||||
M30–M32 增加 consume-m30-m32.mjs 和 m30-m32-contract.ts。将它们复制到同一个独立消费工程,执行运行脚本,并将契约文件加入上述两种 tsc 命令。合并后的产物还应同时通过原 NumberField/Slider 消费检查,避免只验证新加组件。
|
||||
@@ -0,0 +1,49 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { readFileSync } from "node:fs";
|
||||
import { createSSRApp, h } from "vue";
|
||||
import { renderToString } from "@vue/server-renderer";
|
||||
import {
|
||||
InputOTP,
|
||||
InputOTPGroup,
|
||||
InputOTPSlot,
|
||||
Label,
|
||||
Header,
|
||||
Pagination,
|
||||
PaginationContent,
|
||||
PaginationItem,
|
||||
PaginationLink,
|
||||
} from "@heroui-vue/components";
|
||||
const html = await renderToString(
|
||||
createSSRApp({
|
||||
render: () =>
|
||||
h("div", [
|
||||
h(Header, {}, () => "Heading"),
|
||||
h(Pagination, {}, () =>
|
||||
h(PaginationContent, {}, () =>
|
||||
h(PaginationItem, {}, () =>
|
||||
h(PaginationLink, { "aria-current": "step" }, () => "1"),
|
||||
),
|
||||
),
|
||||
),
|
||||
h(InputOTP, { maxLength: 2, defaultValue: "12", name: "code" }, () => [
|
||||
h(Label, { id: "consumer-label" }, () => "Security code"),
|
||||
h(InputOTPGroup, {}, () => [
|
||||
h(InputOTPSlot, { index: 0 }),
|
||||
h(InputOTPSlot, { index: 1 }),
|
||||
]),
|
||||
]),
|
||||
]),
|
||||
}),
|
||||
);
|
||||
assert(html.includes('data-slot="header"'));
|
||||
assert(html.includes('aria-current="step"'));
|
||||
assert.equal(html.match(/aria-labelledby="consumer-label"/g)?.length, 2);
|
||||
assert(html.includes('value="12"'));
|
||||
assert(html.includes('name="code"'));
|
||||
const css = readFileSync(
|
||||
new URL(import.meta.resolve("@heroui-vue/styles/css")),
|
||||
"utf8",
|
||||
);
|
||||
for (const name of ["hv-header", "hv-pagination", "hv-input-otp"])
|
||||
assert(css.includes(name));
|
||||
console.log("M30–M32 independent tarball ESM/SSR/ARIA/CSS passed.");
|
||||
@@ -0,0 +1,45 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { readFileSync } from "node:fs";
|
||||
import { createSSRApp, h } from "vue";
|
||||
import { renderToString } from "@vue/server-renderer";
|
||||
import {
|
||||
Slider,
|
||||
SliderTrack,
|
||||
SliderFill,
|
||||
SliderThumb,
|
||||
SliderOutput,
|
||||
SliderMarks,
|
||||
Label,
|
||||
sliderVariants,
|
||||
} from "@heroui-vue/components";
|
||||
const html = await renderToString(
|
||||
createSSRApp({
|
||||
render: () =>
|
||||
h(Slider, { defaultValue: [20, 80], dir: "rtl" }, () => [
|
||||
h(Label, {}, () => "Price"),
|
||||
h(SliderOutput),
|
||||
h(SliderTrack, {}, () => [
|
||||
h(SliderFill),
|
||||
h(SliderThumb, { name: "min" }),
|
||||
h(SliderThumb, { name: "max", index: 1 }),
|
||||
]),
|
||||
h(SliderMarks),
|
||||
]),
|
||||
}),
|
||||
);
|
||||
assert(html.includes('aria-valuenow="20"'));
|
||||
assert(html.includes('aria-valuenow="80"'));
|
||||
assert(html.includes("right:20%"));
|
||||
assert(html.includes('name="min"'));
|
||||
assert(html.includes('name="max"'));
|
||||
const css = readFileSync(
|
||||
new URL(import.meta.resolve("@heroui-vue/styles/css")),
|
||||
"utf8",
|
||||
);
|
||||
assert(css.includes(".hv-slider__track"));
|
||||
assert(css.includes("prefers-reduced-motion"));
|
||||
assert(!css.includes(".hv-slider__thumb:after:not(:is())"));
|
||||
assert(sliderVariants().thumb().includes("hv-slider__thumb"));
|
||||
console.log(
|
||||
"Independent tarball consumer: ESM, SSR, CSS and six named parts passed.",
|
||||
);
|
||||
@@ -0,0 +1,19 @@
|
||||
import {
|
||||
type InputOTPProps,
|
||||
type PaginationProps,
|
||||
type HeaderProps,
|
||||
} from "@heroui-vue/components";
|
||||
const input: InputOTPProps = {
|
||||
maxLength: 4,
|
||||
modelValue: "1234",
|
||||
variant: "secondary",
|
||||
};
|
||||
const pager: PaginationProps = { size: "sm" };
|
||||
const heading: HeaderProps = { as: "header" };
|
||||
// @ts-expect-error public OTP values are strings
|
||||
const wrongModel: InputOTPProps = { maxLength: 4, modelValue: 1234 };
|
||||
// @ts-expect-error unsupported OTP variant
|
||||
const wrongVariant: InputOTPProps = { maxLength: 4, variant: "ghost" };
|
||||
// @ts-expect-error Pagination has a fixed size set
|
||||
const wrongSize: PaginationProps = { size: "xl" };
|
||||
void [input, pager, heading, wrongModel, wrongVariant, wrongSize];
|
||||
@@ -0,0 +1,24 @@
|
||||
import {
|
||||
type SliderProps,
|
||||
type SliderThumbProps,
|
||||
Slider,
|
||||
SliderTrack,
|
||||
SliderThumb,
|
||||
} from "@heroui-vue/components";
|
||||
const valid: SliderProps = { modelValue: [20, 80], orientation: "vertical" };
|
||||
const thumb: SliderThumbProps = { name: "max", index: 1, isDisabled: true };
|
||||
// @ts-expect-error model is numeric
|
||||
const invalid: SliderProps = { modelValue: "20" };
|
||||
// @ts-expect-error orientation is constrained
|
||||
const direction: SliderProps = { orientation: "diagonal" };
|
||||
void [valid, thumb, invalid, direction, Slider, SliderTrack, SliderThumb];
|
||||
import { type NumberFieldProps } from "@heroui-vue/components";
|
||||
const numeric: NumberFieldProps = {
|
||||
modelValue: null,
|
||||
validate: (value) => (value === null ? "Required" : true),
|
||||
};
|
||||
// @ts-expect-error NumberField public values must remain numeric in NodeNext too
|
||||
const badNumeric: NumberFieldProps = { modelValue: "12,5" };
|
||||
// @ts-expect-error index is numeric
|
||||
const badThumb: SliderThumbProps = { index: "1" };
|
||||
void [numeric, badNumeric, badThumb];
|
||||
@@ -0,0 +1,17 @@
|
||||
// @vitest-environment node
|
||||
import { expect, it } from "vitest";
|
||||
import { createSSRApp, h } from "vue";
|
||||
import { renderToString } from "@vue/server-renderer";
|
||||
import Foundation from "../packages/vue/tests/fixtures/SliderFoundation.vue";
|
||||
|
||||
it("records that raw collection thumbs have no value or stable position on the server", async () => {
|
||||
expect(typeof window).toBe("undefined");
|
||||
const html = await renderToString(
|
||||
createSSRApp({
|
||||
render: () => h(Foundation, { defaultValue: [20, 80] }),
|
||||
}),
|
||||
);
|
||||
expect(html.match(/role="slider"/g)).toHaveLength(2);
|
||||
expect(html).not.toContain("aria-valuenow=");
|
||||
expect(html).toContain("display:none");
|
||||
});
|
||||
@@ -0,0 +1,142 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { mount, flushPromises } from "@vue/test-utils";
|
||||
import { defineComponent, h } from "vue";
|
||||
import Foundation from "../packages/vue/tests/fixtures/SliderFoundation.vue";
|
||||
|
||||
// Installed Reka capability audit only. Public Slider tests must assert adapter fixes.
|
||||
const wrappers: ReturnType<typeof mount>[] = [];
|
||||
// No geometry assertions here: pointer layout/dragging requires a real browser.
|
||||
beforeEach(() => {
|
||||
vi.stubGlobal(
|
||||
"ResizeObserver",
|
||||
class {
|
||||
observe() {}
|
||||
unobserve() {}
|
||||
disconnect() {}
|
||||
},
|
||||
);
|
||||
});
|
||||
afterEach(() => {
|
||||
wrappers.splice(0).forEach((wrapper) => wrapper.unmount());
|
||||
document.body.innerHTML = "";
|
||||
vi.unstubAllGlobals();
|
||||
});
|
||||
function fixture(props: Record<string, unknown>, attrs = {}) {
|
||||
const wrapper = mount(Foundation, {
|
||||
props,
|
||||
attrs,
|
||||
attachTo: document.body,
|
||||
});
|
||||
wrappers.push(wrapper);
|
||||
return wrapper;
|
||||
}
|
||||
function form(props: Record<string, unknown>) {
|
||||
const wrapper = mount(
|
||||
defineComponent({
|
||||
render: () => h("form", {}, [h(Foundation, props)]),
|
||||
}),
|
||||
{ attachTo: document.body },
|
||||
);
|
||||
wrappers.push(wrapper);
|
||||
return wrapper;
|
||||
}
|
||||
const value = (wrapper: ReturnType<typeof mount>, index = 0) =>
|
||||
wrapper.findAll('[role="slider"]')[index].attributes("aria-valuenow");
|
||||
|
||||
describe("Slider foundation: installed Reka capabilities and adapter gaps", () => {
|
||||
it("steps decimals precisely and commits keyboard changes at bounds", async () => {
|
||||
const wrapper = fixture({
|
||||
defaultValue: [0.2],
|
||||
min: 0,
|
||||
max: 0.3,
|
||||
step: 0.1,
|
||||
});
|
||||
await flushPromises();
|
||||
const thumb = wrapper.get('[role="slider"]');
|
||||
await thumb.trigger("focus");
|
||||
await thumb.trigger("keydown", { key: "ArrowRight" });
|
||||
expect(value(wrapper)).toBe("0.3");
|
||||
expect(wrapper.emitted("update:modelValue")).toEqual([[[0.3]]]);
|
||||
expect(wrapper.emitted("valueCommit")).toEqual([[[0.3]]]);
|
||||
await thumb.trigger("keydown", { key: "ArrowRight" });
|
||||
expect(wrapper.emitted("valueCommit")).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("keeps the selected range thumb during keyboard movement", async () => {
|
||||
const wrapper = fixture({ defaultValue: [20, 80] });
|
||||
await flushPromises();
|
||||
const second = wrapper.findAll('[role="slider"]')[1];
|
||||
await second.trigger("focus");
|
||||
await second.trigger("keydown", { key: "ArrowLeft" });
|
||||
expect([value(wrapper), value(wrapper, 1)]).toEqual(["20", "79"]);
|
||||
});
|
||||
|
||||
it("uses logical horizontal direction and upward vertical increments", async () => {
|
||||
const wrapper = fixture({ defaultValue: [20], dir: "rtl" });
|
||||
await flushPromises();
|
||||
await wrapper
|
||||
.get('[role="slider"]')
|
||||
.trigger("keydown", { key: "ArrowRight" });
|
||||
expect(value(wrapper)).toBe("19");
|
||||
await wrapper.setProps({ orientation: "vertical" });
|
||||
await wrapper.get('[role="slider"]').trigger("keydown", { key: "ArrowUp" });
|
||||
expect(value(wrapper)).toBe("20");
|
||||
});
|
||||
|
||||
it("restores controlled thumbs after rejection and emits each repeated proposal", async () => {
|
||||
const wrapper = fixture({ modelValue: [20] });
|
||||
await flushPromises();
|
||||
const thumb = wrapper.get('[role="slider"]');
|
||||
await thumb.trigger("keydown", { key: "ArrowRight" });
|
||||
await thumb.trigger("keydown", { key: "ArrowRight" });
|
||||
expect(value(wrapper)).toBe("20");
|
||||
expect(wrapper.emitted("update:modelValue")).toEqual([[[21]], [[21]]]);
|
||||
// Raw Reka also reports commits for proposals rejected by the parent.
|
||||
expect(wrapper.emitted("valueCommit")).toEqual([[[21]], [[21]]]);
|
||||
});
|
||||
|
||||
it("records indexed form names and no native reset coordination", async () => {
|
||||
const wrapper = form({ defaultValue: [20, 80], name: "range" });
|
||||
await flushPromises();
|
||||
expect([...new FormData(wrapper.get("form").element).entries()]).toEqual([
|
||||
["range[0]", "20"],
|
||||
["range[1]", "80"],
|
||||
]);
|
||||
await wrapper
|
||||
.get('[role="slider"]')
|
||||
.trigger("keydown", { key: "ArrowRight" });
|
||||
wrapper.get("form").element.reset();
|
||||
await flushPromises();
|
||||
expect(value(wrapper)).toBe("21");
|
||||
expect(new FormData(wrapper.get("form").element).get("range[0]")).toBe(
|
||||
"21",
|
||||
);
|
||||
});
|
||||
|
||||
it("omits disabled submission values and removes thumb Tab stops", async () => {
|
||||
const wrapper = form({
|
||||
defaultValue: [20, 80],
|
||||
name: "range",
|
||||
disabled: true,
|
||||
});
|
||||
await flushPromises();
|
||||
expect([...new FormData(wrapper.get("form").element).entries()]).toEqual(
|
||||
[],
|
||||
);
|
||||
const thumb = wrapper.get('[role="slider"]');
|
||||
expect(thumb.attributes("tabindex")).toBeUndefined();
|
||||
await thumb.trigger("keydown", { key: "End" });
|
||||
expect(value(wrapper)).toBe("20");
|
||||
});
|
||||
|
||||
it("records that cancelling user keydown does not stop raw stepping", async () => {
|
||||
const cancel = vi.fn((event: KeyboardEvent) => event.preventDefault());
|
||||
const wrapper = fixture({ defaultValue: [20] }, { onKeydown: cancel });
|
||||
await flushPromises();
|
||||
await wrapper
|
||||
.get('[role="slider"]')
|
||||
.trigger("keydown", { key: "ArrowRight" });
|
||||
expect(cancel).toHaveBeenCalledOnce();
|
||||
expect(value(wrapper)).toBe("21");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,37 @@
|
||||
// @vitest-environment node
|
||||
import { expect, it } from "vitest";
|
||||
import { createSSRApp, h } from "vue";
|
||||
import { renderToString } from "@vue/server-renderer";
|
||||
import {
|
||||
Slider,
|
||||
SliderTrack,
|
||||
SliderFill,
|
||||
SliderThumb,
|
||||
SliderOutput,
|
||||
Label,
|
||||
} from "../packages/vue/src";
|
||||
it("renders explicit native range values, positions and composed label on the server", async () => {
|
||||
expect(typeof window).toBe("undefined");
|
||||
const html = await renderToString(
|
||||
createSSRApp({
|
||||
render: () =>
|
||||
h(Slider, { defaultValue: [20, 80] }, () => [
|
||||
h(Label, {}, () => "Price"),
|
||||
h(SliderOutput),
|
||||
h(SliderTrack, {}, () => [
|
||||
h(SliderFill),
|
||||
h(SliderThumb, { name: "min" }),
|
||||
h(SliderThumb, { index: 1, name: "max" }),
|
||||
]),
|
||||
]),
|
||||
}),
|
||||
);
|
||||
expect(html).toContain('aria-valuenow="20"');
|
||||
expect(html).toContain('aria-valuenow="80"');
|
||||
expect(html).toContain("left:20%");
|
||||
expect(html).toContain("left:80%");
|
||||
expect(html).not.toContain("display:none");
|
||||
const labelId = html.match(/<span[^>]*id="([^"]+)"/)?.[1];
|
||||
expect(labelId).toBeDefined();
|
||||
expect(html).toContain(`aria-labelledby="${labelId}"`);
|
||||
});
|
||||
@@ -0,0 +1,331 @@
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { mount, flushPromises } from "@vue/test-utils";
|
||||
import { createSSRApp, defineComponent, h, ref } from "vue";
|
||||
import { renderToString } from "@vue/server-renderer";
|
||||
import {
|
||||
Slider,
|
||||
SliderTrack,
|
||||
SliderFill,
|
||||
SliderThumb,
|
||||
SliderOutput,
|
||||
SliderMarks,
|
||||
Label,
|
||||
Description,
|
||||
Fieldset,
|
||||
ConfigProvider,
|
||||
} from "../packages/vue/src";
|
||||
const wrappers: ReturnType<typeof mount>[] = [];
|
||||
afterEach(async () => {
|
||||
wrappers.splice(0).forEach((wrapper) => wrapper.unmount());
|
||||
await flushPromises();
|
||||
document.body.innerHTML = "";
|
||||
});
|
||||
const parts =
|
||||
"<Label>Volume</Label><SliderOutput/><SliderTrack><SliderFill/><SliderThumb/></SliderTrack>";
|
||||
function fixture(template: string, setup = () => ({})) {
|
||||
const wrapper = mount(
|
||||
defineComponent({
|
||||
components: {
|
||||
Slider,
|
||||
SliderTrack,
|
||||
SliderFill,
|
||||
SliderThumb,
|
||||
SliderOutput,
|
||||
SliderMarks,
|
||||
Label,
|
||||
Description,
|
||||
Fieldset,
|
||||
ConfigProvider,
|
||||
},
|
||||
setup,
|
||||
template,
|
||||
}),
|
||||
{ attachTo: document.body },
|
||||
);
|
||||
wrappers.push(wrapper);
|
||||
return wrapper;
|
||||
}
|
||||
const sliders = (wrapper: ReturnType<typeof mount>) =>
|
||||
wrapper.findAll('input[type="range"]');
|
||||
const values = (wrapper: ReturnType<typeof mount>) =>
|
||||
sliders(wrapper).map((input) => (input.element as HTMLInputElement).value);
|
||||
|
||||
describe("Slider public contracts", () => {
|
||||
it("maps baseline data slots, initial value, output and native Label association", async () => {
|
||||
const wrapper = fixture(`<Slider :default-value="30">${parts}</Slider>`);
|
||||
await flushPromises();
|
||||
expect(values(wrapper)).toEqual(["30"]);
|
||||
expect(wrapper.get("output").text()).toBe("30");
|
||||
expect(wrapper.get("input").attributes("aria-labelledby")).toContain(
|
||||
wrapper.get("[data-slot=label]").attributes("id"),
|
||||
);
|
||||
expect(
|
||||
wrapper.findAll('[data-slot^="slider"]').length,
|
||||
).toBeGreaterThanOrEqual(6);
|
||||
});
|
||||
it("uses number events for one thumb and supports decimal bounds without duplicate end events", async () => {
|
||||
const update = vi.fn(),
|
||||
end = vi.fn();
|
||||
const wrapper = fixture(
|
||||
`<Slider :default-value="0.2" :max-value="0.3" :step="0.1" @update:model-value="update" @change-end="end">${parts}</Slider>`,
|
||||
() => ({ update, end }),
|
||||
);
|
||||
await wrapper.get("input").trigger("keydown", { key: "ArrowRight" });
|
||||
expect(values(wrapper)).toEqual(["0.3"]);
|
||||
expect(update.mock.calls).toEqual([[0.3]]);
|
||||
expect(end.mock.calls).toEqual([[0.3]]);
|
||||
await wrapper.get("input").trigger("keydown", { key: "End" });
|
||||
expect(end).toHaveBeenCalledOnce();
|
||||
});
|
||||
it("keeps explicit range index and prevents crossing adjacent thumbs", async () => {
|
||||
const update = vi.fn();
|
||||
const wrapper = fixture(
|
||||
`<Slider :default-value="[20,80]" @update:model-value="update"><SliderTrack><SliderThumb name="lower"/><SliderThumb :index="1" name="upper"/></SliderTrack></Slider>`,
|
||||
() => ({ update }),
|
||||
);
|
||||
await sliders(wrapper)[1].trigger("keydown", { key: "ArrowLeft" });
|
||||
expect(values(wrapper)).toEqual(["20", "79"]);
|
||||
expect(update).toHaveBeenLastCalledWith([20, 79]);
|
||||
await sliders(wrapper)[0].trigger("keydown", { key: "End" });
|
||||
expect(values(wrapper)).toEqual(["79", "79"]);
|
||||
});
|
||||
it("restores rejected controlled native input and allows identical retries", async () => {
|
||||
const update = vi.fn();
|
||||
const wrapper = fixture(
|
||||
`<Slider :model-value="20" @update:model-value="update">${parts}</Slider>`,
|
||||
() => ({ update }),
|
||||
);
|
||||
for (let i = 0; i < 2; i++) {
|
||||
await wrapper.get("input").setValue("30");
|
||||
await flushPromises();
|
||||
}
|
||||
expect(values(wrapper)).toEqual(["20"]);
|
||||
expect(update.mock.calls).toEqual([[30], [30]]);
|
||||
});
|
||||
it("reacts to controlled ownership additions/removals and explicit undefined", async () => {
|
||||
const props = ref<Record<string, unknown>>({});
|
||||
const wrapper = fixture(
|
||||
`<Slider v-bind="props" :default-value="40">${parts}</Slider>`,
|
||||
() => ({ props }),
|
||||
);
|
||||
props.value = { modelValue: undefined };
|
||||
await flushPromises();
|
||||
expect(values(wrapper)).toEqual(["0"]);
|
||||
props.value = { modelValue: [20] };
|
||||
await flushPromises();
|
||||
expect(values(wrapper)).toEqual(["20"]);
|
||||
props.value = {};
|
||||
await flushPromises();
|
||||
expect(values(wrapper)).toEqual(["40"]);
|
||||
});
|
||||
it("honors cancelled keydown handlers, arrays and capture", async () => {
|
||||
const cancel = (event: Event) => event.preventDefault();
|
||||
const update = vi.fn();
|
||||
const wrapper = fixture(
|
||||
`<Slider @update:model-value="update"><SliderTrack><SliderThumb :onKeydown="[cancel]"/></SliderTrack></Slider>`,
|
||||
() => ({ cancel, update }),
|
||||
);
|
||||
await wrapper.get("input").trigger("keydown", { key: "End" });
|
||||
await flushPromises();
|
||||
expect(update).not.toHaveBeenCalled();
|
||||
expect(values(wrapper)).toEqual(["0"]);
|
||||
const capture = fixture(
|
||||
`<Slider @keydown.capture.prevent><SliderTrack><SliderThumb/></SliderTrack></Slider>`,
|
||||
);
|
||||
await capture.get("input").trigger("keydown", { key: "End" });
|
||||
expect(values(capture)).toEqual(["0"]);
|
||||
});
|
||||
it("honors stopImmediatePropagation without executing internal stepping", async () => {
|
||||
const stop = (event: Event) => event.stopImmediatePropagation();
|
||||
const wrapper = fixture(
|
||||
`<Slider><SliderTrack><SliderThumb @keydown="stop"/></SliderTrack></Slider>`,
|
||||
() => ({ stop }),
|
||||
);
|
||||
await wrapper.get("input").trigger("keydown", { key: "End" });
|
||||
expect(values(wrapper)).toEqual(["0"]);
|
||||
});
|
||||
it("submits each named native input once, omits a disabled thumb, inherits Fieldset", async () => {
|
||||
const disabled = ref(false);
|
||||
const wrapper = fixture(
|
||||
`<form><Fieldset :disabled="disabled"><Slider :default-value="[20,80]"><SliderTrack><SliderThumb name="range"/><SliderThumb :index="1" name="range" is-disabled/></SliderTrack></Slider></Fieldset></form>`,
|
||||
() => ({ disabled }),
|
||||
);
|
||||
expect(new FormData(wrapper.get("form").element).getAll("range")).toEqual([
|
||||
"20",
|
||||
]);
|
||||
await sliders(wrapper)[1].trigger("keydown", { key: "Home" });
|
||||
expect(values(wrapper)).toEqual(["20", "80"]);
|
||||
disabled.value = true;
|
||||
await flushPromises();
|
||||
expect(new FormData(wrapper.get("form").element).getAll("range")).toEqual(
|
||||
[],
|
||||
);
|
||||
expect(
|
||||
sliders(wrapper).every(
|
||||
(input) => (input.element as HTMLInputElement).disabled,
|
||||
),
|
||||
).toBe(true);
|
||||
});
|
||||
it("resets the initial native/submitted range and respects cancelled reset", async () => {
|
||||
const wrapper = fixture(
|
||||
`<form><Slider :default-value="[20,80]"><SliderTrack><SliderThumb name="a"/><SliderThumb :index="1" name="b"/></SliderTrack></Slider></form>`,
|
||||
);
|
||||
await sliders(wrapper)[0].trigger("keydown", { key: "ArrowRight" });
|
||||
wrapper.get("form").element.reset();
|
||||
await flushPromises();
|
||||
expect(values(wrapper)).toEqual(["20", "80"]);
|
||||
expect([...new FormData(wrapper.get("form").element).values()]).toEqual([
|
||||
"20",
|
||||
"80",
|
||||
]);
|
||||
wrapper
|
||||
.get("form")
|
||||
.element.addEventListener("reset", (event) => event.preventDefault());
|
||||
await sliders(wrapper)[0].trigger("keydown", { key: "ArrowRight" });
|
||||
wrapper.get("form").element.reset();
|
||||
await flushPromises();
|
||||
expect(values(wrapper)).toEqual(["21", "80"]);
|
||||
});
|
||||
it("preserves controlled reset and external form association", async () => {
|
||||
const wrapper = fixture(
|
||||
`<div><form id="outside"/><Slider :model-value="50"><SliderTrack><SliderThumb name="a" form="outside"/></SliderTrack></Slider></div>`,
|
||||
);
|
||||
wrapper.get("form").element.reset();
|
||||
await flushPromises();
|
||||
expect(values(wrapper)).toEqual(["50"]);
|
||||
expect(new FormData(wrapper.get("form").element).getAll("a")).toEqual([
|
||||
"50",
|
||||
]);
|
||||
});
|
||||
it("moves in RTL/vertical direction, formats values through ConfigProvider", async () => {
|
||||
const wrapper = fixture(
|
||||
`<ConfigProvider dir="rtl" locale="de-DE"><Slider :default-value="1234" :max-value="2000"><SliderOutput/><SliderTrack><SliderThumb/></SliderTrack></Slider></ConfigProvider>`,
|
||||
);
|
||||
expect(wrapper.get("output").text()).toBe("1.234");
|
||||
await wrapper.get("input").trigger("keydown", { key: "ArrowRight" });
|
||||
expect(values(wrapper)).toEqual(["1233"]);
|
||||
expect(
|
||||
wrapper.get("[data-slot=slider-thumb]").attributes("style"),
|
||||
).toContain("right:");
|
||||
const vertical = fixture(
|
||||
`<Slider orientation="vertical" :default-value="40">${parts}</Slider>`,
|
||||
);
|
||||
await vertical
|
||||
.get("input")
|
||||
.trigger("keydown", { key: "ArrowUp", shiftKey: true });
|
||||
expect(values(vertical)).toEqual(["50"]);
|
||||
expect(vertical.get("input").attributes("aria-orientation")).toBe(
|
||||
"vertical",
|
||||
);
|
||||
});
|
||||
it("updates explicit attrs, description IDs, classes and custom output", async () => {
|
||||
const show = ref(true),
|
||||
attributes = ref<Record<string, unknown>>({
|
||||
"aria-label": "Custom",
|
||||
class: "custom-thumb",
|
||||
});
|
||||
const wrapper = fixture(
|
||||
`<Slider :default-value="[10,90]"><Description id="help" v-if="show">Help</Description><SliderOutput v-slot="{values}">{{values.join(' to ')}}</SliderOutput><SliderTrack><SliderFill/><SliderThumb v-bind="attributes"/><SliderThumb :index="1"/></SliderTrack><SliderMarks data-test="marks"/></Slider>`,
|
||||
() => ({ show, attributes }),
|
||||
);
|
||||
await flushPromises();
|
||||
expect(wrapper.get("output").text()).toBe("10 to 90");
|
||||
expect(sliders(wrapper)[0].attributes("aria-describedby")).toBe("help");
|
||||
expect(wrapper.get(".custom-thumb").attributes("data-slot")).toBe(
|
||||
"slider-thumb",
|
||||
);
|
||||
attributes.value = {};
|
||||
show.value = false;
|
||||
await flushPromises();
|
||||
expect(sliders(wrapper)[0].attributes("aria-label")).toBeUndefined();
|
||||
expect(sliders(wrapper)[0].attributes("aria-describedby")).toBeUndefined();
|
||||
expect(wrapper.find(".custom-thumb").exists()).toBe(false);
|
||||
});
|
||||
it("hydrates explicit range positions and names without warnings", async () => {
|
||||
const app = {
|
||||
render: () =>
|
||||
h(Slider, { defaultValue: [20, 80] }, () => [
|
||||
h(Label, {}, () => "Price"),
|
||||
h(SliderTrack, {}, () => [
|
||||
h(SliderFill),
|
||||
h(SliderThumb),
|
||||
h(SliderThumb, { index: 1 }),
|
||||
]),
|
||||
]),
|
||||
};
|
||||
const html = await renderToString(createSSRApp(app));
|
||||
const container = document.createElement("div");
|
||||
container.innerHTML = html;
|
||||
document.body.append(container);
|
||||
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
|
||||
const error = vi.spyOn(console, "error").mockImplementation(() => {});
|
||||
const client = createSSRApp(app);
|
||||
try {
|
||||
client.mount(container);
|
||||
await flushPromises();
|
||||
expect(warn).not.toHaveBeenCalled();
|
||||
expect(error).not.toHaveBeenCalled();
|
||||
expect(
|
||||
[...container.querySelectorAll("input")].map((input) => input.value),
|
||||
).toEqual(["20", "80"]);
|
||||
} finally {
|
||||
client.unmount();
|
||||
warn.mockRestore();
|
||||
error.mockRestore();
|
||||
}
|
||||
});
|
||||
it("compiles and mounts all nine baseline demos without Vue warnings", async () => {
|
||||
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
|
||||
try {
|
||||
for (const name of [
|
||||
"default",
|
||||
"disabled",
|
||||
"vertical",
|
||||
"range",
|
||||
"controlled",
|
||||
"custom-value-formatting",
|
||||
"custom-output",
|
||||
"render-function",
|
||||
"custom-styles",
|
||||
]) {
|
||||
const demo = await import(`../apps/docs/demos/slider-${name}.vue`);
|
||||
const wrapper = mount(demo.default, { attachTo: document.body });
|
||||
try {
|
||||
await flushPromises();
|
||||
expect(sliders(wrapper).length).toBeGreaterThan(0);
|
||||
} finally {
|
||||
wrapper.unmount();
|
||||
}
|
||||
}
|
||||
expect(warn).not.toHaveBeenCalled();
|
||||
} finally {
|
||||
warn.mockRestore();
|
||||
}
|
||||
});
|
||||
it("keeps off-grid maxima consistent with actual native input and output", async () => {
|
||||
const wrapper = fixture(
|
||||
`<Slider :default-value="0.8" :step="0.3" :max-value="0.8">${parts}</Slider>`,
|
||||
);
|
||||
expect(values(wrapper)).toEqual(["0.6"]);
|
||||
expect(wrapper.get("input").attributes("aria-valuenow")).toBe("0.6");
|
||||
expect(wrapper.get("output").text()).toBe("0.6");
|
||||
await wrapper.get("input").trigger("keydown", { key: "End" });
|
||||
expect(values(wrapper)).toEqual(["0.6"]);
|
||||
});
|
||||
it("rebinds reset to a dynamically changed native form owner", async () => {
|
||||
const owner = ref("first");
|
||||
const wrapper = fixture(
|
||||
`<div><form id="first"/><form id="second"/><Slider :default-value="20"><SliderTrack><SliderThumb :form="owner" name="amount"/></SliderTrack></Slider></div>`,
|
||||
() => ({ owner }),
|
||||
);
|
||||
await wrapper.get("input").trigger("keydown", { key: "ArrowRight" });
|
||||
owner.value = "second";
|
||||
await flushPromises();
|
||||
wrapper.get("#first").element.dispatchEvent(new Event("reset"));
|
||||
await flushPromises();
|
||||
expect(values(wrapper)).toEqual(["21"]);
|
||||
(wrapper.get("#second").element as HTMLFormElement).reset();
|
||||
await flushPromises();
|
||||
expect(values(wrapper)).toEqual(["20"]);
|
||||
});
|
||||
});
|
||||
@@ -567,3 +567,35 @@ it("renders Toolbar with nested groups without browser globals", async () => {
|
||||
expect(html).toContain("hv-separator--horizontal");
|
||||
expect(html).toContain('data-slot="button-group"');
|
||||
});
|
||||
|
||||
it("renders NumberField in node with initial control associations and numeric submission", async () => {
|
||||
const {
|
||||
NumberField,
|
||||
NumberFieldGroup,
|
||||
NumberFieldInput,
|
||||
Label,
|
||||
Description,
|
||||
} = await import("../packages/vue/src");
|
||||
const html = await renderToString(
|
||||
createSSRApp({
|
||||
render: () =>
|
||||
h(
|
||||
NumberField,
|
||||
{ defaultValue: 12.5, name: "amount", locale: "de-DE" },
|
||||
() => [
|
||||
h(Label, {}, () => "Amount"),
|
||||
h(NumberFieldGroup, {}, () => [h(NumberFieldInput)]),
|
||||
h(Description, {}, () => "Help"),
|
||||
],
|
||||
),
|
||||
}),
|
||||
);
|
||||
expect(html).toContain('value="12,5"');
|
||||
expect(html).toContain('name="amount"');
|
||||
const inputId = html.match(/for="([^"]+)"/)?.[1];
|
||||
expect(inputId).toBeTruthy();
|
||||
expect(html).toContain(`id="${inputId}"`);
|
||||
const descriptionId = html.match(/aria-describedby="([^"]+)"/)?.[1];
|
||||
expect(descriptionId).toBeTruthy();
|
||||
expect(html).toContain(`id="${descriptionId}"`);
|
||||
});
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
import {
|
||||
NumberField,
|
||||
type NumberFieldProps,
|
||||
numberFieldVariants,
|
||||
} from "../../packages/vue/src";
|
||||
const valid: NumberFieldProps = {
|
||||
modelValue: null,
|
||||
defaultValue: 2,
|
||||
minValue: 0,
|
||||
maxValue: 10,
|
||||
step: 0.1,
|
||||
locale: "de-DE",
|
||||
variant: "secondary",
|
||||
validationBehavior: "aria",
|
||||
validate: (value) => (value === null ? "Required" : true),
|
||||
};
|
||||
// @ts-expect-error public value is numeric, not a localized display string
|
||||
const invalidValue: NumberFieldProps = { modelValue: "1.234,5" };
|
||||
// @ts-expect-error unsupported variant
|
||||
const invalidVariant: NumberFieldProps = { variant: "ghost" };
|
||||
// @ts-expect-error no async validation protocol
|
||||
const invalidValidator: NumberFieldProps = { validate: async () => true };
|
||||
void [
|
||||
NumberField,
|
||||
valid,
|
||||
invalidValue,
|
||||
invalidVariant,
|
||||
invalidValidator,
|
||||
numberFieldVariants,
|
||||
];
|
||||
@@ -0,0 +1,16 @@
|
||||
import {
|
||||
type SliderProps,
|
||||
type SliderThumbProps,
|
||||
type SliderValue,
|
||||
} from "../../packages/vue/src";
|
||||
const scalar: SliderProps = { modelValue: 10, orientation: "vertical" };
|
||||
const range: SliderProps = { modelValue: [10, 90], step: 0.1 };
|
||||
const thumb: SliderThumbProps = { index: 1, name: "max", isDisabled: true };
|
||||
// @ts-expect-error Slider does not accept formatted strings
|
||||
const invalid: SliderProps = { modelValue: "$10" };
|
||||
// @ts-expect-error invalid orientation
|
||||
const direction: SliderProps = { orientation: "diagonal" };
|
||||
// @ts-expect-error input indices are numeric
|
||||
const badIndex: SliderThumbProps = { index: "1" };
|
||||
const value: SliderValue = [10, 90];
|
||||
void [scalar, range, thumb, invalid, direction, badIndex, value];
|
||||
Reference in New Issue
Block a user