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
@@ -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);
});
},