BlockDex

Components

Registries

Free blocks

Method

BlockDex

Components

Registries

Free blocks

Method

Open API

BlockDex

Components

Registries

Free blocks

Method

Open API

Components/ericts-ui/use-scroll-anchor

useScrollAnchor

ericts-ui/use-scroll-anchor
FreeHook

A client-safe React hook that parks a selected item at a fixed anchor point in a scroll container, with a configurable easing and duration — the click-to-scroll behavior for navigation panels, command palettes, and step lists.

Install it

npx shadcn@latest add https://ui.ericts.com/r/use-scroll-anchor.json

Source

registry/base/hooks/use-scroll-anchor.tsui.ericts.com/r/use-scroll-anchor.json · first 6 KB
1"use client";
2
3import { useCallback, useEffect, useLayoutEffect, useRef } from "react";
4
5const DEFAULT_ANCHOR_RATIO = 1 / 3;
6const DEFAULT_MIN_DURATION = 160;
7const DEFAULT_MAX_DURATION = 320;
8const DEFAULT_DISTANCE_DURATION_RATIO = 0.45;
9const DEFAULT_TARGET_SELECTOR = "[data-scroll-anchor]";
10
11const useIsomorphicLayoutEffect =
12 typeof window === "undefined" ? useEffect : useLayoutEffect;
13
14export type ScrollAnchorKey = string | number | null | undefined;
15export type ScrollAnchorEasing = (progress: number) => number;
16
17/** Ready-made `progress → progress` easings to pass as `easing`. */
18export const scrollAnchorEasings = {
19 easeOutQuart: (progress: number) => 1 - (1 - progress) ** 4,
20 easeOutCubic: (progress: number) => 1 - (1 - progress) ** 3,
21 easeInOutCubic: (progress: number) =>
22 progress < 0.5
23 ? 4 * progress * progress * progress
24 : 1 - (-2 * progress + 2) ** 3 / 2,
25 linear: (progress: number) => progress,
26} satisfies Record<string, ScrollAnchorEasing>;
27
28export type UseScrollAnchorOptions<T extends HTMLElement> = {
29 /** When this changes while `enabled`, the active target is re-anchored. */
30 activeKey: ScrollAnchorKey;
31 /** Gate the behavior (e.g. only while a panel is open). Defaults to `true`. */
32 enabled?: boolean;
33 /**
34 * Where the target should land: `0` = top edge, `0.5` = vertical center,
35 * `1` = bottom edge. Defaults to `1 / 3` (upper third).
36 */
37 anchorRatio?: number;
38 /**
39 * Locate the element to anchor within the container. Defaults to the first
40 * `[data-scroll-anchor]` descendant.
41 */
42 getTarget?: (container: T) => HTMLElement | null;
43 /**
44 * Ease to the anchor when the key changes. On the first run after enabling —
45 * and whenever the user prefers reduced motion — the jump is instant. Defaults
46 * to `true`.
47 */
48 animate?: boolean;
49 /** Easing for the animated scroll. Defaults to `scrollAnchorEasings.easeOutQuart`. */
50 easing?: ScrollAnchorEasing;
51 /**
52 * Animation length in ms — a fixed number, or a function of the scroll
53 * distance in px. Omit for a distance-proportional ramp (160–320ms).
54 */
55 duration?: number | ((distance: number) => number);
56 /** Jump instantly when the user prefers reduced motion. Defaults to `true`. */
57 respectReducedMotion?: boolean;
58 /** Fires once the target reaches its anchor (after animating or jumping). */
59 onSettled?: () => void;
60};
61
62export type UseScrollAnchorResult<T extends HTMLElement> = {
63// … truncated

Files it writes

  • registry/base/hooks/use-scroll-anchor.ts

Facts

Registry
ericts-ui
Type
registry:hook
Access
Free
Files written
1
Licence
MIT
In the index
at or before 2026-08-08
Last confirmed
yesterday

Go to the source

Docs on ericts-ui ui.ericts.com EricTsai83/ericts-ui on GitHub Raw registry item This item as JSON

More from ericts-ui

All 38 items
Same registry, same kind — the ones you would have found next
ComponentRegistryKindAccessInstallsCommand
useElementHeightuse-element-heightericts-uiHooksFreeno deps
useElementSizeMapuse-element-size-mapericts-uiHooksFreeno deps
useReducedMotionuse-reduced-motionericts-uiHooksFreeno deps
useScrollProgressuse-scroll-progressericts-uiHooksFreeno deps

Also from Kynth Studios

Built for the same person as BlockDex

SkillWorks

Claude Code skills and plugins, scored

skillworks.kynth.studio

RuleStack

AGENTS.md gallery and agent-config comparison

rulestack.kynth.studio

ToolDrift

What the AI coding tools changed last night

tooldrift.kynth.studio

The studio list

One product, taken apart, once a month

Kynth Studios pulls one shipped product open every month — what it does, what it cost to build, what the pipeline behind it looks like, and what the numbers did. One email a month, nothing in between.

Double opt-in — we send one confirmation link and nothing else until you click it.

BlockDex

Built by

Kynth Studios

the studio behind SkillWorks, RuleStack and ToolDrift

part of Toolproof, the measurement layer for AI agent tooling

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

© 2026 BlockDex. A Kynth Studios product. Changelog

BlockDex

The studio list

One product, taken apart, once a month

Kynth Studios pulls one shipped product open every month — what it does, what it cost to build, what the pipeline behind it looks like, and what the numbers did. One email a month, nothing in between.

Double opt-in — we send one confirmation link and nothing else until you click it.

BlockDex

Built by

Kynth Studios

the studio behind SkillWorks, RuleStack and ToolDrift

part of Toolproof, the measurement layer for AI agent tooling

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

© 2026 BlockDex. A Kynth Studios product. Changelog

BlockDex

The studio list

One product, taken apart, once a month

Kynth Studios pulls one shipped product open every month — what it does, what it cost to build, what the pipeline behind it looks like, and what the numbers did. One email a month, nothing in between.

Double opt-in — we send one confirmation link and nothing else until you click it.

BlockDex

Built by

Kynth Studios

the studio behind SkillWorks, RuleStack and ToolDrift

part of Toolproof, the measurement layer for AI agent tooling

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

© 2026 BlockDex. A Kynth Studios product. Changelog

BlockDex