Folder
import { useId, useRef, useState } from 'react';
const TABS = [
{ label: 'Docs', files: ['Brief.pdf', 'Contract.docx', 'Notes.md'] },
{ label: 'Images', files: ['Hero.png', 'Logo.svg', 'Team.jpg'] },
{ label: 'Archive', files: ['2024.zip', 'Old site.zip'] },
];
const css = `
@keyframes tabs-folder-in { from { opacity: 0; transform: translateY(8px); } }
.tabs-folder { width: 260px; }
.tabs-folder__list { display: flex; gap: 2px; padding-left: 8px; }
.tabs-folder__tab {
position: relative;
width: 76px;
height: 30px;
border: 0;
background: light-dark(#f3f4f7, #1a1c1f);
color: light-dark(#5f626a, #a7abb2);
font: inherit;
font-size: 12px;
font-weight: 600;
cursor: pointer;
clip-path: polygon(10% 0, 90% 0, 100% 100%, 0 100%);
transform: translateY(4px);
transition: transform 0.35s cubic-bezier(0.3, 1.6, 0.5, 1), background-color 0.25s, color 0.25s;
}
.tabs-folder__tab:hover { color: light-dark(#42454c, #e5e6e9); transform: translateY(2px); }
.tabs-folder__tab[aria-selected='true'] { z-index: 1; background: light-dark(#ebedf0, #232529); color: light-dark(#373a40, #f1f2f3); transform: translateY(1px); }
.tabs-folder__tab:focus-visible { outline: none; color: light-dark(#373a40, #f1f2f3); text-decoration: underline; text-underline-offset: 3px; }
.tabs-folder__body { position: relative; height: 104px; padding: 12px 14px; border-radius: 4px 12px 12px 12px; background: light-dark(#ebedf0, #232529); box-shadow: 0 12px 24px -14px light-dark(rgba(0, 0, 0, 0.21), rgba(0, 0, 0, 0.7)); }
.tabs-folder[data-armed] .tabs-folder__panel { animation: tabs-folder-in 0.35s cubic-bezier(0.3, 1.3, 0.5, 1); }
.tabs-folder__file { display: flex; align-items: center; gap: 8px; padding: 4px 0; color: light-dark(#42454c, #e5e6e9); font-size: 12.5px; }
.tabs-folder__file::before { content: ''; width: 10px; height: 12px; border-radius: 2px; background: light-dark(#6d7179, #7d8087); }
@media (prefers-reduced-motion: reduce) {
.tabs-folder__tab { transition: none; }
.tabs-folder__panel { animation: none !important; }
}
`;
export function FolderTabs() {
const id = useId();
const [sel, setSel] = useState(0);
const [armed, setArmed] = useState(false);
const tabs = useRef<(HTMLButtonElement | null)[]>([]);
const select = (i: number) => {
setArmed(true);
setSel(i);
};
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-folder" data-armed={armed ? '' : undefined}>
<div className="tabs-folder__list" role="tablist" aria-label="Files" onKeyDown={onKeyDown}>
{TABS.map((t, i) => (
<button
key={t.label}
ref={(el) => {
tabs.current[i] = el;
}}
className="tabs-folder__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-folder__body">
{TABS.map((t, i) => (
<div key={t.label} className="tabs-folder__panel" role="tabpanel" id={`${id}-panel-${i}`} aria-labelledby={`${id}-tab-${i}`} hidden={sel !== i}>
{t.files.map((f) => (
<div key={f} className="tabs-folder__file">
{f}
</div>
))}
</div>
))}
</div>
</div>
</>
);
}Markup where the component goes, CSS in your stylesheet, script before </body>. In Vue, Svelte or Angular, call initTabsFolder(el) on the mounted element instead.
<div class="tabs-folder">
<div class="tabs-folder__list" role="tablist" aria-label="Files">
<button class="tabs-folder__tab" type="button" role="tab" id="tabs-folder-tab-0" aria-selected="true" aria-controls="tabs-folder-panel-0" tabindex="0">Docs</button>
<button class="tabs-folder__tab" type="button" role="tab" id="tabs-folder-tab-1" aria-selected="false" aria-controls="tabs-folder-panel-1" tabindex="-1">Images</button>
<button class="tabs-folder__tab" type="button" role="tab" id="tabs-folder-tab-2" aria-selected="false" aria-controls="tabs-folder-panel-2" tabindex="-1">Archive</button>
</div>
<div class="tabs-folder__body">
<div class="tabs-folder__panel" role="tabpanel" id="tabs-folder-panel-0" aria-labelledby="tabs-folder-tab-0">
<div class="tabs-folder__file">Brief.pdf</div>
<div class="tabs-folder__file">Contract.docx</div>
<div class="tabs-folder__file">Notes.md</div>
</div>
<div class="tabs-folder__panel" role="tabpanel" id="tabs-folder-panel-1" aria-labelledby="tabs-folder-tab-1" hidden="">
<div class="tabs-folder__file">Hero.png</div>
<div class="tabs-folder__file">Logo.svg</div>
<div class="tabs-folder__file">Team.jpg</div>
</div>
<div class="tabs-folder__panel" role="tabpanel" id="tabs-folder-panel-2" aria-labelledby="tabs-folder-tab-2" hidden="">
<div class="tabs-folder__file">2024.zip</div>
<div class="tabs-folder__file">Old site.zip</div>
</div>
</div>
</div>@keyframes tabs-folder-in { from { opacity: 0; transform: translateY(8px); } }
.tabs-folder { width: 260px; }
.tabs-folder__list { display: flex; gap: 2px; padding-left: 8px; }
.tabs-folder__tab {
position: relative;
width: 76px;
height: 30px;
border: 0;
background: light-dark(#f3f4f7, #1a1c1f);
color: light-dark(#5f626a, #a7abb2);
font: inherit;
font-size: 12px;
font-weight: 600;
cursor: pointer;
clip-path: polygon(10% 0, 90% 0, 100% 100%, 0 100%);
transform: translateY(4px);
transition: transform 0.35s cubic-bezier(0.3, 1.6, 0.5, 1), background-color 0.25s, color 0.25s;
}
.tabs-folder__tab:hover { color: light-dark(#42454c, #e5e6e9); transform: translateY(2px); }
.tabs-folder__tab[aria-selected='true'] { z-index: 1; background: light-dark(#ebedf0, #232529); color: light-dark(#373a40, #f1f2f3); transform: translateY(1px); }
.tabs-folder__tab:focus-visible { outline: none; color: light-dark(#373a40, #f1f2f3); text-decoration: underline; text-underline-offset: 3px; }
.tabs-folder__body { position: relative; height: 104px; padding: 12px 14px; border-radius: 4px 12px 12px 12px; background: light-dark(#ebedf0, #232529); box-shadow: 0 12px 24px -14px light-dark(rgba(0, 0, 0, 0.21), rgba(0, 0, 0, 0.7)); }
.tabs-folder[data-armed] .tabs-folder__panel { animation: tabs-folder-in 0.35s cubic-bezier(0.3, 1.3, 0.5, 1); }
.tabs-folder__file { display: flex; align-items: center; gap: 8px; padding: 4px 0; color: light-dark(#42454c, #e5e6e9); font-size: 12.5px; }
.tabs-folder__file::before { content: ''; width: 10px; height: 12px; border-radius: 2px; background: light-dark(#6d7179, #7d8087); }
@media (prefers-reduced-motion: reduce) {
.tabs-folder__tab { transition: none; }
.tabs-folder__panel { animation: none !important; }
}function initTabsFolder(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) {
// Armed on the first change, so nothing animates on load.
root.setAttribute('data-armed', '');
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;
});
panels.forEach(function (panel, k) { panel.hidden = k !== i; });
}
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-folder').forEach(initTabsFolder);Goal: Create a "Folder" tab set.
Visual behavior: File folder tabs: the active tab rises and joins the folder body, and the new page of files slides up into it.
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.
- Tabs are clipped into folder-tab shapes; the selected one shifts up and takes the folder's colour, so it reads as one piece with the body. The panel slides in on keyframes.
- A data-armed attribute is set on the first change, so nothing plays on page load.
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 page appears without sliding.
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 "Folder" tab set.
Visual behavior: File folder tabs: the active tab rises and joins the folder body, and the new page of files slides up into it.
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.
- Tabs are clipped into folder-tab shapes; the selected one shifts up and takes the folder's colour, so it reads as one piece with the body. The panel slides in on keyframes.
- A data-armed attribute is set on the first change, so nothing plays on page load.
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 page appears without sliding.
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
File folder tabs: the active tab rises and joins the folder body, and the new page of files slides up into it.
- Dependencies
- None
- Difficulty
- Beginner
- Triggers
- click, state change
- Techniques
- css transition, keyframes, clip path
- 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 page appears without sliding.