सुलभता पैटर्न · नेविगेशन
साइडबार नेविगेशन
समूह aria-expanded वाले असली बटनों के नीचे खुलते हैं, और खुला पेज aria-current="page" से और सिर्फ़ रंग से ज़्यादा तरीक़ों से चिह्नित है। पट्टी में सिमटने पर शब्द हटाए नहीं जाते, सिर्फ़ नज़र से छिपाए जाते हैं, इसलिए हर आइकन अब भी नाम वाला लिंक है, और वही शब्द होवर या फ़ोकस पर टूलटिप बनकर दिखते हैं।
- डब्ल्यूसीएजी मानदंड
- 6
- कीबोर्ड नियम
- 5
- जाँच का तरीक़ा
- axe, कीबोर्ड और इंस्पेक्टर
लाइव डेमो
आज़माएँ
इसे माउस, कीबोर्ड या स्क्रीन रीडर से इस्तेमाल करें। साथ का इंस्पेक्टर दिखाता है कि आपके इस्तेमाल के दौरान ब्राउज़र सहायक तकनीक को क्या बताता है: फ़ोकस, स्थिति में बदलाव और घोषणाएँ।
जावास्क्रिप्ट के बिना डेमो उतना ही काम करता है जितना उसका एचटीएमएल; इंस्पेक्टर के लिए जावास्क्रिप्ट चाहिए।
कीबोर्ड
जिन कुंजियों पर यह काम करता है
हर क्रिया पॉइंटर के बिना काम करती है।
| कुंजी | यह क्या करती है |
|---|---|
| TabयाShiftTab | लिंक और समूह बटनों पर बारी-बारी से ले जाता है; बंद समूह के लिंक छूट जाते हैं। |
| EnterयाSpace | समूह बटन पर, उसके लिंक खोलता या बंद करता है। पट्टी में, यह साइडबार को चौड़ा करके समूह खोलता है। |
| Enter | लिंक पर, वह पेज खोलता है (डेमो में, उसे मौजूदा पेज के रूप में चिह्नित करता है)। |
| EnterयाSpace | साइडबार समेटें पर, पूरे साइडबार और आइकन पट्टी के बीच बदलता है; फ़ोकस बटन पर ही रहता है। |
| Escape | पट्टी में, दिख रहे टूलटिप को फ़ोकस हटाए बिना छिपाता है। |
स्क्रीन रीडर
यह क्या घोषित करता है
मार्कअप की भूमिकाओं, नामों और स्थितियों से लिखा गया।
| कब | अपेक्षित घोषणा |
|---|---|
| Tab मौजूदा पेज तक पहुँचता है | वर्कस्पेस, नेविगेशन। इनवॉइस, मौजूदा पेज, लिंक |
| Tab किसी बंद समूह तक पहुँचता है | प्रोजेक्ट, बटन, संक्षिप्त |
| साइडबार समेटें दबाया जाता है | साइडबार सिमट गया |
| Tab पट्टी के किसी लिंक तक पहुँचता है | ग्राहक, लिंक |
| साइडबार फैलाएँ दबाया जाता है | साइडबार फैल गया |
ये अपेक्षित घोषणाएँ हैं, रिकॉर्डिंग नहीं। स्क्रीन रीडर और ब्राउज़र के हिसाब से शब्द और क्रम बदलते हैं।
कोड
कोड कॉपी करें
वही फ़ाइलें जिन पर यह डेमो चलता है। स्टाइल एक प्रीफ़िक्स के साथ परोसी जाती हैं जो इस साइट की अपनी स्टाइल को डेमो से दूर रखता है; आप जो कॉपी करते हैं वह मूल है।
<div class="ap-sidebar" data-ap-sidebar>
<div class="ap-sidebar__frame">
<div class="ap-sidebar__panel">
<div class="ap-sidebar__brand">
<span class="ap-sidebar__logo" aria-hidden="true"><svg viewBox="0 0 24 24" focusable="false"><path d="m4 18 5.5-10 3.5 6 2-3.5L20 18Z"/></svg></span>
<span class="ap-sidebar__text" translate="no">Kiran Studio</span>
</div>
<nav class="ap-sidebar__nav" aria-label="Workspace">
<ul class="ap-sidebar__list">
<li><a class="ap-sidebar__link" href="/home/"><svg class="ap-sidebar__icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M4 10.5 12 4l8 6.5V19a1 1 0 0 1-1 1h-4.5v-5.5h-5V20H5a1 1 0 0 1-1-1Z"/></svg><span class="ap-sidebar__text">Home</span></a></li>
<li><a class="ap-sidebar__link" href="/inbox/"><svg class="ap-sidebar__icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M3.5 13H8l1.5 2.5h5L16 13h4.5"/><path d="M6 5h12l2.5 8v5a1 1 0 0 1-1 1h-15a1 1 0 0 1-1-1v-5Z"/></svg><span class="ap-sidebar__text">Inbox</span></a></li>
<li class="ap-sidebar__group">
<button type="button" class="ap-sidebar__toggle" aria-expanded="true" aria-controls="sb-billing"><svg class="ap-sidebar__icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M6 3.5h12v17l-3-2-3 2-3-2-3 2Z"/><path d="M9.5 8.5h5M9.5 12.5h5"/></svg><span class="ap-sidebar__text">Billing</span><svg class="ap-sidebar__chevron" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="m6 9 6 6 6-6"/></svg></button>
<ul class="ap-sidebar__sub" id="sb-billing">
<li><a class="ap-sidebar__sublink" href="/billing/invoices/" aria-current="page">Invoices</a></li>
<li><a class="ap-sidebar__sublink" href="/billing/payments/">Payments</a></li>
<li><a class="ap-sidebar__sublink" href="/billing/tax/">Tax reports</a></li>
</ul>
</li>
<li class="ap-sidebar__group">
<button type="button" class="ap-sidebar__toggle" aria-expanded="false" aria-controls="sb-projects"><svg class="ap-sidebar__icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M3.5 7.5a2 2 0 0 1 2-2h3.8l2 2h7.2a2 2 0 0 1 2 2V17a2 2 0 0 1-2 2h-13a2 2 0 0 1-2-2Z"/></svg><span class="ap-sidebar__text">Projects</span><svg class="ap-sidebar__chevron" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="m6 9 6 6 6-6"/></svg></button>
<ul class="ap-sidebar__sub" id="sb-projects" hidden>
<li><a class="ap-sidebar__sublink" href="/projects/website/">Website redesign</a></li>
<li><a class="ap-sidebar__sublink" href="/projects/app/">Mobile app</a></li>
<li><a class="ap-sidebar__sublink" href="/projects/brand/">Brand refresh</a></li>
</ul>
</li>
<li><a class="ap-sidebar__link" href="/customers/"><svg class="ap-sidebar__icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><circle cx="9.5" cy="8.5" r="3.5"/><path d="M3 19.5a6.5 6.5 0 0 1 13 0"/><path d="M16 5.2a3.5 3.5 0 0 1 0 6.6M18.5 14.4a6.5 6.5 0 0 1 2.5 5.1"/></svg><span class="ap-sidebar__text">Customers</span></a></li>
<li><a class="ap-sidebar__link" href="/settings/"><svg class="ap-sidebar__icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M4 7h8.5M16.5 7H20M4 17h2.5M10.5 17H20"/><circle cx="14.5" cy="7" r="2"/><circle cx="8.5" cy="17" r="2"/></svg><span class="ap-sidebar__text">Settings</span></a></li>
</ul>
</nav>
<button type="button" class="ap-sidebar__collapse">
<svg class="ap-sidebar__icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><rect x="3.5" y="4.5" width="17" height="15" rx="2"/><path d="M9 4.5v15"/><path class="ap-sidebar__flip" d="m15.5 10-2 2 2 2"/></svg>
<span class="ap-sidebar__text">Collapse sidebar</span>
</button>
</div>
<div class="ap-sidebar__main">
<p class="ap-sidebar__crumb" translate="no">Kiran Studio</p>
<h3 class="ap-sidebar__page">Invoices</h3>
<p class="ap-sidebar__hint">Pick a page in the sidebar, then collapse it to the icon rail and hover or Tab through the icons.</p>
<div class="ap-sidebar__mock" aria-hidden="true"><span></span><span></span><span></span></div>
</div>
</div>
<p class="ap-sidebar__status" role="status"></p>
</div>
/* Sidebar navigation. Uses the --ap-* design tokens. */
.ap-sidebar {
container-type: inline-size;
width: min(100%, 680px);
margin-inline: auto;
}
.ap-sidebar__frame {
display: grid;
grid-template-columns: auto minmax(0, 1fr);
min-height: 520px;
border: 1px solid var(--ap-border);
border-radius: var(--ap-radius-lg);
background: var(--ap-surface);
box-shadow: var(--ap-shadow-md);
color: var(--ap-text);
}
/* ── The sidebar ── */
.ap-sidebar__panel {
display: flex;
flex-direction: column;
gap: 10px;
width: 236px;
padding: 14px 12px 12px;
border-inline-end: 1px solid var(--ap-border);
border-radius: var(--ap-radius-lg) 0 0 var(--ap-radius-lg);
background: var(--ap-surface-2);
transition: width 200ms var(--ap-ease);
}
.ap-sidebar__brand {
display: flex;
align-items: center;
gap: 10px;
min-height: 40px;
padding: 0 6px 6px;
font-weight: 700;
}
.ap-sidebar__logo {
display: grid;
place-items: center;
width: 32px;
height: 32px;
flex-shrink: 0;
border-radius: var(--ap-radius-sm);
background: var(--ap-accent);
color: var(--ap-on-accent);
}
.ap-sidebar__logo svg {
width: 18px;
height: 18px;
fill: currentColor;
}
.ap-sidebar__nav {
flex: 1;
padding-bottom: 10px;
border-bottom: 1px solid var(--ap-border);
}
.ap-sidebar__list,
.ap-sidebar__sub {
display: grid;
gap: 2px;
margin: 0;
padding: 0;
list-style: none;
}
.ap-sidebar__link,
.ap-sidebar__toggle,
.ap-sidebar__collapse {
position: relative;
display: flex;
align-items: center;
gap: 12px;
width: 100%;
min-height: var(--ap-target);
padding: 0 10px 0 12px;
border: 0;
border-radius: var(--ap-radius-sm);
background: transparent;
color: var(--ap-text-2);
font: inherit;
font-size: .9375rem;
font-weight: 500;
text-align: start;
text-decoration: none;
cursor: pointer;
transition: background-color var(--ap-duration) var(--ap-ease), color var(--ap-duration) var(--ap-ease);
}
.ap-sidebar__link:hover,
.ap-sidebar__toggle:hover,
.ap-sidebar__collapse:hover,
.ap-sidebar__sublink:hover {
background: var(--ap-surface-3);
color: var(--ap-text);
}
.ap-sidebar__link:focus-visible,
.ap-sidebar__toggle:focus-visible,
.ap-sidebar__collapse:focus-visible,
.ap-sidebar__sublink:focus-visible {
outline: 2px solid var(--ap-focus);
outline-offset: -2px;
}
.ap-sidebar__icon {
width: 20px;
height: 20px;
flex-shrink: 0;
fill: none;
stroke: currentColor;
stroke-width: 1.75;
stroke-linecap: round;
stroke-linejoin: round;
}
.ap-sidebar__flip {
transform-box: fill-box;
transform-origin: center;
transition: transform 200ms var(--ap-ease);
}
.ap-sidebar__text {
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.ap-sidebar__chevron {
width: 16px;
height: 16px;
flex-shrink: 0;
margin-inline-start: auto;
fill: none;
stroke: currentColor;
stroke-width: 2;
stroke-linecap: round;
stroke-linejoin: round;
transition: transform var(--ap-duration) var(--ap-ease);
}
.ap-sidebar__toggle[aria-expanded="true"] .ap-sidebar__chevron {
transform: rotate(180deg);
}
/* Nested links hang off a guide line. */
.ap-sidebar__sub {
position: relative;
margin: 2px 0 6px;
padding-inline-start: 22px;
}
.ap-sidebar__sub::before {
content: "";
position: absolute;
inset-block: 4px;
inset-inline-start: 21px;
border-inline-start: 1px solid var(--ap-border-strong);
opacity: .5;
}
.ap-sidebar__sublink {
position: relative;
display: flex;
align-items: center;
min-height: 38px;
padding: 0 10px 0 18px;
border-radius: var(--ap-radius-sm);
color: var(--ap-text-2);
font-size: .9rem;
text-decoration: none;
transition: background-color var(--ap-duration) var(--ap-ease), color var(--ap-duration) var(--ap-ease);
}
/* The open page: tinted fill, a bar and weight, not color alone. */
.ap-sidebar__link[aria-current="page"],
.ap-sidebar__sublink[aria-current="page"] {
background: var(--ap-accent-soft);
color: var(--ap-accent-soft-text);
font-weight: 650;
}
.ap-sidebar__link[aria-current="page"]::before,
.ap-sidebar__sublink[aria-current="page"]::before {
content: "";
position: absolute;
inset-block: 8px;
inset-inline-start: 0;
width: 3px;
border-radius: var(--ap-radius-full);
background: var(--ap-accent);
}
/* Its group is bold too, so a closed group still shows where you are. */
.ap-sidebar__group:has([aria-current="page"]) > .ap-sidebar__toggle {
color: var(--ap-text);
font-weight: 650;
}
.ap-sidebar__collapse {
color: var(--ap-text-3);
}
/* ── The page beside it ── */
.ap-sidebar__main {
min-width: 0;
padding: 26px 28px;
}
.ap-sidebar__crumb {
margin: 0 0 4px;
color: var(--ap-text-3);
font-size: .8125rem;
font-weight: 600;
}
.ap-sidebar__page {
margin: 0 0 8px;
font-size: 1.375rem;
font-weight: 700;
line-height: 1.25;
letter-spacing: -.01em;
}
.ap-sidebar__hint {
margin: 0 0 22px;
max-width: 36ch;
color: var(--ap-text-2);
line-height: 1.55;
}
.ap-sidebar__mock {
display: grid;
gap: 10px;
}
.ap-sidebar__mock span {
display: block;
height: 44px;
border: 1px solid var(--ap-border);
border-radius: var(--ap-radius-sm);
background: linear-gradient(90deg, var(--ap-surface-2) 0 30%, transparent 30% 36%, var(--ap-surface-2) 36% 58%, transparent 58%);
background-size: calc(100% - 24px) 10px;
background-position: 12px center;
background-repeat: no-repeat;
}
/* Text kept for screen readers but not shown. */
.ap-sidebar__status {
position: absolute;
width: 1px;
height: 1px;
margin: -1px;
overflow: hidden;
clip-path: inset(50%);
white-space: nowrap;
}
/* ── The icon rail ── */
.ap-sidebar--rail .ap-sidebar__panel {
width: 68px;
}
.ap-sidebar--rail .ap-sidebar__link,
.ap-sidebar--rail .ap-sidebar__toggle,
.ap-sidebar--rail .ap-sidebar__collapse {
justify-content: center;
padding: 0;
}
.ap-sidebar--rail .ap-sidebar__brand {
justify-content: center;
padding-inline: 0;
}
.ap-sidebar--rail .ap-sidebar__chevron {
display: none;
}
.ap-sidebar--rail .ap-sidebar__flip {
transform: scaleX(-1);
}
/* A closed group that holds the open page keeps a bar in the rail. */
.ap-sidebar--rail .ap-sidebar__group:has([aria-current="page"]) > .ap-sidebar__toggle {
background: var(--ap-accent-soft);
color: var(--ap-accent-soft-text);
}
.ap-sidebar--rail .ap-sidebar__group:has([aria-current="page"]) > .ap-sidebar__toggle::before {
content: "";
position: absolute;
inset-block: 8px;
inset-inline-start: 0;
width: 3px;
border-radius: var(--ap-radius-full);
background: var(--ap-accent);
}
/* The words stay in the page, visually hidden... */
.ap-sidebar--rail .ap-sidebar__text {
position: absolute;
width: 1px;
height: 1px;
overflow: hidden;
clip-path: inset(50%);
white-space: nowrap;
}
/* ...and the same element is the tooltip on hover or keyboard focus. */
.ap-sidebar--rail :is(.ap-sidebar__link, .ap-sidebar__toggle, .ap-sidebar__collapse):is(:hover, :focus-visible):not([data-quiet]) .ap-sidebar__text {
z-index: 3;
inset-inline-start: calc(100% + 10px);
top: 50%;
width: auto;
height: auto;
overflow: visible;
clip-path: none;
padding: 6px 10px;
border-radius: var(--ap-radius-sm);
background: var(--ap-text);
box-shadow: var(--ap-shadow-md);
color: var(--ap-surface);
font-size: .8125rem;
font-weight: 600;
line-height: 1.3;
transform: translateY(-50%);
animation: ap-sidebar-tip 120ms var(--ap-ease);
}
/* A bridge over the gap, so the pointer can move onto the tooltip. */
.ap-sidebar--rail .ap-sidebar__text::before {
content: "";
position: absolute;
inset-block: 0;
inset-inline-end: 100%;
width: 12px;
}
/* ── Narrow: the full sidebar sits above the page ── */
@container (max-width: 520px) {
.ap-sidebar:not(.ap-sidebar--rail) .ap-sidebar__frame {
grid-template-columns: minmax(0, 1fr);
}
.ap-sidebar:not(.ap-sidebar--rail) .ap-sidebar__panel {
width: auto;
border-inline-end: 0;
border-bottom: 1px solid var(--ap-border);
border-radius: var(--ap-radius-lg) var(--ap-radius-lg) 0 0;
}
.ap-sidebar__main {
padding: 20px;
}
}
@keyframes ap-sidebar-tip {
from { opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
.ap-sidebar__panel,
.ap-sidebar__flip,
.ap-sidebar__chevron,
.ap-sidebar__link,
.ap-sidebar__toggle,
.ap-sidebar__collapse,
.ap-sidebar__sublink { transition: none; }
.ap-sidebar--rail .ap-sidebar__text { animation: none; }
}
/**
* Sidebar navigation: an app sidebar of links, with groups that open and
* close under disclosure buttons, and a button that shrinks it to an icon
* rail. In the rail every word stays in the page, visually hidden, and shows
* as a tooltip on hover or keyboard focus.
*
* Markup: [data-ap-sidebar] holding nav > ul of a.ap-sidebar__link and
* groups (button.ap-sidebar__toggle[aria-expanded][aria-controls] + ul), a
* button.ap-sidebar__collapse, an .ap-sidebar__page that names the open
* page, and a role=status element. The rail is the class ap-sidebar--rail.
*/
export function init(root) {
const collapse = root.querySelector(".ap-sidebar__collapse");
const collapseText = collapse.querySelector(".ap-sidebar__text");
const status = root.querySelector("[role=status]");
const pageName = root.querySelector(".ap-sidebar__page");
const groups = [...root.querySelectorAll(".ap-sidebar__toggle")];
const links = [...root.querySelectorAll(".ap-sidebar__link, .ap-sidebar__sublink")];
const listOf = (button) => document.getElementById(button.getAttribute("aria-controls"));
const isRail = () => root.classList.contains("ap-sidebar--rail");
let openBefore = null;
function setGroup(button, open) {
button.setAttribute("aria-expanded", String(open));
listOf(button).hidden = !open;
}
// The rail has no room for nested links, so its groups report collapsed
// (aria-expanded must match what is on screen). Their state comes back
// when the sidebar widens again.
function setRail(rail) {
if (rail === isRail()) return;
if (rail) {
openBefore = groups.map((b) => b.getAttribute("aria-expanded") === "true");
for (const b of groups) setGroup(b, false);
} else if (openBefore) {
groups.forEach((b, i) => setGroup(b, openBefore[i]));
}
root.classList.toggle("ap-sidebar--rail", rail);
// The label says what the button will do; no aria-pressed on top of it.
collapseText.textContent = rail ? "Expand sidebar" : "Collapse sidebar";
status.textContent = rail ? "Sidebar collapsed" : "Sidebar expanded";
}
function onClick(event) {
if (event.target.closest(".ap-sidebar__collapse")) {
setRail(!isRail());
return;
}
const group = event.target.closest(".ap-sidebar__toggle");
if (group) {
// In the rail a group cannot open in place: widen the sidebar and open it there.
if (isRail()) {
setRail(false);
setGroup(group, true);
} else {
setGroup(group, group.getAttribute("aria-expanded") !== "true");
}
return;
}
const link = event.target.closest(".ap-sidebar__link, .ap-sidebar__sublink");
if (!link) return;
// The demo stays on this page: the link becomes the current page instead.
event.preventDefault();
for (const l of links) {
if (l === link) l.setAttribute("aria-current", "page");
else l.removeAttribute("aria-current");
}
pageName.textContent = (link.querySelector(".ap-sidebar__text") || link).textContent.trim();
}
/* Tooltips in the rail: Escape hides the one showing without moving focus
(WCAG 1.4.13); it comes back the next time the item is hovered or focused. */
const quiet = (el) => el?.closest(".ap-sidebar__link, .ap-sidebar__toggle, .ap-sidebar__collapse");
function onKeydown(event) {
if (event.key !== "Escape" || !isRail()) return;
const targets = [quiet(document.activeElement), ...[...root.querySelectorAll(":hover")].map(quiet)].filter((el) => el && root.contains(el));
if (!targets.length) return;
for (const el of targets) el.setAttribute("data-quiet", "");
event.preventDefault();
}
function onFocusout(event) {
event.target.removeAttribute?.("data-quiet");
}
function onPointerout(event) {
const el = event.target.closest?.("[data-quiet]");
if (el && !el.contains(event.relatedTarget)) el.removeAttribute("data-quiet");
}
root.addEventListener("click", onClick);
root.addEventListener("keydown", onKeydown);
root.addEventListener("focusout", onFocusout);
root.addEventListener("pointerout", onPointerout);
return () => {
root.removeEventListener("click", onClick);
root.removeEventListener("keydown", onKeydown);
root.removeEventListener("focusout", onFocusout);
root.removeEventListener("pointerout", onPointerout);
};
}
for (const root of document.querySelectorAll("[data-ap-sidebar]")) init(root);
/* Design tokens for the pattern components. Light by default, dark when the
system asks for it; set data-theme="dark" on :root to force dark. */
:root {
--ap-radius-sm: 8px;
--ap-radius: 12px;
--ap-radius-lg: 16px;
--ap-radius-full: 999px;
--ap-font: "Instrument Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
--ap-mono: "JetBrains Mono", ui-monospace, "Cascadia Mono", "SF Mono", Consolas, monospace;
--ap-ease: cubic-bezier(.2, .8, .2, 1);
--ap-duration: 180ms;
--ap-target: 44px;
--ap-bg: #F4F4F5;
--ap-surface: #FFFFFF;
--ap-surface-2: #F4F4F5;
--ap-surface-3: #E4E4E7;
--ap-border: #E4E4E7;
--ap-border-strong: #76767F;
--ap-text: #18181B;
--ap-text-2: #3F3F46;
--ap-text-3: #5E5E66;
--ap-accent: #4F46E5;
--ap-accent-hover: #4338CA;
--ap-on-accent: #FFFFFF;
--ap-accent-text: #4338CA;
--ap-accent-soft: #EEF2FF;
--ap-accent-soft-text: #3730A3;
--ap-focus: #4F46E5;
--ap-danger: #B91C1C;
--ap-danger-soft: #FEF2F2;
--ap-success: #15803D;
--ap-success-soft: #F0FDF4;
--ap-warning: #A15C07;
--ap-warning-soft: #FEFCE8;
--ap-info: #1D4ED8;
--ap-info-soft: #EFF6FF;
--ap-scrim: rgb(9 9 11 / .48);
--ap-shadow-sm: 0 1px 2px rgb(9 9 11 / .06);
--ap-shadow-md: 0 1px 2px rgb(9 9 11 / .05), 0 6px 16px -4px rgb(9 9 11 / .1);
--ap-shadow-lg: 0 2px 6px rgb(9 9 11 / .06), 0 20px 40px -12px rgb(9 9 11 / .22);
--ap-light-bg: #F4F4F5;
--ap-light-surface: #FFFFFF;
--ap-light-surface-2: #F4F4F5;
--ap-light-surface-3: #E4E4E7;
--ap-light-border: #E4E4E7;
--ap-light-border-strong: #76767F;
--ap-light-text: #18181B;
--ap-light-text-2: #3F3F46;
--ap-light-text-3: #5E5E66;
--ap-light-accent: #4F46E5;
--ap-light-accent-hover: #4338CA;
--ap-light-on-accent: #FFFFFF;
--ap-light-accent-text: #4338CA;
--ap-light-accent-soft: #EEF2FF;
--ap-light-accent-soft-text: #3730A3;
--ap-light-focus: #4F46E5;
--ap-light-danger: #B91C1C;
--ap-light-danger-soft: #FEF2F2;
--ap-light-success: #15803D;
--ap-light-success-soft: #F0FDF4;
--ap-light-warning: #A15C07;
--ap-light-warning-soft: #FEFCE8;
--ap-light-info: #1D4ED8;
--ap-light-info-soft: #EFF6FF;
--ap-light-scrim: rgb(9 9 11 / .48);
--ap-light-shadow-sm: 0 1px 2px rgb(9 9 11 / .06);
--ap-light-shadow-md: 0 1px 2px rgb(9 9 11 / .05), 0 6px 16px -4px rgb(9 9 11 / .1);
--ap-light-shadow-lg: 0 2px 6px rgb(9 9 11 / .06), 0 20px 40px -12px rgb(9 9 11 / .22);
--ap-dark-bg: #09090B;
--ap-dark-surface: #18181B;
--ap-dark-surface-2: #27272A;
--ap-dark-surface-3: #3F3F46;
--ap-dark-border: #2E2E33;
--ap-dark-border-strong: #8E8E97;
--ap-dark-text: #FAFAFA;
--ap-dark-text-2: #D4D4D8;
--ap-dark-text-3: #A1A1AA;
--ap-dark-accent: #818CF8;
--ap-dark-accent-hover: #A5B4FC;
--ap-dark-on-accent: #0C0A1F;
--ap-dark-accent-text: #A5B4FC;
--ap-dark-accent-soft: #1E1B4B;
--ap-dark-accent-soft-text: #C7D2FE;
--ap-dark-focus: #A5B4FC;
--ap-dark-danger: #F87171;
--ap-dark-danger-soft: #2A1215;
--ap-dark-success: #4ADE80;
--ap-dark-success-soft: #0F2A1A;
--ap-dark-warning: #FACC15;
--ap-dark-warning-soft: #2A2410;
--ap-dark-info: #60A5FA;
--ap-dark-info-soft: #0F1D33;
--ap-dark-scrim: rgb(0 0 0 / .62);
--ap-dark-shadow-sm: 0 1px 2px rgb(0 0 0 / .4);
--ap-dark-shadow-md: 0 1px 2px rgb(0 0 0 / .4), 0 8px 20px -6px rgb(0 0 0 / .5);
--ap-dark-shadow-lg: 0 2px 8px rgb(0 0 0 / .45), 0 24px 48px -12px rgb(0 0 0 / .7);
}
@media (prefers-color-scheme: dark) {
:root:not([data-theme="light"]) {
--ap-bg: #09090B;
--ap-surface: #18181B;
--ap-surface-2: #27272A;
--ap-surface-3: #3F3F46;
--ap-border: #2E2E33;
--ap-border-strong: #8E8E97;
--ap-text: #FAFAFA;
--ap-text-2: #D4D4D8;
--ap-text-3: #A1A1AA;
--ap-accent: #818CF8;
--ap-accent-hover: #A5B4FC;
--ap-on-accent: #0C0A1F;
--ap-accent-text: #A5B4FC;
--ap-accent-soft: #1E1B4B;
--ap-accent-soft-text: #C7D2FE;
--ap-focus: #A5B4FC;
--ap-danger: #F87171;
--ap-danger-soft: #2A1215;
--ap-success: #4ADE80;
--ap-success-soft: #0F2A1A;
--ap-warning: #FACC15;
--ap-warning-soft: #2A2410;
--ap-info: #60A5FA;
--ap-info-soft: #0F1D33;
--ap-scrim: rgb(0 0 0 / .62);
--ap-shadow-sm: 0 1px 2px rgb(0 0 0 / .4);
--ap-shadow-md: 0 1px 2px rgb(0 0 0 / .4), 0 8px 20px -6px rgb(0 0 0 / .5);
--ap-shadow-lg: 0 2px 8px rgb(0 0 0 / .45), 0 24px 48px -12px rgb(0 0 0 / .7);
}
}
:root[data-theme="dark"] {
--ap-bg: #09090B;
--ap-surface: #18181B;
--ap-surface-2: #27272A;
--ap-surface-3: #3F3F46;
--ap-border: #2E2E33;
--ap-border-strong: #8E8E97;
--ap-text: #FAFAFA;
--ap-text-2: #D4D4D8;
--ap-text-3: #A1A1AA;
--ap-accent: #818CF8;
--ap-accent-hover: #A5B4FC;
--ap-on-accent: #0C0A1F;
--ap-accent-text: #A5B4FC;
--ap-accent-soft: #1E1B4B;
--ap-accent-soft-text: #C7D2FE;
--ap-focus: #A5B4FC;
--ap-danger: #F87171;
--ap-danger-soft: #2A1215;
--ap-success: #4ADE80;
--ap-success-soft: #0F2A1A;
--ap-warning: #FACC15;
--ap-warning-soft: #2A2410;
--ap-info: #60A5FA;
--ap-info-soft: #0F1D33;
--ap-scrim: rgb(0 0 0 / .62);
--ap-shadow-sm: 0 1px 2px rgb(0 0 0 / .4);
--ap-shadow-md: 0 1px 2px rgb(0 0 0 / .4), 0 8px 20px -6px rgb(0 0 0 / .5);
--ap-shadow-lg: 0 2px 8px rgb(0 0 0 / .45), 0 24px 48px -12px rgb(0 0 0 / .7);
}
डब्ल्यूसीएजी 2.2
यह किन मानदंडों को पूरा करता है
वे सफलता मानदंड जिनका यह पैटर्न ध्यान रखता है, और कैसे।
-
1.3.1 जानकारी और संबंध
स्तर A
साइडबार नेस्टेड सूचियों वाला नेविगेशन लैंडमार्क है, और हर समूह के लिंक उसे नियंत्रित करने वाले बटन के ठीक बाद आते हैं।
-
1.4.1 रंग का उपयोग
स्तर A
मौजूदा पेज पर हल्का रंग भरा है, एक पट्टी है और मोटे अक्षर हैं; उसका समूह भी मोटे अक्षरों में है, और आइकन पट्टी में भी उस पर निशान रहता है।
-
1.4.13 Hover या फ़ोकस पर सामग्री
स्तर AA
पट्टी के टूलटिप होवर और कीबोर्ड फ़ोकस पर दिखते हैं, पॉइंटर उन पर ले जाने पर बने रहते हैं, और Escape उन्हें छिपा देता है।
-
2.5.3 नाम में लेबल
स्तर A
पट्टी में हर आइकन का नाम वही शब्द है जो पहले दिखता था, और टूलटिप वही शब्द दिखाता है, इसलिए वॉइस कमांड अब भी मेल खाते हैं।
-
4.1.2 नाम, भूमिका, मान
स्तर A
समूह बटन विस्तारित या संक्षिप्त बताते हैं, और खुले पेज का लिंक मौजूदा पेज बताता है।
-
4.1.3 स्टेटस मैसेज
स्तर AA
साइडबार समेटने या फैलाने की पुष्टि स्टेटस मैसेज से होती है, फ़ोकस हटाए बिना।
उपयोग
इसे कब इस्तेमाल करें
इसे अपनाएँ
- ऐसे ऐप और डैशबोर्ड जिनमें कई हिस्से हैं और लोग दिन भर उनके बीच आते-जाते हैं।
- ऐसा नेविगेशन जिसे काम के बगल में दिखते रहना है, और जिसे समेटने की जगह भी हो।
कुछ और इस्तेमाल करें
- कुछ ही पेज वाली कंटेंट साइटें: हेडर नेविगेशन काफ़ी है।
- फ़ोन, जहाँ साइडबार को ड्रॉअर बन जाना चाहिए।
- सहेजें या एक्सपोर्ट जैसे कमांड: उनकी जगह टूलबार या मेन्यू बटन में है।
आम विफलताएँ
आमतौर पर यह कहाँ गलत होता है
सिमटी पट्टी में बिना नाम के आइकन
display: none से शब्द छिपाने पर लिंक का कोई नाम ही नहीं रहता। यहाँ वे सिर्फ़ नज़र से छिपे हैं, इसलिए हर आइकन अब भी नाम वाला लिंक है।
लेबल के रूप में title एट्रिब्यूट
title वाले टूलटिप कीबोर्ड फ़ोकस या टच पर नहीं दिखते, और स्क्रीन रीडर उन्हें एक जैसा नहीं पढ़ते। यहाँ दिखने वाला टूलटिप लिंक का अपना टेक्स्ट है।
साइट नेविगेशन पर मेन्यू रोल
role=menu स्क्रीन रीडर को तीर कुंजियों वाले ऐप्लिकेशन मेन्यू की उम्मीद दिलाता है। नेविगेशन को लिंक और डिस्क्लोज़र बटन चाहिए।
समूह का नाम जो लिंक भी हो और टॉगल भी
अगर बिलिंग एक पेज खोले और फैले भी, तो लोग नहीं जान पाते कि क्या होगा। समूहों के नाम बटन हैं; पेज उनके अंदर के लिंक हैं।
विस्तारित स्थिति जो सच नहीं है
अगर पट्टी किसी समूह के लिंक छिपा दे पर उसका बटन अब भी विस्तारित बताए, तो लोग ऐसे लिंक ढूँढते हैं जो हैं ही नहीं। पट्टी हर समूह को संक्षिप्त कर देती है।
टूलटिप जिन्हें हटाया न जा सके
बगल की सामग्री ढकने वाला टूलटिप, जिसे बंद करने का कोई तरीक़ा न हो, डब्ल्यूसीएजी 1.4.13 में फ़ेल होता है। यहाँ Escape उसे छिपा देता है।
नोट्स
इसे बनाना
- समूह APG के डिस्क्लोज़र नेविगेशन पैटर्न पर चलते हैं: aria-expanded और aria-controls वाला बटन, और उसके ठीक बाद एक सूची में लिंक।
- पट्टी में शब्द display: none नहीं, बल्कि नज़र से छिपाने वाली स्टाइल इस्तेमाल करते हैं, और वही एलिमेंट टूलटिप बन जाता है, इसलिए जो दिखता है और जो पढ़ा जाता है, वे कभी अलग नहीं होते।
- समेटने वाले बटन का लेबल साइडबार समेटें और साइडबार फैलाएँ के बीच बदलता है, इसलिए उस पर अलग से aria-pressed नहीं है; स्टेटस मैसेज बदलाव की पुष्टि करता है।
- चुनाव याद रखें, जैसे localStorage में, ताकि साइडबार वैसा ही रहे जैसा लोगों ने छोड़ा था।
- सिंगल-पेज ऐप में पेज खुलने पर फ़ोकस उसकी मुख्य हेडिंग पर भी जाना चाहिए; पेज बदलने के बाद फ़ोकस वाला पैटर्न देखें।
स्रोत: WAI-एआरआईए ऑथरिंग प्रैक्टिसेज़: डिस्क्लोज़र नेविगेशन मेन्यू का उदाहरण · डब्ल्यूसीएजी 2.2 को समझना: होवर या फ़ोकस पर सामग्री
लाइट और डार्क थीम में, डेस्कटॉप और फ़ोन की चौड़ाई पर axe से और कीबोर्ड से जाँचा गया। अभी हर स्क्रीन रीडर और ब्राउज़र जोड़ी के साथ नहीं परखा गया। सुधार बताएँ