Sidebar Collapse

A nav that shrinks to an icon rail, with the icons holding still and only the labels leaving.

Build a sidebar that collapses to an icon rail. Structure: a nav whose width animates between a full width and a narrow rail, with rows of icon plus label, and a toggle button beside it. The detail that decides whether it feels solid: THE ICONS NEVER MOVE. Give each icon a fixed width and flex-shrink 0 so it sits at the same x in both states. Let the icons slide with the container and the nav feels loose, and the eye loses the row it was reading. Animate the container WIDTH on a spring (stiffness 420, damping 40) AND fade the labels out with a 4px slide. Animating only the width clips the text mid-letter; fading only the labels leaves an empty rail the width of the full nav. Stagger the labels about 20ms per row, so they leave as a sequence rather than all at once. That is what makes the collapse read as one movement instead of four. When collapsed, add aria-label AND title to every row. Without them, a collapsed rail is four unlabelled glyphs to a screen reader and a guess to everybody else. Drop both when the labels are visible, so the name is not announced twice. Keep the active row's accent background on the ICON, so the current page is still visible at rail width. The toggle needs aria-expanded and a label that changes between "Collapse sidebar" and "Expand sidebar". A lone chevron does not say what it will do. Under prefers-reduced-motion, use zero duration on the width and no label slide. Both layouts are correct; only the transition is gone. Colors as tokens: accent with on-primary ink for the active row, surface and border for the panel, primary ink for the rest. Build the component, not this demo of it. - Ambient motion that IS the component may loop: a drifting background, a marquee, a spinner while something is genuinely loading. - Do not add any timer, interval, loop or script that performs a person's action by itself. No auto-hover, no auto-click, no cycling through states, no pretend submitting, no replaying the interaction on a schedule. - Every state that answers a person waits for a real event from that person. - Placeholder copy and sample content are welcome. Simulated behaviour is not.

Rate it
0
0

We'd like to measure how the site gets used, with Google Analytics. It sets cookies. Everything the site needs to work runs either way. How we handle data