@payfit/unity-components
Version:
14 lines (13 loc) • 761 B
TypeScript
import { MutableRefObject, RefObject } from 'react';
export type ScrollDirection = 'up' | 'down' | 'idle';
/**
* Detects the scroll direction from the nearest scrollable ancestor.
* @param scrollContainerRef - Optional explicit scroll container. If omitted, the
* hook walks the DOM from the returned `elementRef` to find the nearest scrollable
* ancestor, falling back to `window`.
* @returns A tuple of `[elementRef, direction]`. Attach `elementRef` to the
* component's root element to enable auto-detection.
* @remarks
* - When `prefers-reduced-motion` is active, direction is always `'idle'`.
*/
export declare function useScrollDirection(scrollContainerRef?: RefObject<Element | null>): [MutableRefObject<Element | null>, ScrollDirection];