fix: enforce handbook scrollbar and reduced motion contracts
This commit is contained in:
@@ -326,6 +326,43 @@ it("keeps non-modal content interactive outside without claiming a modal lock",
|
||||
});
|
||||
|
||||
describe("floating overlay animation lifecycle", () => {
|
||||
it("clears an entrance cancelled by an ancestor reduced-motion change", async () => {
|
||||
const { useOverlayAnimation } =
|
||||
await import("../packages/vue/src/components/overlay/animation");
|
||||
const element = ref<HTMLElement>();
|
||||
const reduced = ref(false);
|
||||
let phase!: ReturnType<typeof useOverlayAnimation>;
|
||||
const realStyle = getComputedStyle;
|
||||
const css = vi
|
||||
.spyOn(window, "getComputedStyle")
|
||||
.mockImplementation((el) => {
|
||||
if (el === element.value)
|
||||
return {
|
||||
animationName: el.closest('[data-reduce-motion="true"]')
|
||||
? "none"
|
||||
: "enter",
|
||||
} as CSSStyleDeclaration;
|
||||
return realStyle(el);
|
||||
});
|
||||
try {
|
||||
fixture(
|
||||
'<section :data-reduce-motion="reduced ? \'true\' : undefined"><div ref="element" /></section>',
|
||||
() => {
|
||||
phase = useOverlayAnimation(ref(true), element);
|
||||
return { element, reduced };
|
||||
},
|
||||
);
|
||||
await settle();
|
||||
expect(phase.entering.value).toBe(true);
|
||||
reduced.value = true;
|
||||
await settle();
|
||||
// No synthetic animationend: CSS cancels the entrance entirely.
|
||||
expect(phase.entering.value).toBe(false);
|
||||
} finally {
|
||||
css.mockRestore();
|
||||
}
|
||||
});
|
||||
|
||||
async function animationFixture(transform: string, animated = true) {
|
||||
const { useOverlayAnimation } =
|
||||
await import("../packages/vue/src/components/overlay/animation");
|
||||
|
||||
@@ -17,6 +17,20 @@ for (const id of process.argv.slice(2)) {
|
||||
assert(css.includes(token), `Missing CSS ${token}`);
|
||||
for (const name of spec.absent ?? [])
|
||||
assert(!(name in lib), `Private component exposed: ${name}`);
|
||||
if (id === "handbook-styles") {
|
||||
const extended = lib.tv({
|
||||
extend: lib.buttonVariants,
|
||||
variants: { intent: { quiet: "audit-quiet" } },
|
||||
});
|
||||
const classes = extended({ intent: "quiet", size: "sm" });
|
||||
assert(
|
||||
classes.includes("hv-button--sm") && classes.includes("audit-quiet"),
|
||||
);
|
||||
// This proves final CSS packaging; computed style and lifecycle assertions
|
||||
// run separately in apps/playground/src/HandbookLab.vue.
|
||||
for (const mode of ["none", "default", "thin"])
|
||||
assert(new RegExp(`\\[data-scrollbar=["']?${mode}["']?\\]`).test(css));
|
||||
}
|
||||
if (id === "b02-pickers") {
|
||||
assert(
|
||||
lib
|
||||
|
||||
@@ -1,4 +1,23 @@
|
||||
{
|
||||
"handbook-styles": {
|
||||
"exports": [
|
||||
"Button",
|
||||
"Input",
|
||||
"Popover",
|
||||
"Table",
|
||||
"buttonVariants",
|
||||
"tv",
|
||||
"cn"
|
||||
],
|
||||
"css": [
|
||||
"data-scrollbar",
|
||||
"--scrollbar-width",
|
||||
"data-reduce-motion",
|
||||
".hv-skeleton",
|
||||
".hv-drawer__dialog",
|
||||
".hv-popover"
|
||||
]
|
||||
},
|
||||
"b01-menu-dropdown": {
|
||||
"exports": [
|
||||
"DropdownRoot",
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
import { h } from "vue";
|
||||
import {
|
||||
Button,
|
||||
Input,
|
||||
buttonVariants,
|
||||
type ButtonProps,
|
||||
} from "@heroui-vue/components";
|
||||
import { tv, type VariantProps, type ButtonVariants } from "@heroui-vue/styles";
|
||||
|
||||
const extended = tv({
|
||||
extend: buttonVariants,
|
||||
variants: { intent: { quiet: "opacity-70", loud: "font-bold" } },
|
||||
});
|
||||
type Extended = VariantProps<typeof extended>;
|
||||
const valid: Extended = { intent: "quiet", size: "sm" };
|
||||
extended(valid);
|
||||
const native: ButtonProps = { asChild: true, variant: "secondary" };
|
||||
h(Button, native, () => h("button", { type: "button" }, "Native composition"));
|
||||
h(Input, {
|
||||
"aria-label": "Field",
|
||||
class: ["custom"],
|
||||
style: { color: "var(--foreground)" },
|
||||
});
|
||||
// @ts-expect-error custom intent remains typed
|
||||
const badIntent: Extended = { intent: "missing" };
|
||||
// @ts-expect-error built-in variants remain typed
|
||||
const badVariant: ButtonVariants = { variant: "missing" };
|
||||
void badIntent;
|
||||
void badVariant;
|
||||
Reference in New Issue
Block a user