UNPKG

@assistant-ui/react

Version:

TypeScript/React library for AI Chat

29 lines 1.23 kB
import { type RefObject } from "react"; /** * Locks scroll position during collapsible/height animations and hides scrollbar. * * This utility prevents page jumps when content height changes during animations, * providing a smooth user experience. It finds the nearest scrollable ancestor and * temporarily locks its scroll position while the animation completes. * * - Prevents forced reflows: no layout reads, mutations scoped to scrollable parent only * - Reactive: only intercepts scroll events when browser actually adjusts * - Cleans up automatically after animation duration * * @param animatedElementRef - Ref to the animated element * @param animationDuration - Lock duration in milliseconds * @returns Function to activate the scroll lock * * @example * ```tsx * const collapsibleRef = useRef<HTMLDivElement>(null); * const lockScroll = useScrollLock(collapsibleRef, 200); * * const handleCollapse = () => { * lockScroll(); // Lock scroll before collapsing * setIsOpen(false); * }; * ``` */ export declare const useScrollLock: <T extends HTMLElement = HTMLElement>(animatedElementRef: RefObject<T | null>, animationDuration: number) => () => void; //# sourceMappingURL=useScrollLock.d.ts.map