Skip to content

useScrollIntoView

function useScrollIntoView(nodeRef): (options?) => void;

Returns a function that scrolls the nearest parent ScrollView to make the referenced node visible.

This is the non-focusable counterpart to handle.scrollIntoView() — use it with plain Box refs or any GlyphNode.

Works both when the calling component is inside the ScrollView (via React context) and when it is outside (by walking up the target node’s parent chain).

ParameterTypeDescription
nodeRef{ current: GlyphNode | null; }React ref pointing to the target node.
nodeRef.currentGlyphNode | null-

A stable callback you can invoke to scroll to the node.

(options?): void;
ParameterType
options?ScrollIntoViewOptions

void

const boxRef = useRef<GlyphNode>(null);
const scrollIntoView = useScrollIntoView(boxRef);
// Later, e.g. in an effect or event handler:
scrollIntoView(); // minimal scroll
scrollIntoView({ block: "center" }); // center in viewport