Breadcrumbs
A breadcrumb path at the top of a file card. It keeps its first and last levels and folds the rest into a "…" button, which opens the hidden levels as a small menu.
- logo-mark.svg12 KB
- logo-wordmark.svg18 KB
- brand-guide.pdf2.4 MB
3 filesChanged 2 hours ago
Options
Code
import { useEffect, useId, useRef, useState } from "react";
import "./breadcrumbs.css";
/* A breadcrumb path. When there are more than "max" levels, the middle ones
fold into a "…" button that opens them as a small menu.
<Breadcrumbs items={[{ label: "Home", href: "/" }, { label: "Logo files", href: "/files" }]} /> */
export function Breadcrumbs({ items, max = 3 }) {
const id = useId();
const more = useRef(null);
const [open, setOpen] = useState(false);
const fold = items.length > max;
const folded = fold ? items.slice(1, items.length - (max - 1)) : [];
const shown = fold ? items.slice(items.length - (max - 1)) : items.slice(1);
const last = items[items.length - 1];
useEffect(() => {
const away = (event) => {
if (more.current && !more.current.contains(event.target)) setOpen(false);
};
document.addEventListener("pointerdown", away);
return () => document.removeEventListener("pointerdown", away);
}, []);
const keys = (event) => {
const links = Array.from(more.current.querySelectorAll("ul a"));
if (event.key === "Escape") {
setOpen(false);
more.current.querySelector("button").focus();
}
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
event.preventDefault();
setOpen(true);
const at = links.indexOf(document.activeElement);
const step = event.key === "ArrowDown" ? 1 : -1;
links[(at + step + links.length) % links.length].focus();
}
};
const link = (item) => (
<li key={item.label}>
<a href={item.href} aria-current={item === last ? "page" : undefined}>
{item.label}
</a>
</li>
);
return (
<nav className="dh-crumbs" aria-label="Breadcrumb">
<ol>
{link(items[0])}
{fold && (
<li
className="dh-crumbs-more"
ref={more}
onKeyDown={keys}
onBlur={(event) => {
if (!event.currentTarget.contains(event.relatedTarget)) setOpen(false);
}}
>
<button
type="button"
aria-label={"Show " + folded.length + " more levels"}
aria-expanded={open}
aria-controls={id}
onClick={() => setOpen(!open)}
>
…
</button>
<ul id={id}>{folded.map(link)}</ul>
</li>
)}
{shown.map(link)}
</ol>
</nav>
);
}
const file = "M4 1.500h4.500V5a1.500 1.500 0 0 0 1.500 1.500h3.500V13a1.500 1.500 0 0 1-1.500 1.500H4A1.500 1.500 0 0 1 2.500 13V3A1.500 1.500 0 0 1 4 1.500Zm6 .400 3.100 3.100H10V1.900Z";
export function Example() {
const files = [
["logo-mark.svg", "12 KB"],
["logo-wordmark.svg", "18 KB"],
["brand-guide.pdf", "2.4 MB"],
];
return (
<div className="dh-crumbs-card">
<Breadcrumbs
items={[
{ label: "Home", href: "#" },
{ label: "Clients", href: "#" },
{ label: "Logoipsum", href: "#" },
{ label: "Projects", href: "#" },
{ label: "Brand refresh", href: "#" },
{ label: "Logo files", href: "#" },
]}
/>
<ul className="dh-crumbs-files">
{files.map(([name, size]) => (
<li key={name}>
<svg viewBox="0 0 16 16" aria-hidden="true">
<path d={file} />
</svg>
<span>{name}</span>
<em>{size}</em>
</li>
))}
</ul>
<p className="dh-crumbs-foot">
3 files<span>Changed 2 hours ago</span>
</p>
</div>
);
}/* A breadcrumb path at the top of a small file card. It keeps its first and
last levels and folds the rest into a "…" button, which opens them as a menu.
Sizes are in em, on a base a little under the text around it. */
.dh-crumbs-card {
--line: color-mix(in srgb, var(--dh-fg, #171717) 9%, transparent);
--ease: cubic-bezier(0.23, 1, 0.32, 1);
width: 26em;
max-width: 100%;
border-radius: 1em;
background: var(--dh-raised, #fff);
box-shadow:
0 0 0 1px var(--line),
0 1px 2px color-mix(in srgb, var(--dh-fg, #171717) 10%, transparent);
color: var(--dh-fg, #171717);
font-family: inherit;
font-size: 0.8125em;
line-height: 1.54;
text-align: left;
}
.dh-crumbs-card :is(ol, ul, p) {
margin: 0;
padding: 0;
list-style: none;
}
.dh-crumbs {
padding: 0.62em 0.62em 0.62em 0.77em;
border-bottom: 1px solid var(--line);
}
.dh-crumbs ol {
display: flex;
align-items: center;
}
.dh-crumbs ol > li {
position: relative;
display: flex;
align-items: center;
min-width: 0;
}
/* The slash between levels. */
.dh-crumbs ol > li + li::before {
content: "/";
margin: 0 0.15em;
color: color-mix(in srgb, var(--dh-fg, #171717) 22%, transparent);
}
.dh-crumbs :is(a, button) {
border-radius: 0.46em;
color: var(--dh-muted, #5c5c5c);
font: inherit;
text-decoration: none;
outline: none;
transition:
color 150ms var(--ease),
background-color 150ms var(--ease);
}
.dh-crumbs ol > li > a {
overflow: hidden;
max-width: 11em;
padding: 0.15em 0.46em;
text-overflow: ellipsis;
white-space: nowrap;
}
.dh-crumbs a[aria-current="page"] {
color: var(--dh-fg, #171717);
font-weight: 500;
letter-spacing: -0.01em;
}
.dh-crumbs :is(a, button):focus-visible {
box-shadow: 0 0 0 2px var(--dh-faint, #8a8a8a);
}
.dh-crumbs button {
width: 1.85em;
height: 1.54em;
padding: 0;
border: 0;
background: color-mix(in srgb, var(--dh-fg, #171717) 6%, transparent);
line-height: 1;
letter-spacing: 0.05em;
cursor: pointer;
-webkit-tap-highlight-color: transparent;
}
.dh-crumbs button:active {
transform: scale(0.94);
}
.dh-crumbs button[aria-expanded="true"] {
background: color-mix(in srgb, var(--dh-fg, #171717) 12%, transparent);
color: var(--dh-fg, #171717);
}
/* The folded levels, opening from the button. */
.dh-crumbs ul {
position: absolute;
top: calc(100% + 0.46em);
left: 0.9em;
z-index: 10;
display: grid;
gap: 1px;
min-width: 10.8em;
padding: 0.31em;
border-radius: 0.77em;
background: var(--dh-raised, #fff);
box-shadow:
0 0 0 1px var(--line),
0 1px 2px color-mix(in srgb, var(--dh-fg, #171717) 10%, transparent),
0 1.08em 2.15em -1.08em color-mix(in srgb, var(--dh-fg, #171717) 28%, transparent);
opacity: 0;
visibility: hidden;
transform: scale(0.97);
transform-origin: 0 0;
transition:
opacity 120ms var(--ease),
transform 120ms var(--ease),
visibility 0s 120ms;
}
.dh-crumbs button[aria-expanded="true"] + ul {
opacity: 1;
visibility: visible;
transform: none;
transition-duration: 150ms, 150ms, 0s;
transition-delay: 0s;
}
.dh-crumbs ul a {
display: flex;
align-items: center;
height: 2.15em;
padding: 0 0.62em;
color: var(--dh-fg, #171717);
white-space: nowrap;
}
.dh-crumbs ul a:focus-visible {
background: color-mix(in srgb, var(--dh-fg, #171717) 6%, transparent);
box-shadow: none;
}
/* The folder's files, to give the path somewhere to lead. */
.dh-crumbs-files {
padding: 0.31em !important;
}
.dh-crumbs-files li {
display: flex;
align-items: center;
gap: 0.62em;
height: 2.46em;
padding: 0 0.62em 0 0.46em;
border-radius: 0.54em;
}
.dh-crumbs-files svg {
flex: none;
width: 1.08em;
height: 1.08em;
fill: var(--dh-faint, #8a8a8a);
}
.dh-crumbs-files span {
flex: 1;
overflow: hidden;
min-width: 0;
text-overflow: ellipsis;
white-space: nowrap;
}
.dh-crumbs-files em,
.dh-crumbs-foot {
color: var(--dh-faint, #8a8a8a);
font-size: 0.846em;
font-style: normal;
}
.dh-crumbs-files em {
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.dh-crumbs-foot {
display: flex;
justify-content: space-between;
padding: 0.73em 1.1em !important;
border-top: 1px solid var(--line);
border-radius: 0 0 1.18em 1.18em;
background: color-mix(in srgb, var(--dh-fg, #171717) 3%, transparent);
color: var(--dh-muted, #5c5c5c);
}
.dh-crumbs-foot span {
color: var(--dh-faint, #8a8a8a);
}
@media (hover: hover) and (pointer: fine) {
.dh-crumbs ol > li > a:hover,
.dh-crumbs button:hover {
color: var(--dh-fg, #171717);
}
.dh-crumbs ul a:hover {
background: color-mix(in srgb, var(--dh-fg, #171717) 6%, transparent);
}
}
@media (prefers-reduced-motion: reduce) {
.dh-crumbs ul,
.dh-crumbs button:active {
transform: none;
}
}<div class="dh-crumbs-card">
<nav class="dh-crumbs" aria-label="Breadcrumb">
<ol>
<li><a href="#">Home</a></li>
<li class="dh-crumbs-more">
<button type="button" aria-label="Show 3 more levels" aria-expanded="false" aria-controls="dh-crumbs-menu">…</button>
<ul id="dh-crumbs-menu">
<li><a href="#">Clients</a></li>
<li><a href="#">Logoipsum</a></li>
<li><a href="#">Projects</a></li>
</ul>
</li>
<li><a href="#">Brand refresh</a></li>
<li><a href="#" aria-current="page">Logo files</a></li>
</ol>
</nav>
<ul class="dh-crumbs-files">
<li><svg viewBox="0 0 16 16" aria-hidden="true"><path d="M4 1.500h4.500V5a1.500 1.500 0 0 0 1.500 1.500h3.500V13a1.500 1.500 0 0 1-1.500 1.500H4A1.500 1.500 0 0 1 2.500 13V3A1.500 1.500 0 0 1 4 1.500Zm6 .400 3.100 3.100H10V1.900Z" /></svg><span>logo-mark.svg</span><em>12 KB</em></li>
<li><svg viewBox="0 0 16 16" aria-hidden="true"><path d="M4 1.500h4.500V5a1.500 1.500 0 0 0 1.500 1.500h3.500V13a1.500 1.500 0 0 1-1.500 1.500H4A1.500 1.500 0 0 1 2.500 13V3A1.500 1.500 0 0 1 4 1.500Zm6 .400 3.100 3.100H10V1.900Z" /></svg><span>logo-wordmark.svg</span><em>18 KB</em></li>
<li><svg viewBox="0 0 16 16" aria-hidden="true"><path d="M4 1.500h4.500V5a1.500 1.500 0 0 0 1.500 1.500h3.500V13a1.500 1.500 0 0 1-1.500 1.500H4A1.500 1.500 0 0 1 2.500 13V3A1.500 1.500 0 0 1 4 1.500Zm6 .400 3.100 3.100H10V1.900Z" /></svg><span>brand-guide.pdf</span><em>2.4 MB</em></li>
</ul>
<p class="dh-crumbs-foot">3 files<span>Changed 2 hours ago</span></p>
</div>/* A breadcrumb path at the top of a small file card. It keeps its first and
last levels and folds the rest into a "…" button, which opens them as a menu.
Sizes are in em, on a base a little under the text around it. */
.dh-crumbs-card {
--line: color-mix(in srgb, var(--dh-fg, #171717) 9%, transparent);
--ease: cubic-bezier(0.23, 1, 0.32, 1);
width: 26em;
max-width: 100%;
border-radius: 1em;
background: var(--dh-raised, #fff);
box-shadow:
0 0 0 1px var(--line),
0 1px 2px color-mix(in srgb, var(--dh-fg, #171717) 10%, transparent);
color: var(--dh-fg, #171717);
font-family: inherit;
font-size: 0.8125em;
line-height: 1.54;
text-align: left;
}
.dh-crumbs-card :is(ol, ul, p) {
margin: 0;
padding: 0;
list-style: none;
}
.dh-crumbs {
padding: 0.62em 0.62em 0.62em 0.77em;
border-bottom: 1px solid var(--line);
}
.dh-crumbs ol {
display: flex;
align-items: center;
}
.dh-crumbs ol > li {
position: relative;
display: flex;
align-items: center;
min-width: 0;
}
/* The slash between levels. */
.dh-crumbs ol > li + li::before {
content: "/";
margin: 0 0.15em;
color: color-mix(in srgb, var(--dh-fg, #171717) 22%, transparent);
}
.dh-crumbs :is(a, button) {
border-radius: 0.46em;
color: var(--dh-muted, #5c5c5c);
font: inherit;
text-decoration: none;
outline: none;
transition:
color 150ms var(--ease),
background-color 150ms var(--ease);
}
.dh-crumbs ol > li > a {
overflow: hidden;
max-width: 11em;
padding: 0.15em 0.46em;
text-overflow: ellipsis;
white-space: nowrap;
}
.dh-crumbs a[aria-current="page"] {
color: var(--dh-fg, #171717);
font-weight: 500;
letter-spacing: -0.01em;
}
.dh-crumbs :is(a, button):focus-visible {
box-shadow: 0 0 0 2px var(--dh-faint, #8a8a8a);
}
.dh-crumbs button {
width: 1.85em;
height: 1.54em;
padding: 0;
border: 0;
background: color-mix(in srgb, var(--dh-fg, #171717) 6%, transparent);
line-height: 1;
letter-spacing: 0.05em;
cursor: pointer;
-webkit-tap-highlight-color: transparent;
}
.dh-crumbs button:active {
transform: scale(0.94);
}
.dh-crumbs button[aria-expanded="true"] {
background: color-mix(in srgb, var(--dh-fg, #171717) 12%, transparent);
color: var(--dh-fg, #171717);
}
/* The folded levels, opening from the button. */
.dh-crumbs ul {
position: absolute;
top: calc(100% + 0.46em);
left: 0.9em;
z-index: 10;
display: grid;
gap: 1px;
min-width: 10.8em;
padding: 0.31em;
border-radius: 0.77em;
background: var(--dh-raised, #fff);
box-shadow:
0 0 0 1px var(--line),
0 1px 2px color-mix(in srgb, var(--dh-fg, #171717) 10%, transparent),
0 1.08em 2.15em -1.08em color-mix(in srgb, var(--dh-fg, #171717) 28%, transparent);
opacity: 0;
visibility: hidden;
transform: scale(0.97);
transform-origin: 0 0;
transition:
opacity 120ms var(--ease),
transform 120ms var(--ease),
visibility 0s 120ms;
}
.dh-crumbs button[aria-expanded="true"] + ul {
opacity: 1;
visibility: visible;
transform: none;
transition-duration: 150ms, 150ms, 0s;
transition-delay: 0s;
}
.dh-crumbs ul a {
display: flex;
align-items: center;
height: 2.15em;
padding: 0 0.62em;
color: var(--dh-fg, #171717);
white-space: nowrap;
}
.dh-crumbs ul a:focus-visible {
background: color-mix(in srgb, var(--dh-fg, #171717) 6%, transparent);
box-shadow: none;
}
/* The folder's files, to give the path somewhere to lead. */
.dh-crumbs-files {
padding: 0.31em !important;
}
.dh-crumbs-files li {
display: flex;
align-items: center;
gap: 0.62em;
height: 2.46em;
padding: 0 0.62em 0 0.46em;
border-radius: 0.54em;
}
.dh-crumbs-files svg {
flex: none;
width: 1.08em;
height: 1.08em;
fill: var(--dh-faint, #8a8a8a);
}
.dh-crumbs-files span {
flex: 1;
overflow: hidden;
min-width: 0;
text-overflow: ellipsis;
white-space: nowrap;
}
.dh-crumbs-files em,
.dh-crumbs-foot {
color: var(--dh-faint, #8a8a8a);
font-size: 0.846em;
font-style: normal;
}
.dh-crumbs-files em {
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.dh-crumbs-foot {
display: flex;
justify-content: space-between;
padding: 0.73em 1.1em !important;
border-top: 1px solid var(--line);
border-radius: 0 0 1.18em 1.18em;
background: color-mix(in srgb, var(--dh-fg, #171717) 3%, transparent);
color: var(--dh-muted, #5c5c5c);
}
.dh-crumbs-foot span {
color: var(--dh-faint, #8a8a8a);
}
@media (hover: hover) and (pointer: fine) {
.dh-crumbs ol > li > a:hover,
.dh-crumbs button:hover {
color: var(--dh-fg, #171717);
}
.dh-crumbs ul a:hover {
background: color-mix(in srgb, var(--dh-fg, #171717) 6%, transparent);
}
}
@media (prefers-reduced-motion: reduce) {
.dh-crumbs ul,
.dh-crumbs button:active {
transform: none;
}
}/* The "…" button opens the folded levels. Escape or a click anywhere else
closes them, and the arrow keys move through them. */
document.querySelectorAll(".dh-crumbs-more").forEach((more) => {
const button = more.querySelector("button");
const links = Array.from(more.querySelectorAll("ul a"));
const set = (open) => button.setAttribute("aria-expanded", String(open));
button.addEventListener("click", () => set(button.getAttribute("aria-expanded") !== "true"));
more.addEventListener("keydown", (event) => {
if (event.key === "Escape") {
set(false);
button.focus();
}
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
event.preventDefault();
set(true);
const at = links.indexOf(document.activeElement);
const step = event.key === "ArrowDown" ? 1 : -1;
links[(at + step + links.length) % links.length].focus();
}
});
document.addEventListener("pointerdown", (event) => {
if (!more.contains(event.target)) set(false);
});
more.addEventListener("focusout", (event) => {
if (!more.contains(event.relatedTarget)) set(false);
});
});Breadcrumbs is not in the Figma file yet.
Use the React or HTML code for now.