Skip to content
WunderUI

useGlide

Pro

Lets hover marks glide from point to point and fade out in place, instead of jumping or vanishing.

import { useGlide } from "@wunderui/react/charts"

Playground

Hover the chart, or focus it and press an arrow key

Installation

useGlide comes with WunderUI Core and Pro, in the entry of the package from your plan. See the plans. Then import it:

tsx
import { useGlide } from "@wunderui/react/charts"

When to use

Use useGlide for

  • A custom SVG chart with a hover dot, a crosshair or a band that follows the pointer or the keyboard marker.
  • Any mark that moves between a few fixed positions and should fade out in place instead of vanishing.
  • Several marks that share one index, such as a crosshair and a dot, so they move together.

Use something else for

  • Line Chart for a finished chart. Its hover marks already glide.
  • Area Chart for the same, for filled series.
  • useChartInteraction for the pointer and keyboard handling that produces the active index of a chart. It feeds this hook; it does not animate.
  • A plain CSS transition for a mark that is always on screen and never needs to fade out. on the element is enough.

Signature

Give it the active index, or when nothing is active. keeps the last active point while the marks fade out, says whether they show, and is true for the one render in which they appear, so they jump into place the first time and glide from then on. Pair it with , an SVG group that moves by a CSS transform on the token and the entrance curve.

ts
useGlide(active: number | null): Glide

Parameters

ParameterTypeDescription
activenumber | nullThe index of the point under the pointer or the keyboard marker, or when nothing is active. The hook does not read events; you set it from your own handlers or from .

Returns

An object to read the position from and hand to : keep the group mounted, place it at and drive it with and .

FieldTypeDescription
indexnumber | nullThe index to draw the marks at: the active one, or the last active one while the marks fade out. It is until something has been active once, so read it as .
visibleboolean while is not . Pass it to , which fades in and out with it.
snapboolean in the render where the marks appear after being hidden. Pass it to so they jump to the new spot, fading in, instead of gliding from where they were last.

Behavior and motion

The hook only remembers; the movement is the CSS transition of `GlideGroup`.

State
The hook keeps the last non-null in a ref and the visibility of the previous render in another one. is that last value, is , and is true when the marks are visible now and were not in the previous render. The ref is updated after every commit, so is true for the render in which the marks appear and false in the next one.
Why snap
While the marks are hidden they stay mounted at their last position. Without , the first move after re-entering would slide them from there to the new spot while they fade in. With the position changes at once and only the opacity fades.
Server rendering
The hook uses no browser API, only state and refs, so it renders the same on the server and the client. writes its position as an inline transform, so the server markup already carries it.
Cleanup
Nothing to clean up: no timers, no listeners. The fade and the glide are transitions that the browser owns.
Motion
moves with on and . A transition retargets from where it is, so sliding across a plot is a smooth follow. With only opacity transitions, on . Only and change, so nothing triggers layout. The group is and ignores the pointer.
Reduced motion
Under the transform is not transitioned: the marks jump to the new position and still fade in and out.

Best practices

  • Do

    Keep mounted and drive it with . A mark that is unmounted when nothing is active has nothing to fade out and nothing to glide from.

  • Don’t

    Do not render the marks only while . They would vanish at once and appear without the fade.

  • Do

    Read the data for a label or a dot from , not from . is while the marks fade out, so a label read from it would disappear before the fade has finished.

  • Do

    Pass to every that follows the same index.

  • Don’t

    Do not animate , or on your own marks. Position them with , which moves by .

  • Do

    Announce the active point in a live region next to the chart. The marks are and carry no text for screen readers.

  • Don’t

    Do not put controls inside a . It ignores the pointer and is hidden from assistive technology.

Notes for AI

Give your coding assistant the page or the MCP call instead of screenshots.

MCPget_component("useGlide")
Importimport { useGlide } from "@wunderui/react/charts"

The full library index for assistants is at /llms.txt.