When to use
- Forms, settings pages and toolbars people move through with
Tab, where a ring that travels shows where focus went. - A panel of mixed controls (inputs, toggles, segmented controls, buttons) that should share one consistent focus style.
- Custom controls whose focusable element is hidden, such as a styled checkbox, where the ring should circle the visible label instead.
When not to use
- A single control: its own
focus-ringis enough. - Long scrolling documents with focus targets far apart: the ring travels the whole distance, which reads as noise rather than guidance.
- Composite widgets that move focus with arrow keys over many items (grids, long menus), where the item highlight already shows the position.
Installation
pnpm dlx shadcn add @eased-pro/gliding-focus-ringnpx shadcn add @eased-pro/gliding-focus-ringyarn dlx shadcn add @eased-pro/gliding-focus-ringbunx --bun shadcn add @eased-pro/gliding-focus-ringInstalls from the @eased-pro registry and MCP server. · Already have Pro? Sign in.
Install the dependencies
pnpm add motionnpm install motionyarn add motionbun add motionAdd the Eased pieces it builds on
Copy each item’s files the same way, or install them with the CLI:
Add the files
- components/eased/gliding-focus-ring/gliding-focus-ring.tsx
Source is included with Eased Pro. Members download the files with the CLI command above, or through the MCP server.
Keep the folder layout
The files import each other by relative path (
../lib/motion), so keep each one at the path shown, undercomponents/eased/.
Usage
import { GlidingFocus } from "@/components/eased/gliding-focus-ring/gliding-focus-ring";export function Example() { return ( <GlidingFocus className="flex flex-col gap-3 p-4"> <label className="flex flex-col gap-1.5 text-ui-sm"> Name <input defaultValue="Maya Rao" className="h-control-md rounded-control border border-line-strong px-3.5" /> </label> <label className="flex flex-col gap-1.5 text-ui-sm"> Email <input type="email" defaultValue="maya@northwind.studio" className="h-control-md rounded-control border border-line-strong px-3.5" /> </label> <button type="submit" className="h-control-sm rounded-control-sm bg-brand px-3 text-text-on-brand"> Save </button> </GlidingFocus> );}Examples
Ring a wrapper, or opt an element out
data-focus-ring on an ancestor of a focusable element rings that ancestor instead, e.g. a custom checkbox whose input is visually hidden. data-focus-ring="none" on an element or an ancestor hides the ring for it, for fields that show focus with their own border.
<GlidingFocus> <label data-focus-ring className="flex items-center gap-2 rounded-control-sm px-2 py-1"> <input type="checkbox" className="sr-only" /> Email me a weekly digest </label> <input data-focus-ring="none" className="border border-line-strong focus:border-text" /></GlidingFocus>Per-element offset and colour
data-focus-offset on the ringed element overrides offset for it; ringClassName restyles the ring.
<GlidingFocus offset={2} thickness={2} ringClassName="border-brand"> <button type="button" data-focus-offset="4" className="size-9 rounded-pill"> MR </button></GlidingFocus>On an element you already render
useGlidingFocus(ref, options) returns the ring to place inside your own element. The element must be positioned and should be isolate, as GlidingFocus's root is.
import { useRef, type ReactNode } from "react";import { useGlidingFocus } from "@/components/eased/gliding-focus-ring/gliding-focus-ring";function Toolbar({ children }: { children: ReactNode }) { const ref = useRef<HTMLDivElement>(null); const ring = useGlidingFocus(ref, { offset: 3 }); return ( <div ref={ref} role="toolbar" aria-label="Formatting" className="relative isolate flex gap-1"> {children} {ring} </div> );}API reference
GlidingFocus
| Prop | Type | Default | Description |
|---|---|---|---|
offset | number | 2 | Gap between the focused element's edge and the ring, in px. Per element: data-focus-offset="4". |
thickness | number | 2 | Ring stroke width, in px. |
ringClassName | string | "" | Extra classes for the ring, e.g. border-brand to recolour it. The default colour is border-focus. |
disabled | boolean | false | Draw nothing and leave native focus outlines alone. |
onTargetChange | (target: HTMLElement | null) => void | The element the ring moves to, or null when it hides. | |
className | string | "" | Appended to the root's classes (relative isolate). |
Every other div prop passes through to the root. ref is not forwarded; use useGlidingFocus when you need the element.
useGlidingFocus
useGlidingFocus(root: RefObject<HTMLElement | null>, options?: GlidingFocusOptions): ReactNode. The options are the props above, without className. Render the returned node inside root.
Data attributes
| Attribute | On | Effect |
|---|---|---|
data-focus-ring | An ancestor of a focusable element | Rings the ancestor instead of the focused element. |
data-focus-ring="none" | The element or an ancestor | No ring; the element shows its own focus. |
data-focus-offset="4" | The ringed element | Overrides offset for it. |
data-gliding-focus="on" | Set on the root by the component | Present while the ring is drawn; native :focus-visible outlines inside are made transparent. |
Keyboard
| Key | Action |
|---|---|
Tab / Shift+Tab | Moves focus as usual; the ring glides to the newly focused element inside the root. |
Any other key without Cmd, Ctrl or Alt | Counts as keyboard use, so the next focus inside the root draws the ring. |
A pointer press anywhere hides the ring until the next key press. Focus leaving the root hides it too.
Accessibility
- The ring is a decoration: it is
aria-hidden, takes no pointer events and does not change focus order or roles. - It shows only for keyboard focus that also matches
:focus-visible. Text inputs match:focus-visibleeven on click, so the component tracks the last input method itself and a click into a field draws nothing. - While the ring is drawn, native focus outlines inside the root are set to
transparentrather than removed, and Tailwind ring shadows (Eased'sfocus-ringglow) are cleared, so there is one ring. In forced-colors mode the native outline still paints. - Focus moved by script after a pointer press draws no ring and is left to the element's native focus style, since outlines are only suppressed while the ring is drawn.
Motion
The ring is one empty, contained box whose position, width, height and four corner radii each spring on snappy, the same spring as every Eased thumb and indicator, so Tab reads as one ring travelling rather than rings blinking on and off. Each radius is the target's own (capped at half its shorter side) plus the offset and thickness, so the ring stays concentric with pills, inputs and squares alike. On first appearance it starts 3px outside its target and settles onto it while fading in over 200ms, so it lands rather than pops; it fades out in 100ms. Scrolling and resizing keep it glued without animating, and retarget a glide already in flight. Reduced motion: the ring jumps between targets with no settle, fading in over 100ms.
Notes for AI
Wrap a form, settings panel or toolbar in GlidingFocus when keyboard focus should travel visibly between controls. Leave offset and thickness at their defaults unless the design calls for a looser ring; use data-focus-ring on custom control wrappers and data-focus-ring="none" on inputs that already change their border on focus.
Do not add focus-visible:outline-none or remove focus-ring from children to make room for it: the root suppresses them only while the ring is drawn. Do not nest two GlidingFocus roots, and do not animate focus styles yourself inside one.
Related components
- Animated Segmented Control: an indicator that glides on the same spring.
- Form Field with Validation: the label and input layout the ring usually travels through.
- Progressive Blur Effect