labs

dot navigation

2026-11-08

a few pixels of navigation

inspired by the sidebars on recent.design and gustavo fior’s craft. recent places a dot after the current label, so changing sections moves it sideways as well as down. craft puts it before the label and shifts the selected text to make room. both make a few pixels do the work of a whole highlighted row.

the arc and the handover

this version measures the actual label and sends one dot along an arc whose width grows with the distance between entries. a neighbouring row gets a small curve; a jump across groups takes a wider path. the incoming dot nudges the selected label aside as it arrives, while the old label springs home.

changing your mind mid-flight carries the dot’s position and velocity into the next arc. switching its placement takes it over the active label while the text settles into its new position.

selection that stays yours

hover never steals the current page: it only changes the label colour, while keyboard focus has its own outline and enter moves the dot immediately. a resize observer and a font-ready measurement keep it attached after the layout changes, and reduced motion makes every move immediate. these are ordinary links with aria-current, so the example can hand selection to a router without becoming a custom tab widget.

take it with you

three steps, and the stage above runs in your own project.

  1. install

    nothing to add. it runs on react alone, 18 or newer.

  2. copy

    4 files, kept together in one folder, dot-navigation/. the styles travel with them.

    "use client";
    
    import { useLayoutEffect, useRef, type ReactNode } from "react";
    import "./dot-navigation.css";
    import { useDotMotion } from "./useDotMotion";
    
    export interface NavigationGroup {
      label: string;
      icon?: ReactNode;
      items: { id: string; label: string; href: string }[];
    }
    
    // Inspired by recent.design and craft.gustavofior.com.
    export default function DotNavigation({ groups, activeId, onNavigate, leading = true, label = "Sections" }: {
      groups: NavigationGroup[];
      activeId: string;
      onNavigate?: (id: string) => void;
      leading?: boolean;
      label?: string;
    }) {
      const root = useRef<HTMLElement>(null);
      const dot = useRef<HTMLSpanElement>(null);
      const links = useRef(new Map<string, HTMLAnchorElement>());
      const motion = useDotMotion(root, dot, links);
      const placed = useRef(false);
      const remeasure = useRef<() => void>(() => {});
      const previousLeading = useRef(leading);
    
      useLayoutEffect(() => {
        const nav = root.current;
        const indicator = dot.current;
        if (!nav || !indicator) return;
        const measure = (instant: boolean) => {
          const link = links.current.get(activeId);
          const text = link?.querySelector("span");
          if (!link || !text) { indicator.style.visibility = "hidden"; return; }
          const box = nav.getBoundingClientRect();
          const row = link.getBoundingClientRect();
          const fontSize = parseFloat(getComputedStyle(nav).fontSize);
          const push = leading ? fontSize : -fontSize * 2 / 3;
          const dotSize = parseFloat(getComputedStyle(indicator).height);
          const x = row.left - box.left + (leading ? 0 : (text as HTMLElement).offsetWidth + push + fontSize * .55);
          const y = row.top - box.top + row.height / 2 - dotSize / 2;
          motion.current({ x, y, id: activeId, leading, push }, instant);
          placed.current = true;
        };
        const placementChanged = previousLeading.current !== leading;
        measure(!placed.current || (!placementChanged && nav.dataset.motion !== "pointer"));
        previousLeading.current = leading;
        remeasure.current = () => measure(true);
      }, [activeId, groups, leading, motion]);
    
      useLayoutEffect(() => {
        const nav = root.current;
        if (!nav) return;
        let initial = true;
        const observer = new ResizeObserver(() => {
          if (initial) { initial = false; return; }
          remeasure.current();
        });
        observer.observe(nav);
        links.current.forEach((link) => observer.observe(link));
        return () => observer.disconnect();
      }, [groups]);
    
      useLayoutEffect(() => {
        let cancelled = false;
        const measure = () => remeasure.current();
        void document.fonts.ready.then(() => { if (!cancelled) measure(); });
        document.fonts.addEventListener("loadingdone", measure);
        return () => { cancelled = true; document.fonts.removeEventListener("loadingdone", measure); };
      }, []);
    
      return (
        <nav className="dn-nav" ref={root} aria-label={label} data-leading={leading}
          onKeyDown={() => { if (root.current) root.current.dataset.motion = "keyboard"; }}>
          <span ref={dot} className="dn-dot" aria-hidden="true" />
          {groups.map((group) => (
            <div className="dn-group" key={group.label}>
              <p className="dn-heading">{group.icon && <span className="dn-group-icon" aria-hidden="true">{group.icon}</span>}{group.label}</p>
              <ul>
                {group.items.map((item) => (
                  <li key={item.id}>
                    <a href={item.href} ref={(el) => { if (el) links.current.set(item.id, el); else links.current.delete(item.id); }}
                      aria-current={activeId === item.id ? "page" : undefined}
                      onClick={(event) => {
                        if (!onNavigate || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey || event.button !== 0) return;
                        event.preventDefault();
                        if (root.current) root.current.dataset.motion = event.detail === 0 ? "keyboard" : "pointer";
                        onNavigate(item.id);
                      }}>
                      <span>{item.label}</span>
                    </a>
                  </li>
                ))}
              </ul>
            </div>
          ))}
        </nav>
      );
    }
    
  3. use

    the stage above, exactly as it runs here. the comments mark what to change.

    example.tsx
    "use client";
    
    import { useState } from "react";
    import DotNavigation, { type NavigationGroup } from "./dot-navigation/DotNavigation";
    
    function GroupIcon({ kind }: { kind: "work" | "practice" }) {
      return (
        <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round"
          style={{ color: kind === "work" ? "oklch(0.58 0.17 255)" : "oklch(0.62 0.14 45)" }}>
          {kind === "work" ? <>
            <rect x="3" y="7" width="18" height="14" rx="3" />
            <path d="M8 7V5a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2M3 12a23 23 0 0 0 18 0M12 11v4" />
          </> : <>
            <path d="m14 3 7 7-8 10-10 1 1-10L14 3ZM3 21l7-7M12 5l7 7" />
            <circle cx="11" cy="13" r="2" />
          </>}
        </svg>
      );
    }
    
    const GROUPS: NavigationGroup[] = [
      { label: "work", icon: <GroupIcon kind="work" />, items: [
        { id: "projects", label: "selected projects", href: "#projects" },
        { id: "experiments", label: "experiments", href: "#experiments" },
        { id: "notes", label: "notes", href: "#notes" },
      ] },
      { label: "practice", icon: <GroupIcon kind="practice" />, items: [
        { id: "about", label: "about", href: "#about" },
        { id: "now", label: "now", href: "#now" },
      ] },
    ];
    
    export default function DotNavigationExample({ leading = true, onSelect }: { leading?: boolean; onSelect?: () => void }) {
      const [active, setActive] = useState("projects");
      return (
        <div className="dn-lab">
          {/* In a routed app, derive activeId from the URL and use your own destinations. */}
          <DotNavigation groups={GROUPS} activeId={active} onNavigate={(id) => { if (id !== active) { setActive(id); onSelect?.(); } }} leading={leading} />
        </div>
      );
    }