fix: enforce handbook scrollbar and reduced motion contracts

This commit is contained in:
maoyingjie
2026-10-27 21:10:51 +08:00
parent b1344d8a4c
commit 202e3a5b5d
23 changed files with 702 additions and 23 deletions
+19
View File
@@ -0,0 +1,19 @@
/* Adapted from HeroUI ce90ea3, packages/styles/base/scrollbar.css.
* Copyright 2025 NextUI Inc. Apache-2.0; see third-party/HEROUI-LICENSE. */
[data-scrollbar="thin"] {
--scrollbar-width: thin;
--scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
--scrollbar-gutter: auto;
}
[data-scrollbar="default"] {
--scrollbar-width: auto;
--scrollbar-color: auto;
--scrollbar-gutter: auto;
}
[data-scrollbar="none"] {
--scrollbar-width: none;
--scrollbar-color: auto;
--scrollbar-gutter: auto;
}
@@ -174,6 +174,7 @@
&[data-exiting="true"],
&[data-entering="true"] {
@apply transition-[opacity,transform] will-change-[opacity,transform];
@apply motion-reduce:animate-none motion-reduce:transition-none;
}
/* Arrow styling */
+1
View File
@@ -143,6 +143,7 @@
&[data-exiting="true"],
&[data-entering="true"] {
@apply transition-[opacity,transform] will-change-[opacity,transform];
@apply motion-reduce:animate-none motion-reduce:transition-none;
}
/* Arrow styling */
@@ -79,6 +79,7 @@
&[data-exiting="true"],
&[data-entering="true"] {
@apply transition-[opacity,transform] will-change-[opacity,transform];
@apply motion-reduce:animate-none motion-reduce:transition-none;
}
}
@@ -83,6 +83,7 @@
&[data-exiting="true"],
&[data-entering="true"] {
@apply transition-[opacity,transform] will-change-[opacity,transform];
@apply motion-reduce:animate-none motion-reduce:transition-none;
}
}
+7 -19
View File
@@ -215,25 +215,13 @@
var(--drawer-exit-ease);
}
/* Reduced motion must beat the direction-specific animation rules above. */
@media (prefers-reduced-motion: reduce) {
.hv-drawer__dialog[data-entering="true"],
.hv-drawer__dialog[data-exiting="true"],
.hv-drawer__dialog[data-entering="true"][data-placement="left"],
.hv-drawer__dialog[data-entering="true"][data-placement="right"],
.hv-drawer__dialog[data-entering="true"][data-placement="top"],
.hv-drawer__dialog[data-entering="true"][data-placement="bottom"],
.hv-drawer__dialog[data-exiting="true"][data-placement="left"],
.hv-drawer__dialog[data-exiting="true"][data-placement="right"],
.hv-drawer__dialog[data-exiting="true"][data-placement="top"],
.hv-drawer__dialog[data-exiting="true"][data-placement="bottom"] {
animation: none;
}
.hv-drawer__backdrop[data-entering="true"],
.hv-drawer__backdrop[data-exiting="true"] {
animation: none;
}
/* Reduced motion must beat direction-specific animation rules, including
* explicit data-reduce-motion on the element or its portal ancestor. */
.hv-drawer__dialog[data-entering="true"][data-placement],
.hv-drawer__dialog[data-exiting="true"][data-placement],
.hv-drawer__backdrop[data-entering="true"],
.hv-drawer__backdrop[data-exiting="true"] {
@apply motion-reduce:animate-none;
}
@keyframes hv-drawer-backdrop-in {
+1
View File
@@ -97,6 +97,7 @@
&[data-exiting="true"],
&[data-entering="true"] {
@apply transition-[opacity,transform] will-change-[opacity,transform];
@apply motion-reduce:animate-none motion-reduce:transition-none;
}
/* Arrow styling */
+1
View File
@@ -42,6 +42,7 @@
&[data-exiting="true"],
&[data-entering="true"] {
@apply transition-[opacity,transform] will-change-[opacity,transform];
@apply motion-reduce:animate-none motion-reduce:transition-none;
}
/* Arrow styling */
+1
View File
@@ -232,6 +232,7 @@
&[data-exiting="true"],
&[data-entering="true"] {
@apply transition-[opacity,transform] will-change-[opacity,transform];
@apply motion-reduce:animate-none motion-reduce:transition-none;
}
/* Arrow styling */
+5
View File
@@ -46,3 +46,8 @@
.hv-skeleton--none {
}
/* Also covers the synchronized parent shimmer pseudo-elements. */
.hv-skeleton {
@apply motion-reduce:animate-none;
}
+1
View File
@@ -40,6 +40,7 @@
&[data-exiting="true"],
&[data-entering="true"] {
@apply transition-[opacity,transform] will-change-[opacity,transform];
@apply motion-reduce:animate-none motion-reduce:transition-none;
}
/* Arrow styling */
+2
View File
@@ -3,6 +3,8 @@
@import "tailwindcss/preflight.css" layer(base);
@import "./themes/shared/theme.css";
@import "./themes/default/variables.css";
/* Mode overrides must follow theme defaults so an explicit mode on a theme root wins. */
@import "./base/scrollbar.css" layer(base);
@import "./utilities/index.css";
@import "./animations.css";
@import "./variants/index.css";
@@ -40,12 +40,22 @@ export function useOverlayAnimation(
if (!animation || animation === "none") entering.value = false;
};
const observer = new MutationObserver(check);
observer.observe(el, { attributes: true, attributeFilter: ["style"] });
if (floating && wrapper)
observer.observe(wrapper, {
observer.observe(el, {
attributes: true,
attributeFilter: ["data-reduce-motion", "class", "style"],
});
// Reduced motion can change on a theme/portal ancestor while an entrance
// runs. A cancelled animation has no animationend to clear its marker.
for (
let ancestor = el.parentElement;
ancestor;
ancestor = ancestor.parentElement
)
observer.observe(ancestor, {
attributes: true,
attributeFilter: ["style"],
attributeFilter: ["data-reduce-motion", "class", "style"],
});
el.addEventListener("animationcancel", check);
const media = el.ownerDocument.defaultView?.matchMedia?.(
"(prefers-reduced-motion: reduce)",
);
@@ -54,6 +64,7 @@ export function useOverlayAnimation(
onCleanup(() => {
stale = true;
observer.disconnect();
el.removeEventListener("animationcancel", check);
media?.removeEventListener("change", check);
});
},