सुलभता पैटर्न · इंटरैक्शन और मोशन
फ़ोकस इंडिकेटर
रिंग फ़ोकस रंग की एक आउटलाइन है, जो सतह के रंग के दो घेरों (हेलो) के बीच रहती है, इसलिए पीछे जो भी हो, कोई एक पट्टी उससे अलग दिखती है: हल्का पेज, गहरी पट्टी या ब्रांड रंग की भराई। गैलरी में Tab दबाएँ, और मीटर फ़ोकस वाले एलिमेंट की रिंग मापता है: उसकी चौड़ाई, पृष्ठभूमि के मुक़ाबले उसका कंट्रास्ट और यह कि कुछ उसे ढक तो नहीं रहा।
- डब्ल्यूसीएजी मानदंड
- 5
- कीबोर्ड नियम
- 4
- जाँच का तरीक़ा
- axe, कीबोर्ड और इंस्पेक्टर
लाइव डेमो
आज़माएँ
इसे माउस, कीबोर्ड या स्क्रीन रीडर से इस्तेमाल करें। साथ का इंस्पेक्टर दिखाता है कि आपके इस्तेमाल के दौरान ब्राउज़र सहायक तकनीक को क्या बताता है: फ़ोकस, स्थिति में बदलाव और घोषणाएँ।
फ़ोकस मीटर
जिस पर भी फ़ोकस हो, उसकी रिंग मापने के लिए Tab दबाएँ।
- रिंग की चौड़ाई
- –
- किनारे से गैप
- –
- पृष्ठभूमि के मुक़ाबले रिंग
- –
- पृष्ठभूमि के मुक़ाबले हेलो
- –
- 2.4.7 फ़ोकस दिखाई देता है मापा नहीं गया
- 1.4.11 गैर-टेक्स्ट कंट्रास्ट मापा नहीं गया
- 2.4.11 फ़ोकस ढका नहीं मापा नहीं गया
- 2.4.13 फ़ोकस का रूप मापा नहीं गया
ख़राब संस्करण: लिंक, बटन और टैब पर कोई रिंग नहीं है, फ़ील्ड, आइकन बटन और कार्ड पर 1 px की हल्की रिंग है, और ऑर्डर सूची फ़ोकस को अपनी स्टिकी बार के नीचे खिसकने देती है।
पेज की सतह पर
सैफ़रन टेबल बेंगलुरु के इंदिरानगर में उडुपी थाली परोसता है। बुक करने से पहले पूरा मेनू देखें।
उलटे रंगों वाली पट्टी पर
बारह व्यंजनों की थाली, दोपहर बारह से तीन बजे तक।
ऑर्डर पर डोसा और अप्पम, शाम सात से रात ग्यारह बजे तक।
फ़िल्टर कॉफ़ी, छाछ और ताज़ा नींबू सोडा, दिन भर।
जावास्क्रिप्ट के बिना डेमो उतना ही काम करता है जितना उसका एचटीएमएल; इंस्पेक्टर के लिए जावास्क्रिप्ट चाहिए।
कीबोर्ड
जिन कुंजियों पर यह काम करता है
हर क्रिया पॉइंटर के बिना काम करती है।
| कुंजी | यह क्या करती है |
|---|---|
| TabयाShiftTab | गैलरी में आगे-पीछे जाता है; जिस पर भी फ़ोकस आए, उस पर दो रंगों की रिंग दिखती है, और मीटर उसे मापता है। |
| Arrow RightयाArrow Left | मेनू टैब में, अगले या पिछले टैब पर जाता है और उसका पैनल दिखाता है। |
| HomeयाEnd | मेनू टैब में, पहले या आख़िरी टैब पर जाता है। |
| EnterयाSpace | फ़ोकस वाले बटन को चलाता है; Enter लिंक भी खोलता है। उसके बाद भी रिंग उसी एलिमेंट पर रहती है। |
स्क्रीन रीडर
यह क्या घोषित करता है
मार्कअप की भूमिकाओं, नामों और स्थितियों से लिखा गया।
| कब | अपेक्षित घोषणा |
|---|---|
| फ़ोकस बुकिंग बटन पर पहुँचता है | टेबल बुक करें, बटन |
| फ़ोकस सहेजें आइकन बटन पर पहुँचता है | सहेजें, टॉगल बटन, दबा हुआ नहीं |
| फ़ोकस पहले मेनू टैब पर पहुँचता है | दोपहर का खाना, टैब, चयनित, 3 में से 1 |
| फ़ोकस ब्रांड पट्टी वाले कार्ड पर पहुँचता है | आज की थाली, बारह व्यंजन, ₹320, लिंक |
| रिंग दिखती है | कुछ अतिरिक्त नहीं: रिंग केवल दिखने वाली चीज़ है, पढ़ा जाता है नाम और भूमिका |
| टेबल बुक होती है | टेबल का अनुरोध भेज दिया गया। हम एक घंटे के अंदर SMS से पुष्टि करेंगे। |
ये अपेक्षित घोषणाएँ हैं, रिकॉर्डिंग नहीं। स्क्रीन रीडर और ब्राउज़र के हिसाब से शब्द और क्रम बदलते हैं।
कोड
कोड कॉपी करें
वही फ़ाइलें जिन पर यह डेमो चलता है। स्टाइल एक प्रीफ़िक्स के साथ परोसी जाती हैं जो इस साइट की अपनी स्टाइल को डेमो से दूर रखता है; आप जो कॉपी करते हैं वह मूल है।
<div class="ap-focus" data-ap-focus-indicator>
<div class="ap-focus__layout">
<section class="ap-focus__meter" aria-labelledby="focus-meter-name">
<div class="ap-focus__meter-top">
<h3 class="ap-focus__meter-name" id="focus-meter-name">Focus meter</h3>
<p class="ap-focus__target" data-ap-target><span class="ap-focus__target-idle">Press Tab to measure the ring on whatever has focus.</span></p>
</div>
<dl class="ap-focus__nums">
<div class="ap-focus__num"><dt>Ring width</dt><dd><span data-ap-m="width" translate="no">–</span></dd></div>
<div class="ap-focus__num"><dt>Gap to the edge</dt><dd><span data-ap-m="gap" translate="no">–</span></dd></div>
<div class="ap-focus__num"><dt>Ring against background</dt><dd><span class="ap-focus__swatch" data-ap-swatch="ring" aria-hidden="true"></span><span data-ap-m="ring" translate="no">–</span></dd></div>
<div class="ap-focus__num"><dt>Halo against background</dt><dd><span class="ap-focus__swatch" data-ap-swatch="halo" aria-hidden="true"></span><span data-ap-m="halo" translate="no">–</span></dd></div>
</dl>
<ul class="ap-focus__checks">
<li class="ap-focus__check" data-ap-check="visible" data-state="idle">
<svg class="ap-focus__mark" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path class="ap-focus__mark-idle" d="M7 12h10"/><path class="ap-focus__mark-pass" d="m5 12.5 4.5 4.5L19 7.5"/><path class="ap-focus__mark-fail" d="M7 7l10 10M17 7 7 17"/></svg>
<span class="ap-focus__what"><span class="ap-focus__ref" translate="no">2.4.7</span> <span class="ap-focus__crit">Focus visible</span></span>
<span class="ap-focus__verdict" data-ap-verdict>Not measured</span>
</li>
<li class="ap-focus__check" data-ap-check="contrast" data-state="idle">
<svg class="ap-focus__mark" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path class="ap-focus__mark-idle" d="M7 12h10"/><path class="ap-focus__mark-pass" d="m5 12.5 4.5 4.5L19 7.5"/><path class="ap-focus__mark-fail" d="M7 7l10 10M17 7 7 17"/></svg>
<span class="ap-focus__what"><span class="ap-focus__ref" translate="no">1.4.11</span> <span class="ap-focus__crit">Non-text contrast</span></span>
<span class="ap-focus__verdict" data-ap-verdict>Not measured</span>
</li>
<li class="ap-focus__check" data-ap-check="obscured" data-state="idle">
<svg class="ap-focus__mark" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path class="ap-focus__mark-idle" d="M7 12h10"/><path class="ap-focus__mark-pass" d="m5 12.5 4.5 4.5L19 7.5"/><path class="ap-focus__mark-fail" d="M7 7l10 10M17 7 7 17"/></svg>
<span class="ap-focus__what"><span class="ap-focus__ref" translate="no">2.4.11</span> <span class="ap-focus__crit">Focus not obscured</span></span>
<span class="ap-focus__verdict" data-ap-verdict>Not measured</span>
</li>
<li class="ap-focus__check" data-ap-check="appearance" data-state="idle">
<svg class="ap-focus__mark" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path class="ap-focus__mark-idle" d="M7 12h10"/><path class="ap-focus__mark-pass" d="m5 12.5 4.5 4.5L19 7.5"/><path class="ap-focus__mark-fail" d="M7 7l10 10M17 7 7 17"/></svg>
<span class="ap-focus__what"><span class="ap-focus__ref" translate="no">2.4.13</span> <span class="ap-focus__crit">Focus appearance</span></span>
<span class="ap-focus__verdict" data-ap-verdict>Not measured</span>
</li>
</ul>
<p class="ap-focus__why" data-ap-why></p>
</section>
<div class="ap-focus__gallery">
<p class="ap-focus__bad-note"><svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M12 9v4m0 4h.01M10.3 3.9 2.4 18a2 2 0 0 0 1.7 3h15.8a2 2 0 0 0 1.7-3L13.7 3.9a2 2 0 0 0-3.4 0Z"/></svg><span>Bad versions: the link, the button and the tabs have no ring at all, the field, the icon buttons and the card get a faint 1 px ring, and the order list lets focus slide under its sticky bar.</span></p>
<div class="ap-focus__tile ap-focus__tile--page" role="group" aria-labelledby="focus-cap-page">
<p class="ap-focus__cap" id="focus-cap-page">On the page surface</p>
<p class="ap-focus__text">Saffron Table serves Udupi thalis in Indiranagar, Bengaluru. <a class="ap-focus__link" href="#focus-menu">See the full menu</a> before you book.</p>
<div class="ap-focus__book">
<div class="ap-field ap-focus__guests">
<label class="ap-label" for="focus-guests">Guests</label>
<input class="ap-input" id="focus-guests" type="number" min="1" max="12" value="2" inputmode="numeric" />
</div>
<button type="button" class="ap-btn ap-btn--primary" data-ap-book>Book a table</button>
</div>
</div>
<div class="ap-focus__tile ap-focus__tile--invert" role="group" aria-labelledby="focus-cap-invert">
<div class="ap-focus__tile-top">
<p class="ap-focus__cap" id="focus-cap-invert">On an inverted band</p>
<div class="ap-focus__icons">
<button type="button" class="ap-focus__icon" aria-label="Save" aria-pressed="false" data-ap-save>
<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M19 21 12 16.5 5 21V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2Z"/></svg>
</button>
<button type="button" class="ap-focus__icon" aria-label="Share" data-ap-share>
<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><circle cx="18" cy="5" r="3"/><circle cx="6" cy="12" r="3"/><circle cx="18" cy="19" r="3"/><path d="m8.6 13.5 6.8 4M15.4 6.5l-6.8 4"/></svg>
</button>
</div>
</div>
<div class="ap-focus__tabs" role="tablist" aria-label="Menus">
<button type="button" class="ap-focus__tab" role="tab" id="focus-tab-lunch" aria-selected="true" aria-controls="focus-panel-lunch">Lunch</button>
<button type="button" class="ap-focus__tab" role="tab" id="focus-tab-dinner" aria-selected="false" aria-controls="focus-panel-dinner" tabindex="-1">Dinner</button>
<button type="button" class="ap-focus__tab" role="tab" id="focus-tab-drinks" aria-selected="false" aria-controls="focus-panel-drinks" tabindex="-1">Drinks</button>
</div>
<p class="ap-focus__panel" role="tabpanel" id="focus-panel-lunch" aria-labelledby="focus-tab-lunch" tabindex="0">A thali of twelve dishes, served from noon until three.</p>
<p class="ap-focus__panel" role="tabpanel" id="focus-panel-dinner" aria-labelledby="focus-tab-dinner" tabindex="0" hidden>Dosas and appams to order, from seven until eleven.</p>
<p class="ap-focus__panel" role="tabpanel" id="focus-panel-drinks" aria-labelledby="focus-tab-drinks" tabindex="0" hidden>Filter coffee, buttermilk and fresh lime soda all day.</p>
</div>
<div class="ap-focus__tile ap-focus__tile--brand" role="group" aria-labelledby="focus-cap-brand">
<p class="ap-focus__cap" id="focus-cap-brand">On the brand color</p>
<a class="ap-focus__card" href="#focus-thali">
<svg class="ap-focus__art" viewBox="0 0 96 64" aria-hidden="true" focusable="false"><circle class="ap-focus__plate" cx="48" cy="32" r="29"/><circle class="ap-focus__bowl ap-focus__bowl--a" cx="34" cy="19" r="8"/><circle class="ap-focus__bowl ap-focus__bowl--b" cx="54" cy="16" r="7"/><circle class="ap-focus__bowl ap-focus__bowl--c" cx="66" cy="31" r="7.5"/><ellipse class="ap-focus__rice" cx="42" cy="40" rx="13" ry="9"/><circle class="ap-focus__bowl ap-focus__bowl--a" cx="61" cy="47" r="6"/></svg>
<span class="ap-focus__card-body">
<span class="ap-focus__card-name">Thali of the day</span>
<span class="ap-focus__card-meta">Twelve dishes, ₹320</span>
</span>
</a>
<div class="ap-focus__brand-foot">
<p class="ap-focus__brand-text">Festive menu from 20 October.</p>
<button type="button" class="ap-focus__ghost" data-ap-gift>Gift a meal</button>
</div>
</div>
<div class="ap-focus__tile ap-focus__tile--list" role="group" aria-labelledby="focus-cap-list">
<p class="ap-focus__cap" id="focus-cap-list">In a list with a sticky bar</p>
<div class="ap-focus__scroll" data-ap-scroll>
<ul class="ap-focus__orders" aria-label="Your orders">
<li><a class="ap-focus__order" href="#focus-order-4821"><span class="ap-focus__dish">Masala dosa, two</span> <span class="ap-focus__when">12 Sep · ₹240</span></a></li>
<li><a class="ap-focus__order" href="#focus-order-4790"><span class="ap-focus__dish">Lunch thali</span> <span class="ap-focus__when">9 Sep · ₹320</span></a></li>
<li><a class="ap-focus__order" href="#focus-order-4755"><span class="ap-focus__dish">Bisi bele bath</span> <span class="ap-focus__when">4 Sep · ₹180</span></a></li>
<li><a class="ap-focus__order" href="#focus-order-4712"><span class="ap-focus__dish">Filter coffee, four</span> <span class="ap-focus__when">1 Sep · ₹160</span></a></li>
<li><a class="ap-focus__order" href="#focus-order-4688"><span class="ap-focus__dish">Neer dosa with curry</span> <span class="ap-focus__when">28 Aug · ₹260</span></a></li>
<li><a class="ap-focus__order" href="#focus-order-4651"><span class="ap-focus__dish">Mysore pak, half kilo</span> <span class="ap-focus__when">24 Aug · ₹350</span></a></li>
<li><a class="ap-focus__order" href="#focus-order-4630"><span class="ap-focus__dish">Rava idli, two</span> <span class="ap-focus__when">20 Aug · ₹150</span></a></li>
</ul>
<div class="ap-focus__bar">
<button type="button" class="ap-btn" data-ap-bills>Download bills</button>
</div>
</div>
</div>
<p class="ap-focus__status" role="status"></p>
</div>
</div>
</div>
/* Shared primitives: buttons and form fields used across the patterns.
Uses the --ap-* design tokens. */
.ap-btn {
display: inline-flex;
align-items: center;
justify-content: center;
gap: 8px;
min-height: 40px;
padding: 0 16px;
border: 1px solid var(--ap-border-strong);
border-radius: var(--ap-radius-sm);
background: var(--ap-surface);
color: var(--ap-text);
font: inherit;
font-weight: 600;
line-height: 1.2;
text-decoration: none;
white-space: nowrap;
cursor: pointer;
transition: background-color var(--ap-duration) var(--ap-ease), border-color var(--ap-duration) var(--ap-ease), box-shadow var(--ap-duration) var(--ap-ease);
}
.ap-btn:hover {
background: var(--ap-surface-2);
}
.ap-btn:focus-visible {
outline: 2px solid var(--ap-focus);
outline-offset: 2px;
}
.ap-btn:disabled,
.ap-btn[aria-disabled="true"] {
opacity: .55;
cursor: not-allowed;
}
.ap-btn--primary {
border-color: var(--ap-accent);
background: var(--ap-accent);
color: var(--ap-on-accent);
box-shadow: var(--ap-shadow-sm);
}
.ap-btn--primary:hover {
border-color: var(--ap-accent-hover);
background: var(--ap-accent-hover);
}
.ap-btn--danger {
border-color: var(--ap-danger);
background: var(--ap-danger);
color: var(--ap-surface);
}
.ap-btn--danger:hover {
filter: brightness(1.08);
}
.ap-btn--ghost {
border-color: transparent;
background: transparent;
}
.ap-btn--ghost:hover {
background: var(--ap-surface-2);
}
.ap-btn__icon {
width: 18px;
height: 18px;
flex-shrink: 0;
fill: none;
stroke: currentColor;
stroke-width: 2;
stroke-linecap: round;
stroke-linejoin: round;
}
.ap-field {
display: grid;
gap: 6px;
}
.ap-label {
color: var(--ap-text);
font-weight: 600;
font-size: .9375rem;
}
.ap-hint {
margin: 0;
color: var(--ap-text-3);
font-size: .875rem;
line-height: 1.45;
}
.ap-error {
display: flex;
align-items: flex-start;
gap: 6px;
margin: 0;
color: var(--ap-danger);
font-size: .875rem;
font-weight: 600;
line-height: 1.45;
}
.ap-input {
width: 100%;
min-height: 44px;
padding: 10px 12px;
border: 1px solid var(--ap-border-strong);
border-radius: var(--ap-radius-sm);
background: var(--ap-surface);
color: var(--ap-text);
font: inherit;
line-height: 1.4;
transition: border-color var(--ap-duration) var(--ap-ease), box-shadow var(--ap-duration) var(--ap-ease);
}
.ap-input::placeholder {
color: var(--ap-text-3);
}
.ap-input:hover {
border-color: var(--ap-text-2);
}
.ap-input:focus-visible {
outline: 2px solid var(--ap-focus);
outline-offset: 1px;
border-color: var(--ap-focus);
}
.ap-input[aria-invalid="true"] {
border-color: var(--ap-danger);
box-shadow: inset 4px 0 0 var(--ap-danger);
}
textarea.ap-input {
resize: vertical;
min-height: 88px;
}
@media (prefers-reduced-motion: reduce) {
.ap-btn,
.ap-input { transition: none; }
}
/* Focus indicator. Uses the --ap-* design tokens and the shared primitives. */
.ap-focus {
/* The ring: an outline in the focus color between two halos in the
surface color. One of the two bands contrasts with any background. */
--ring-color: var(--ap-focus);
--ring-halo: var(--ap-surface);
--ring-width: 3px;
--ring-gap: 2px;
--ring-outer: 2px;
width: min(100%, 780px);
margin-inline: auto;
color: var(--ap-text);
container-type: inline-size;
}
.ap-focus [hidden] {
display: none;
}
/* Every focusable element in the component, keyboard focus only. */
.ap-focus :focus-visible {
outline: var(--ring-width) solid var(--ring-color);
outline-offset: var(--ring-gap);
box-shadow:
0 0 0 var(--ring-gap) var(--ring-halo),
0 0 0 calc(var(--ring-gap) + var(--ring-width) + var(--ring-outer)) var(--ring-halo);
}
.ap-focus__layout {
display: grid;
gap: 16px;
}
/* ── The meter ── */
.ap-focus__meter {
display: grid;
gap: 14px;
padding: 18px 20px;
border: 1px solid var(--ap-border);
border-radius: var(--ap-radius-lg);
background: var(--ap-surface);
box-shadow: var(--ap-shadow-md);
}
.ap-focus__meter-top {
display: flex;
flex-wrap: wrap;
align-items: baseline;
justify-content: space-between;
gap: 4px 16px;
}
.ap-focus__meter-name {
margin: 0;
font-size: 1rem;
font-weight: 650;
line-height: 1.35;
}
.ap-focus__target {
margin: 0;
color: var(--ap-text-3);
font-size: .875rem;
line-height: 1.45;
}
.ap-focus__target strong {
color: var(--ap-text);
font-weight: 650;
}
.ap-focus__nums {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 8px;
margin: 0;
}
.ap-focus__num {
min-width: 0;
padding: 10px 12px;
border-radius: var(--ap-radius-sm);
background: var(--ap-surface-2);
}
.ap-focus__num dt {
color: var(--ap-text-3);
font-size: .75rem;
font-weight: 600;
line-height: 1.35;
}
.ap-focus__num dd {
display: flex;
align-items: center;
gap: 8px;
margin: 4px 0 0;
font-family: var(--ap-mono);
font-size: 1.0625rem;
font-weight: 650;
font-variant-numeric: tabular-nums;
}
/* Left half: the background. Right half: the band measured against it. */
.ap-focus__swatch {
display: none;
width: 22px;
height: 14px;
flex-shrink: 0;
border-radius: 4px;
background: linear-gradient(90deg, var(--sw-bg) 50%, var(--sw-fg) 50%);
box-shadow: inset 0 0 0 1px var(--ap-border-strong);
}
.ap-focus__swatch[data-on] {
display: block;
}
.ap-focus__checks {
display: grid;
gap: 6px;
margin: 0;
padding: 0;
list-style: none;
}
.ap-focus__checks {
grid-template-columns: repeat(2, minmax(0, 1fr));
}
/* Verdict first to the eye, criterion first to the ear. */
.ap-focus__check {
display: grid;
grid-template-columns: auto minmax(0, 1fr);
grid-template-areas: "mark verdict" "what what";
align-items: center;
gap: 4px 6px;
min-width: 0;
padding: 10px 12px;
border: 1px solid var(--ap-border);
border-radius: var(--ap-radius-sm);
font-size: .8125rem;
line-height: 1.35;
}
.ap-focus__check .ap-focus__mark { grid-area: mark; }
.ap-focus__what { grid-area: what; }
.ap-focus__verdict { grid-area: verdict; }
.ap-focus__mark {
width: 18px;
height: 18px;
fill: none;
stroke: currentColor;
stroke-width: 2.5;
stroke-linecap: round;
stroke-linejoin: round;
}
.ap-focus__mark path {
display: none;
}
.ap-focus__check[data-state="idle"] .ap-focus__mark-idle,
.ap-focus__check[data-state="pass"] .ap-focus__mark-pass,
.ap-focus__check[data-state="fail"] .ap-focus__mark-fail {
display: inline;
}
.ap-focus__ref {
color: var(--ap-text-3);
font-family: var(--ap-mono);
font-size: .75rem;
}
.ap-focus__crit {
font-weight: 600;
}
.ap-focus__verdict {
font-size: .9375rem;
font-weight: 650;
}
.ap-focus__check[data-state="idle"] {
color: var(--ap-text-3);
}
.ap-focus__check[data-state="pass"] {
border-color: var(--ap-success);
background: var(--ap-success-soft);
color: var(--ap-success);
}
.ap-focus__check[data-state="fail"] {
border-color: var(--ap-danger);
background: var(--ap-danger-soft);
color: var(--ap-danger);
}
.ap-focus__check[data-state="pass"] .ap-focus__ref,
.ap-focus__check[data-state="fail"] .ap-focus__ref {
color: inherit;
}
.ap-focus__why {
margin: 0;
color: var(--ap-text-2);
font-size: .875rem;
line-height: 1.5;
}
/* ── The gallery ── */
.ap-focus__gallery {
display: grid;
gap: 14px;
align-items: stretch;
}
.ap-focus__bad-note {
display: none;
align-items: flex-start;
gap: 10px;
margin: 0;
padding: 12px 14px;
border: 1px solid var(--ap-danger);
border-radius: var(--ap-radius);
background: var(--ap-danger-soft);
color: var(--ap-danger);
font-size: .875rem;
font-weight: 600;
line-height: 1.5;
}
.ap-focus[data-bad] .ap-focus__bad-note {
display: flex;
}
.ap-focus__bad-note svg {
width: 18px;
height: 18px;
flex-shrink: 0;
margin-top: 1px;
fill: none;
stroke: currentColor;
stroke-width: 2;
stroke-linecap: round;
stroke-linejoin: round;
}
.ap-focus__tile {
display: flex;
flex-direction: column;
gap: 12px;
min-width: 0;
padding: 16px 18px 18px;
border-radius: var(--ap-radius-lg);
/* A color close to the tile's own, for the faint ring of the bad versions. */
--tile-faint: var(--ap-border);
}
.ap-focus__tile--page,
.ap-focus__tile--list {
border: 1px solid var(--ap-border);
background: var(--ap-surface);
box-shadow: var(--ap-shadow-sm);
}
.ap-focus__tile--invert {
background: var(--ap-text);
color: var(--ap-surface);
--tile-faint: var(--ap-text-2);
}
.ap-focus__tile--brand {
background: var(--ap-accent);
color: var(--ap-on-accent);
--tile-faint: var(--ap-accent-hover);
}
.ap-focus__cap {
margin: 0;
color: var(--ap-text-3);
font-size: .75rem;
font-weight: 650;
letter-spacing: .06em;
line-height: 1.4;
text-transform: uppercase;
}
.ap-focus__tile--invert .ap-focus__cap {
color: var(--ap-surface-3);
}
.ap-focus__tile--brand .ap-focus__cap {
color: var(--ap-on-accent);
}
/* Page surface: a link in text, a field and a button. */
.ap-focus__text {
margin: 0;
color: var(--ap-text-2);
line-height: 1.6;
}
.ap-focus__link {
border-radius: 3px;
color: var(--ap-accent-text);
font-weight: 600;
text-decoration: underline;
text-decoration-thickness: 1px;
text-underline-offset: 3px;
}
.ap-focus__link:hover {
text-decoration-thickness: 2px;
}
.ap-focus__book {
display: flex;
flex-wrap: wrap;
align-items: flex-end;
gap: 12px;
margin-top: auto;
}
.ap-focus__guests {
width: 96px;
}
.ap-focus__book .ap-btn {
min-height: 44px;
}
/* Inverted band: icon buttons and tabs. */
.ap-focus__tile-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-block: -6px;
}
.ap-focus__icons {
display: flex;
gap: 6px;
}
.ap-focus__icon {
display: grid;
place-items: center;
width: 40px;
height: 40px;
padding: 0;
border: 0;
border-radius: var(--ap-radius-sm);
background: transparent;
color: inherit;
cursor: pointer;
transition: background-color var(--ap-duration) var(--ap-ease);
}
.ap-focus__icon:hover {
background: var(--ap-text-2);
}
.ap-focus__icon svg {
width: 20px;
height: 20px;
fill: none;
stroke: currentColor;
stroke-width: 2;
stroke-linecap: round;
stroke-linejoin: round;
}
.ap-focus__icon[aria-pressed="true"] svg {
fill: currentColor;
}
.ap-focus__tabs {
display: flex;
gap: 4px;
border-bottom: 1px solid var(--ap-text-2);
}
.ap-focus__tab {
position: relative;
min-height: 40px;
padding: 0 12px;
border: 0;
border-radius: var(--ap-radius-sm) var(--ap-radius-sm) 0 0;
background: transparent;
color: var(--ap-surface-3);
font: inherit;
font-weight: 500;
cursor: pointer;
}
.ap-focus__tab:hover {
color: var(--ap-surface);
}
.ap-focus__tab[aria-selected="true"] {
color: var(--ap-surface);
font-weight: 650;
}
/* The selected marker is a bar, not a shadow, so the focus halo cannot erase it. */
.ap-focus__tab[aria-selected="true"]::after {
content: "";
position: absolute;
left: 8px;
right: 8px;
bottom: -1px;
height: 3px;
border-radius: 3px 3px 0 0;
background: currentColor;
}
.ap-focus__panel {
margin: 0;
padding: 2px 4px;
border-radius: 4px;
color: var(--ap-surface-3);
line-height: 1.55;
}
/* Brand band: a card that is one link. */
.ap-focus__card {
display: flex;
align-items: center;
gap: 14px;
padding: 12px;
border-radius: var(--ap-radius);
background: var(--ap-surface);
color: var(--ap-text);
text-decoration: none;
box-shadow: var(--ap-shadow-md);
}
.ap-focus__card:hover .ap-focus__card-name {
text-decoration: underline;
text-underline-offset: 3px;
}
.ap-focus__art {
width: 76px;
height: 52px;
flex-shrink: 0;
border-radius: var(--ap-radius-sm);
background: var(--ap-surface-2);
}
.ap-focus__plate {
fill: var(--ap-surface);
stroke: var(--ap-border-strong);
stroke-width: 1.5;
}
.ap-focus__bowl--a { fill: var(--ap-warning); }
.ap-focus__bowl--b { fill: var(--ap-success); }
.ap-focus__bowl--c { fill: var(--ap-danger); }
.ap-focus__rice { fill: var(--ap-surface-3); }
.ap-focus__card-body {
display: grid;
gap: 2px;
min-width: 0;
}
.ap-focus__card-name {
font-weight: 650;
}
.ap-focus__card-meta {
color: var(--ap-text-3);
font-size: .875rem;
}
.ap-focus__brand-foot {
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: space-between;
gap: 10px 16px;
margin-top: auto;
}
.ap-focus__brand-text {
margin: 0;
font-weight: 600;
line-height: 1.45;
}
.ap-focus__ghost {
min-height: 40px;
padding: 0 16px;
border: 1px solid var(--ap-on-accent);
border-radius: var(--ap-radius-sm);
background: transparent;
color: var(--ap-on-accent);
font: inherit;
font-weight: 600;
cursor: pointer;
transition: background-color var(--ap-duration) var(--ap-ease), color var(--ap-duration) var(--ap-ease);
}
.ap-focus__ghost:hover {
background: var(--ap-on-accent);
color: var(--ap-accent);
}
/* A scrolling list with a sticky bar. scroll-padding as tall as the bar
(plus the ring) makes the browser stop a focused row above it. */
.ap-focus__scroll {
position: relative;
height: 204px;
overflow-y: auto;
overscroll-behavior: contain;
border: 1px solid var(--ap-border);
border-radius: var(--ap-radius);
background: var(--ap-surface);
scroll-padding-block: 10px 76px;
}
.ap-focus__orders {
display: grid;
gap: 2px;
margin: 0;
padding: 8px;
list-style: none;
}
.ap-focus__order {
display: flex;
flex-wrap: wrap;
align-items: baseline;
justify-content: space-between;
gap: 2px 12px;
padding: 10px 12px;
border-radius: var(--ap-radius-sm);
color: var(--ap-text);
text-decoration: none;
}
.ap-focus__order:hover {
background: var(--ap-surface-2);
}
.ap-focus__dish {
font-weight: 600;
}
.ap-focus__when {
color: var(--ap-text-3);
font-size: .8125rem;
white-space: nowrap;
}
.ap-focus__bar {
position: sticky;
bottom: 0;
z-index: 1;
display: flex;
justify-content: flex-end;
padding: 10px 12px;
border-top: 1px solid var(--ap-border);
background: var(--ap-surface-2);
}
.ap-focus__status {
margin: 0;
min-height: 1.5em;
color: var(--ap-text);
font-weight: 600;
}
.ap-focus__status:empty {
display: none;
}
@container (min-width: 620px) {
.ap-focus__nums { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.ap-focus__checks { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.ap-focus__gallery { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.ap-focus__bad-note,
.ap-focus__status { grid-column: 1 / -1; }
}
/* ── The bad versions, for comparison only. Never ship these. ── */
.ap-focus[data-bad] :is(.ap-focus__link, .ap-focus__book .ap-btn, .ap-focus__tab):focus-visible {
outline: none;
box-shadow: none;
}
.ap-focus[data-bad] :is(.ap-input, .ap-focus__icon, .ap-focus__card):focus-visible {
outline: 1px solid var(--tile-faint);
outline-offset: 0;
box-shadow: none;
}
.ap-focus[data-bad] .ap-input:focus-visible {
border-color: var(--ap-border-strong);
}
.ap-focus[data-bad] .ap-focus__card:focus-visible {
box-shadow: var(--ap-shadow-md);
}
.ap-focus[data-bad] .ap-focus__scroll {
scroll-padding-block: 0;
}
@media (prefers-reduced-motion: reduce) {
.ap-focus__icon { transition: none; }
}
/**
* Focus indicator: a two-color ring on every control, kept clear of sticky
* bars with scroll-padding, and a meter that measures the ring on whatever
* has focus (WCAG 2.4.7, 1.4.11, 2.4.11 and 2.4.13).
*
* Markup: [data-ap-focus-indicator] holding the components, a meter
* ([data-ap-target], [data-ap-m], [data-ap-swatch], [data-ap-check],
* [data-ap-why]) and a role=status paragraph. Add data-bad to the root to
* see the failures the ring guards against.
*/
const MIN = 3; // contrast for 1.4.11 and 2.4.13
const SEEN = 1.1; // below this a band is effectively invisible
const MIN_BAND = 2; // px: 2.4.13's two-pixel perimeter
/* ── Color: parse computed values, composite, measure ── */
function parseColor(text) {
const alpha = (a) => (a == null ? 1 : a.endsWith("%") ? parseFloat(a) / 100 : parseFloat(a));
let m = /rgba?\(\s*([\d.]+)[\s,]+([\d.]+)[\s,]+([\d.]+)(?:\s*[,/]\s*([\d.]+%?))?/.exec(text);
if (m) return { r: +m[1], g: +m[2], b: +m[3], a: alpha(m[4]) };
// color-mix() and friends compute to color(srgb r g b / a), in 0–1.
m = /color\(srgb\s+([\d.e-]+)\s+([\d.e-]+)\s+([\d.e-]+)(?:\s*\/\s*([\d.]+%?))?/.exec(text);
if (m) return { r: m[1] * 255, g: m[2] * 255, b: m[3] * 255, a: alpha(m[4]) };
return null;
}
const over = (top, under) => ({
r: top.r * top.a + under.r * (1 - top.a),
g: top.g * top.a + under.g * (1 - top.a),
b: top.b * top.a + under.b * (1 - top.a),
a: 1,
});
function luminance({ r, g, b }) {
const ch = (c) => { c /= 255; return c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4; };
return 0.2126 * ch(r) + 0.7152 * ch(g) + 0.0722 * ch(b);
}
function contrast(a, b) {
const x = luminance(a);
const y = luminance(b);
return (Math.max(x, y) + 0.05) / (Math.min(x, y) + 0.05);
}
const css = ({ r, g, b }) => `rgb(${Math.round(r)} ${Math.round(g)} ${Math.round(b)})`;
// WCAG ratios are not rounded up: 2.996 is a fail, so show it as 2.99.
const ratio = (n) => `${(Math.floor(n * 100) / 100).toFixed(2)}:1`;
/** The color the ring is drawn over: the first solid background behind it. */
function backgroundOf(start) {
const layers = [];
for (let n = start; n && n.nodeType === 1; n = n.parentElement) {
const c = parseColor(getComputedStyle(n).backgroundColor);
if (c && c.a > 0) {
layers.push(c);
if (c.a >= 1) break;
}
}
let base = { r: 255, g: 255, b: 255, a: 1 };
for (const c of layers.reverse()) base = over(c, base);
return base;
}
/** Solid rings drawn with box-shadow: no offset, no blur, a spread. */
function halosOf(shadow) {
if (!shadow || shadow === "none") return [];
const parts = [];
let depth = 0;
let start = 0;
for (let i = 0; i < shadow.length; i++) {
if (shadow[i] === "(") depth++;
else if (shadow[i] === ")") depth--;
else if (shadow[i] === "," && depth === 0) {
parts.push(shadow.slice(start, i));
start = i + 1;
}
}
parts.push(shadow.slice(start));
return parts.map((part) => {
const color = parseColor(part);
const [x = 0, y = 0, blur = 0, spread = 0] = (part.replace(/\w+\([^)]*\)/g, "").match(/-?[\d.]+px/g) || []).map(parseFloat);
return { color, x, y, blur, spread, inset: /\binset\b/.test(part) };
}).filter((s) => s.color && s.color.a > 0 && !s.inset && !s.x && !s.y && !s.blur && s.spread > 0);
}
/** How much of the element is on top at its own position: 1, part, or 0. */
function shownShare(el) {
let seen = 0;
let total = 0;
for (const r of el.getClientRects()) {
for (let i = 0; i < 5; i++) {
for (let j = 0; j < 3; j++) {
const x = r.left + ((i + 0.5) * r.width) / 5;
const y = r.top + ((j + 0.5) * r.height) / 3;
total++;
if (x < 0 || y < 0 || x >= innerWidth || y >= innerHeight) continue;
const top = document.elementFromPoint(x, y);
if (top && (top === el || el.contains(top))) seen++;
}
}
}
return total ? seen / total : 0;
}
function nameOf(el) {
const text = (el.getAttribute("aria-label") || (el.labels && el.labels[0] ? el.labels[0].textContent : "")
|| el.querySelector?.(".ap-focus__card-name, .ap-focus__dish")?.textContent || el.textContent || "").replace(/\s+/g, " ").trim();
return text.length > 44 ? `${text.slice(0, 42)}…` : text;
}
export function init(root) {
const ac = new AbortController();
const on = (target, type, fn, options = {}) => target.addEventListener(type, fn, { ...options, signal: ac.signal });
const status = root.querySelector(".ap-focus__status");
const target = root.querySelector("[data-ap-target]");
const values = Object.fromEntries([...root.querySelectorAll("[data-ap-m]")].map((n) => [n.dataset.apM, n]));
const swatches = Object.fromEntries([...root.querySelectorAll("[data-ap-swatch]")].map((n) => [n.dataset.apSwatch, n]));
const checks = Object.fromEntries([...root.querySelectorAll("[data-ap-check]")].map((n) => [n.dataset.apCheck, n]));
const why = root.querySelector("[data-ap-why]");
const tabs = [...root.querySelectorAll("[role=tab]")];
let frame = 0;
let settle = 0;
let sayTimer = 0;
function say(text) {
status.textContent = "";
clearTimeout(sayTimer);
sayTimer = setTimeout(() => { status.textContent = text; }, 60);
}
function setCheck(key, state) {
const li = checks[key];
li.dataset.state = state;
li.querySelector("[data-ap-verdict]").textContent = state === "pass" ? "Pass" : state === "fail" ? "Fail" : "Not measured";
}
function swatch(key, fg, bg) {
const s = swatches[key];
if (!fg) {
s.removeAttribute("data-on");
return;
}
s.style.setProperty("--sw-fg", css(fg));
s.style.setProperty("--sw-bg", css(bg));
s.setAttribute("data-on", "");
}
function clear() {
const hint = document.createElement("span");
hint.className = "ap-focus__target-idle";
hint.textContent = "Press Tab to measure the ring on whatever has focus.";
target.replaceChildren(hint);
for (const n of Object.values(values)) n.textContent = "–";
for (const k of Object.keys(swatches)) swatch(k, null);
for (const k of Object.keys(checks)) setCheck(k, "idle");
why.textContent = "The checks need keyboard focus on something in the gallery.";
}
function measure(el) {
const label = document.createElement("strong");
label.textContent = nameOf(el);
const lead = document.createElement("span");
lead.textContent = "Measuring";
target.replaceChildren(lead, document.createTextNode(" "), label);
if (!el.matches(":focus-visible")) {
for (const n of Object.values(values)) n.textContent = "–";
for (const k of Object.keys(swatches)) swatch(k, null);
for (const k of Object.keys(checks)) setCheck(k, "idle");
why.textContent = "Focused by a pointer: :focus-visible does not match, so no ring is drawn. Press Tab to see it.";
return;
}
const cs = getComputedStyle(el);
const width = cs.outlineStyle === "none" ? 0 : parseFloat(cs.outlineWidth) || 0;
const offset = width ? parseFloat(cs.outlineOffset) || 0 : 0;
// A ring drawn inside the element sits on the element's own background.
const bg = backgroundOf(offset + width <= 0 ? el : el.parentElement);
const ring = width ? parseColor(cs.outlineColor) : null;
const ringC = ring ? contrast(over(ring, bg), bg) : 0;
const halos = halosOf(cs.boxShadow);
const widest = halos.reduce((a, h) => (h.spread > (a ? a.spread : 0) ? h : a), null);
// The halo shows in the gap inside the ring and beyond its outer edge.
const inner = halos.some((h) => h.spread >= offset) ? Math.max(0, offset) : 0;
const outer = widest ? Math.max(0, widest.spread - Math.max(0, offset + width)) : 0;
const haloBand = widest ? inner + outer : 0;
const haloC = widest ? contrast(over(widest.color, bg), bg) : 0;
values.width.textContent = `${+width.toFixed(1)} px`;
values.gap.textContent = width ? `${+offset.toFixed(1)} px` : "–";
values.ring.textContent = ring ? ratio(ringC) : "–";
values.halo.textContent = widest ? ratio(haloC) : "–";
swatch("ring", ring && over(ring, bg), bg);
swatch("halo", widest && over(widest.color, bg), bg);
const drawn = (width > 0 && ringC >= SEEN) || (haloBand > 0 && haloC >= SEEN);
const strong = (width >= 1 && ringC >= MIN) || (haloBand >= 1 && haloC >= MIN);
const appearance = (width >= MIN_BAND && ringC >= MIN) || (haloBand >= MIN_BAND && haloC >= MIN);
const share = shownShare(el);
setCheck("visible", drawn ? "pass" : "fail");
setCheck("contrast", strong ? "pass" : "fail");
setCheck("obscured", share > 0 ? "pass" : "fail");
setCheck("appearance", appearance ? "pass" : "fail");
if (share === 0) why.textContent = "This element is entirely covered: focus slid under the sticky bar.";
else if (!drawn) why.textContent = "No ring: this element has outline: none and nothing in its place.";
else if (!appearance) why.textContent = "A ring is drawn, but it is too thin and too faint to find at a glance.";
else if (share < 1) why.textContent = "Part of this element is covered. That passes 2.4.11 but not 2.4.12, which asks for all of it.";
else if (ringC < MIN) why.textContent = "The ring color alone is too close to this background; the halo carries the contrast.";
else if (haloC < MIN) why.textContent = "The ring carries the contrast here; the halo matches the background, which is fine.";
else why.textContent = "Both bands contrast with this background.";
}
// Measure after the browser has scrolled the element into view, and again
// once a transition on the ring (the shared buttons ease box-shadow) is over.
function soon() {
cancelAnimationFrame(frame);
clearTimeout(settle);
frame = requestAnimationFrame(() => {
frame = requestAnimationFrame(() => {
const el = document.activeElement;
if (!el || !root.contains(el) || el === root) return clear();
measure(el);
settle = setTimeout(() => { if (document.activeElement === el) measure(el); }, 260);
});
});
}
/* The menu tabs: one tab stop, arrow keys inside. */
function select(tab) {
for (const t of tabs) {
const onIt = t === tab;
t.setAttribute("aria-selected", String(onIt));
t.tabIndex = onIt ? 0 : -1;
document.getElementById(t.getAttribute("aria-controls")).hidden = !onIt;
}
}
function onTabKey(event) {
const at = tabs.indexOf(event.target);
if (at === -1) return;
let next = null;
if (event.key === "ArrowRight") next = tabs[(at + 1) % tabs.length];
else if (event.key === "ArrowLeft") next = tabs[(at - 1 + tabs.length) % tabs.length];
else if (event.key === "Home") next = tabs[0];
else if (event.key === "End") next = tabs[tabs.length - 1];
if (!next) return;
event.preventDefault();
select(next);
next.focus();
}
async function share() {
try {
await navigator.clipboard.writeText(location.href.split("#")[0]);
say("Link copied");
} catch {
say("Could not copy the link");
}
}
function onClick(event) {
const t = event.target;
const tab = t.closest("[role=tab]");
if (tab) return select(tab);
const save = t.closest("[data-ap-save]");
if (save) return save.setAttribute("aria-pressed", String(save.getAttribute("aria-pressed") !== "true"));
if (t.closest("[data-ap-share]")) return share();
if (t.closest("[data-ap-book]")) return say("Table request sent. We confirm by SMS within the hour.");
if (t.closest("[data-ap-gift]")) return say("In a real site this opens the gift order form.");
if (t.closest("[data-ap-bills]")) return say("In a real site this downloads your bills as a PDF.");
const link = t.closest("a[href^='#']");
if (link) {
// The demo's pages do not exist here: stay, and say what would happen.
event.preventDefault();
say("In a real site this link opens that page.");
}
}
on(root, "focusin", soon);
on(root, "focusout", soon);
on(root, "click", onClick);
on(root, "keydown", onTabKey);
clear();
return () => {
ac.abort();
cancelAnimationFrame(frame);
clearTimeout(settle);
clearTimeout(sayTimer);
};
}
for (const root of document.querySelectorAll("[data-ap-focus-indicator]")) 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
यह किन मानदंडों को पूरा करता है
वे सफलता मानदंड जिनका यह पैटर्न ध्यान रखता है, और कैसे।
-
2.4.7 फ़ोकस दिखाई देना
स्तर AA
हर लिंक, बटन, फ़ील्ड, टैब, कार्ड और आइकन बटन कीबोर्ड फ़ोकस मिलने पर रिंग दिखाता है; कहीं भी बिना विकल्प के outline: none नहीं लगाया गया।
-
1.4.11 गैर-टेक्स्ट कंट्रास्ट
स्तर AA
रिंग और उसका हेलो दो ऐसे रंग हैं जो एक-दूसरे से अलग दिखते हैं, इसलिए हल्के पेज, गहरी पट्टी और ब्रांड रंग, तीनों पर कम से कम एक पट्टी उभरकर दिखती है; मीटर अनुपात दिखाता है।
-
2.4.11 फ़ोकस अवरुद्ध नहीं (न्यूनतम)
स्तर AA
ऑर्डर सूची में उसकी स्टिकी बार जितना ऊँचा scroll-padding है, इसलिए ब्राउज़र फ़ोकस वाली पंक्ति को बार के नीचे नहीं, उसके ऊपर रोकता है।
-
2.4.12 फ़ोकस अवरुद्ध नहीं (उन्नत)
स्तर AAA
यही scroll-padding फ़ोकस वाली पूरी पंक्ति को नज़र में रखता है, सिर्फ़ उसका एक हिस्सा नहीं।
-
2.4.13 फ़ोकस का रूप
स्तर AAA
रिंग एलिमेंट से 2 px बाहर बनी 3 px की आउटलाइन है, जो 2 px की परिधि से ज़्यादा है, और इसकी किसी एक पट्टी के पिक्सेल बिना फ़ोकस वाली पृष्ठभूमि से कम से कम 3:1 बदलते हैं।
उपयोग
इसे कब इस्तेमाल करें
इसे अपनाएँ
- हर इंटरफ़ेस में: फ़ोकस हो सकने वाले हर एलिमेंट को रिंग चाहिए, और एक साझा स्टाइल सबको एक जैसा रखता है।
- ऐसे कंपोनेंट जो एक से ज़्यादा पृष्ठभूमि पर आते हैं, जैसे कोई बटन जो सफ़ेद कार्ड, गहरी पट्टियों और ब्रांड रंग, सब पर दिखता है।
कुछ और इस्तेमाल करें
- क्लिक पर दिखने की वजह से रिंग हटाना: :focus-visible इस्तेमाल करें, जो पॉइंटर क्लिक पर रिंग वैसे भी नहीं दिखाता।
- सिर्फ़ रंग बदलना, जैसे बटन का थोड़ा गहरा हो जाना: यह रिंग नहीं है, और जो लोग रंगों के हल्के अंतर नहीं पहचान पाते, उनके लिए यह काम नहीं करता।
- रिंग के तौर पर अकेला box-shadow: फ़ोर्स्ड-कलर्स मोड छायाएँ हटा देता है, इसलिए आउटलाइन रखें।
आम विफलताएँ
आमतौर पर यह कहाँ गलत होता है
outline: none, और उसकी जगह कुछ नहीं
हर जगह से आउटलाइन हटाने वाला रीसेट कीबोर्ड उपयोगकर्ताओं को अंदाज़ा लगाने पर छोड़ देता है कि वे कहाँ हैं। ख़राब संस्करण चालू करें और लिंक व बटन से Tab करके गुज़रें: कुछ नहीं दिखता।
ऐसी रिंग जो सिर्फ़ एक पृष्ठभूमि पर काम करे
इंडिगो बैनर पर इंडिगो रिंग दिखती ही नहीं। सतह के रंग का हेलो रिंग को किसी भी भराई से अलग करता है, जैसा ब्रांड पट्टी में दिखता है।
हल्की 1 px की रिंग
हल्के धूसर रंग की बाल जितनी पतली रेखा तकनीकी रूप से बनी तो है, पर लगभग दिखती नहीं, ख़ासकर हाई-रिज़ॉल्यूशन स्क्रीन पर। 2 px या उससे ज़्यादा इस्तेमाल करें, बगल की चीज़ के मुक़ाबले 3:1 पर।
स्टिकी हेडर या फ़ुटर के नीचे फ़ोकस
ब्राउज़र फ़ोकस वाले एलिमेंट को स्क्रॉल करके नज़र में लाता है, पर स्टिकी बार के नीचे से नहीं निकालता। बार जितना ऊँचा scroll-padding इसे ठीक करता है, स्क्रॉल होने वाले पैनल में भी और पेज पर भी।
:focus को स्टाइल करना, फिर उसे हटा देना
:focus पर बनी रिंग माउस क्लिक के बाद भी दिखती है, इसलिए डिज़ाइनर उसे हटा देते हैं। :focus-visible उसे सिर्फ़ कीबोर्ड और टेक्स्ट फ़ील्ड के लिए दिखाता है।
कटी हुई रिंग
पैरेंट पर लगा overflow: hidden एलिमेंट के बाहर बनी रिंग को काट देता है। कंटेनर में रिंग जितनी चौड़ी पैडिंग दें, या रिंग को अंदर की ओर बनाएँ।
नोट्स
इसे बनाना
- रिंग है outline: 3px solid var(--ap-focus) और outline-offset: 2px, साथ में var(--ap-surface) रंग के दो box-shadow हेलो: एक 2 px का गैप भरता है, दूसरा रिंग के 2 px बाहर रहता है। फ़ोर्स्ड-कलर्स मोड में छायाएँ हट जाती हैं, पर आउटलाइन बनी रहती है।
- जिन दो रंगों के बीच कंट्रास्ट C हो, वे किसी भी पृष्ठभूमि पर कम से कम √C की गारंटी देते हैं। इंडिगो और सफ़ेद किसी मध्यम टोन पर सबसे बुरी स्थिति में 2.5:1 देते हैं; लगभग काला और सफ़ेद 4.1:1 देते हैं, इसलिए फ़ोटो पर रिंग के लिए टेक्स्ट का रंग इस्तेमाल करें।
- स्टिकी बार वाले हर स्क्रॉल कंटेनर पर, और साइट हेडर फ़िक्स्ड हो तो html पर, scroll-padding लगाएँ, ताकि फ़ोकस के साथ होने वाला स्क्रॉल बार से पहले ही रुक जाए।
- मीटर कंप्यूटेड स्टाइल पढ़ता है: आउटलाइन की चौड़ाई, ऑफ़सेट और रंग, box-shadow से बना हेलो, और एलिमेंट के पीछे की पहली ठोस पृष्ठभूमि। ढके होने की जाँच वह elementFromPoint से करता है, एलिमेंट पर कई बिंदुओं पर पूछकर कि सबसे ऊपर क्या है।
- डेमो के लिंक #… पर जाते हैं, क्योंकि उनके पेज यहाँ मौजूद नहीं हैं; असली साइट में ये सामान्य लिंक होते हैं।
स्रोत: डब्ल्यूसीएजी 2.2 को समझना: फ़ोकस का रूप · डब्ल्यूसीएजी 2.2 को समझना: फ़ोकस अवरुद्ध नहीं (न्यूनतम) · सीएसएस सेलेक्टर्स लेवल 4: :focus-visible
आगे पढ़ें: सुलभ रंग डिज़ाइन और डब्ल्यूसीएजी कंट्रास्ट
लाइट और डार्क थीम में, डेस्कटॉप और फ़ोन की चौड़ाई पर axe से और कीबोर्ड से जाँचा गया। अभी हर स्क्रीन रीडर और ब्राउज़र जोड़ी के साथ नहीं परखा गया। सुधार बताएँ