Reveal
import { useId, useRef, useState } from 'react';
const TABS = [
{ label: 'Dawn', title: '6:12 am', body: 'First light, cool and still. Best for long shadows.' },
{ label: 'Noon', title: '12:40 pm', body: 'Hard light from overhead. Look for shade.' },
{ label: 'Dusk', title: '7:58 pm', body: 'The golden hour, soft and warm.' },
];
const SURFACES = ['light-dark(#ebedf0, #232529)', 'light-dark(#cbced3, #393c41)', 'light-dark(#dbdde1, #2e3035)'];
const css = `
@keyframes tabs-reveal-open { from { clip-path: circle(0% at var(--tabs-reveal-x) 0%); } to { clip-path: circle(160% at var(--tabs-reveal-x) 0%); } }
.tabs-reveal { width: 260px; }
.tabs-reveal__list { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; margin-bottom: 8px; }
.tabs-reveal__tab { padding: 8px 0; border: 0; border-radius: 8px; background: none; color: light-dark(#5f626a, #a7abb2); font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; transition: color 0.2s, background-color 0.2s; }
.tabs-reveal__tab:hover { color: light-dark(#42454c, #e5e6e9); }
.tabs-reveal__tab[aria-selected='true'] { background: light-dark(#f3f4f7, #1a1c1f); color: light-dark(#373a40, #f1f2f3); }
.tabs-reveal__tab:focus-visible { outline: 2px solid light-dark(#5f626a, #a7abb2); outline-offset: 2px; }
.tabs-reveal__stage { display: grid; overflow: hidden; border-radius: 12px; }
.tabs-reveal__panel { grid-area: 1 / 1; padding: 16px; background: var(--tabs-reveal-bg); }
.tabs-reveal__panel[data-prev] { z-index: 0; }
.tabs-reveal__panel[data-on] { z-index: 1; }
.tabs-reveal[data-armed] .tabs-reveal__panel[data-on] { animation: tabs-reveal-open 0.6s cubic-bezier(0.4, 0, 0.2, 1); }
.tabs-reveal__title { display: block; margin-bottom: 4px; color: light-dark(#373a40, #f1f2f3); font-size: 18px; font-weight: 600; letter-spacing: -0.01em; }
.tabs-reveal__body { color: light-dark(#42454c, #e5e6e9); font-size: 12.5px; line-height: 1.5; }
@media (prefers-reduced-motion: reduce) {
.tabs-reveal__panel { animation: none !important; }
}
`;
export function RevealTabs() {
const id = useId();
const [state, setState] = useState({ sel: 0, prev: -1 });
const tabs = useRef<(HTMLButtonElement | null)[]>([]);
const { sel, prev } = state;
const select = (i: number) => {
if (i !== sel) setState({ sel: i, prev: sel });
};
const onKeyDown = (e: React.KeyboardEvent) => {
const n = TABS.length;
const next = { ArrowRight: (sel + 1) % n, ArrowLeft: (sel + n - 1) % n, Home: 0, End: n - 1 }[e.key];
if (next === undefined) return;
e.preventDefault();
select(next);
tabs.current[next]?.focus();
};
return (
<>
<style>
{css}
</style>
<div
className="tabs-reveal"
data-armed={prev >= 0 ? '' : undefined}
style={{ '--tabs-reveal-x': `${((sel + 0.5) / TABS.length) * 100}%` } as React.CSSProperties}
>
<div className="tabs-reveal__list" role="tablist" aria-label="Light" onKeyDown={onKeyDown}>
{TABS.map((t, i) => (
<button
key={t.label}
ref={(el) => {
tabs.current[i] = el;
}}
className="tabs-reveal__tab"
type="button"
role="tab"
id={`${id}-tab-${i}`}
aria-selected={sel === i}
aria-controls={`${id}-panel-${i}`}
tabIndex={sel === i ? 0 : -1}
onClick={() => select(i)}
>
{t.label}
</button>
))}
</div>
<div className="tabs-reveal__stage">
{/* The panel you left stays underneath, out of reach, while the new one opens over it. */}
{TABS.map((t, i) => (
<div
key={t.label}
className="tabs-reveal__panel"
role="tabpanel"
id={`${id}-panel-${i}`}
aria-labelledby={`${id}-tab-${i}`}
hidden={i !== sel && i !== prev}
aria-hidden={i === prev || undefined}
inert={i === prev}
data-on={i === sel ? '' : undefined}
data-prev={i === prev ? '' : undefined}
style={{ '--tabs-reveal-bg': SURFACES[i] } as React.CSSProperties}
>
<span className="tabs-reveal__title">{t.title}</span>
<span className="tabs-reveal__body">{t.body}</span>
</div>
))}
</div>
</div>
</>
);
}Markup where the component goes, CSS in your stylesheet, script before </body>. In Vue, Svelte or Angular, call initTabsReveal(el) on the mounted element instead.
<div class="tabs-reveal" style="--tabs-reveal-x:16.666666666666664%">
<div class="tabs-reveal__list" role="tablist" aria-label="Light">
<button class="tabs-reveal__tab" type="button" role="tab" id="tabs-reveal-tab-0" aria-selected="true" aria-controls="tabs-reveal-panel-0" tabindex="0">Dawn</button>
<button class="tabs-reveal__tab" type="button" role="tab" id="tabs-reveal-tab-1" aria-selected="false" aria-controls="tabs-reveal-panel-1" tabindex="-1">Noon</button>
<button class="tabs-reveal__tab" type="button" role="tab" id="tabs-reveal-tab-2" aria-selected="false" aria-controls="tabs-reveal-panel-2" tabindex="-1">Dusk</button>
</div>
<div class="tabs-reveal__stage">
<div class="tabs-reveal__panel" role="tabpanel" id="tabs-reveal-panel-0" aria-labelledby="tabs-reveal-tab-0" data-on="" style="--tabs-reveal-bg:light-dark(#ebedf0, #232529)">
<span class="tabs-reveal__title">6:12 am</span>
<span class="tabs-reveal__body">First light, cool and still. Best for long shadows.</span>
</div>
<div class="tabs-reveal__panel" role="tabpanel" id="tabs-reveal-panel-1" aria-labelledby="tabs-reveal-tab-1" hidden="" style="--tabs-reveal-bg:light-dark(#cbced3, #393c41)">
<span class="tabs-reveal__title">12:40 pm</span>
<span class="tabs-reveal__body">Hard light from overhead. Look for shade.</span>
</div>
<div class="tabs-reveal__panel" role="tabpanel" id="tabs-reveal-panel-2" aria-labelledby="tabs-reveal-tab-2" hidden="" style="--tabs-reveal-bg:light-dark(#dbdde1, #2e3035)">
<span class="tabs-reveal__title">7:58 pm</span>
<span class="tabs-reveal__body">The golden hour, soft and warm.</span>
</div>
</div>
</div>@keyframes tabs-reveal-open { from { clip-path: circle(0% at var(--tabs-reveal-x) 0%); } to { clip-path: circle(160% at var(--tabs-reveal-x) 0%); } }
.tabs-reveal { width: 260px; }
.tabs-reveal__list { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; margin-bottom: 8px; }
.tabs-reveal__tab { padding: 8px 0; border: 0; border-radius: 8px; background: none; color: light-dark(#5f626a, #a7abb2); font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; transition: color 0.2s, background-color 0.2s; }
.tabs-reveal__tab:hover { color: light-dark(#42454c, #e5e6e9); }
.tabs-reveal__tab[aria-selected='true'] { background: light-dark(#f3f4f7, #1a1c1f); color: light-dark(#373a40, #f1f2f3); }
.tabs-reveal__tab:focus-visible { outline: 2px solid light-dark(#5f626a, #a7abb2); outline-offset: 2px; }
.tabs-reveal__stage { display: grid; overflow: hidden; border-radius: 12px; }
.tabs-reveal__panel { grid-area: 1 / 1; padding: 16px; background: var(--tabs-reveal-bg); }
.tabs-reveal__panel[data-prev] { z-index: 0; }
.tabs-reveal__panel[data-on] { z-index: 1; }
.tabs-reveal[data-armed] .tabs-reveal__panel[data-on] { animation: tabs-reveal-open 0.6s cubic-bezier(0.4, 0, 0.2, 1); }
.tabs-reveal__title { display: block; margin-bottom: 4px; color: light-dark(#373a40, #f1f2f3); font-size: 18px; font-weight: 600; letter-spacing: -0.01em; }
.tabs-reveal__body { color: light-dark(#42454c, #e5e6e9); font-size: 12.5px; line-height: 1.5; }
@media (prefers-reduced-motion: reduce) {
.tabs-reveal__panel { animation: none !important; }
}function initTabsReveal(root) {
var list = root.querySelector('[role="tablist"]');
var tabs = Array.prototype.slice.call(list.querySelectorAll('[role="tab"]'));
var panels = root.querySelectorAll('[role="tabpanel"]');
var sel = tabs.findIndex(function (tab) { return tab.getAttribute('aria-selected') === 'true'; });
function select(i) {
if (i === sel) return;
var prev = sel;
sel = i;
tabs.forEach(function (tab, k) {
tab.setAttribute('aria-selected', String(k === i));
tab.tabIndex = k === i ? 0 : -1;
});
// The panel you left stays visible, out of reach, while the new one comes in over it.
panels.forEach(function (panel, k) {
panel.hidden = k !== i && k !== prev;
panel.toggleAttribute('data-on', k === i);
panel.toggleAttribute('data-prev', k === prev);
panel.inert = k === prev;
if (k === prev) panel.setAttribute('aria-hidden', 'true');
else panel.removeAttribute('aria-hidden');
});
root.setAttribute('data-armed', '');
root.style.setProperty('--tabs-reveal-x', ((i + 0.5) / tabs.length) * 100 + '%');
}
function onClick(e) {
var tab = e.target.closest('[role="tab"]');
if (tab) select(tabs.indexOf(tab));
}
function onKeyDown(e) {
var n = tabs.length;
var next = { ArrowRight: (sel + 1) % n, ArrowLeft: (sel + n - 1) % n, Home: 0, End: n - 1 }[e.key];
if (next === undefined) return;
e.preventDefault();
select(next);
tabs[next].focus();
}
list.addEventListener('click', onClick);
list.addEventListener('keydown', onKeyDown);
return function () {
list.removeEventListener('click', onClick);
list.removeEventListener('keydown', onKeyDown);
};
}
document.querySelectorAll('.tabs-reveal').forEach(initTabsReveal);Goal: Create a "Reveal" tab set.
Visual behavior: Times of day as tabs: the new panel opens in a circle spreading from under the tab you picked, over the one you left.
Technique:
- The ARIA tabs pattern: a role="tablist" with an aria-label, buttons with role="tab", aria-selected and aria-controls, and role="tabpanel" panels labelled by their tab. Only the selected tab is in the Tab order (roving tabindex); the arrow keys, Home and End move between tabs and select as they go.
- The new panel animates clip-path: circle() from 0 to full size, centred at the selected tab's position (a custom property).
- The panel you left stays in place, marked data-prev, inert and aria-hidden, so it can animate out under the new one while only the new one is reachable.
Accessibility: Real ARIA tabs: arrow keys, Home and End move between tabs, only the selected tab is in the Tab order, and each panel is labelled by its tab. Decoration is aria-hidden. Under prefers-reduced-motion the panel switches without the circle.
My stack: {{USER_STACK}}
My styling: {{USER_STYLING}}
My constraints: {{USER_CONSTRAINTS}}
My colors: neutral only. Black, white and grays, no hues. Use the color values above as written, or my project's closest neutral tokens.
Return a single self-contained component. No dependencies.Goal: Create a "Reveal" tab set.
Visual behavior: Times of day as tabs: the new panel opens in a circle spreading from under the tab you picked, over the one you left.
Technique:
- The ARIA tabs pattern: a role="tablist" with an aria-label, buttons with role="tab", aria-selected and aria-controls, and role="tabpanel" panels labelled by their tab. Only the selected tab is in the Tab order (roving tabindex); the arrow keys, Home and End move between tabs and select as they go.
- The new panel animates clip-path: circle() from 0 to full size, centred at the selected tab's position (a custom property).
- The panel you left stays in place, marked data-prev, inert and aria-hidden, so it can animate out under the new one while only the new one is reachable.
Accessibility: Real ARIA tabs: arrow keys, Home and End move between tabs, only the selected tab is in the Tab order, and each panel is labelled by its tab. Decoration is aria-hidden. Under prefers-reduced-motion the panel switches without the circle.
My stack: {{USER_STACK}}
My styling: {{USER_STYLING}}
My constraints: {{USER_CONSTRAINTS}}
My colors: use my project's existing color tokens. The color values above are grayscale placeholders. Map each one by its role (surface, text, border, accent, glow) to my theme, and keep their relative lightness so contrast and the effect still read.
Return a single self-contained component. No dependencies.Paste into Claude, ChatGPT or Cursor after filling in {{USER_STACK}}, {{USER_STYLING}} and {{USER_CONSTRAINTS}}. Neutral keeps the greys you see here; Match my project asks the model to map them onto your own colour tokens.
Free to use in any project, commercial included. MIT-0, no attribution required. Licence
About this component
Times of day as tabs: the new panel opens in a circle spreading from under the tab you picked, over the one you left.
- Dependencies
- None
- Difficulty
- Intermediate
- Triggers
- click, state change, keyframe
- Techniques
- clip path, keyframes, css variables
- Reduced motion
- Respected
- Theme
- Light and dark (follows your page's color-scheme)
Real ARIA tabs: arrow keys, Home and End move between tabs, only the selected tab is in the Tab order, and each panel is labelled by its tab. Decoration is aria-hidden. Under prefers-reduced-motion the panel switches without the circle.