सुलभता पैटर्न · बटन और क्रियाएँ
टॉगल बटन
टॉगल बटन aria-pressed वाला एक साधारण बटन है: उसका नाम बताता है कि वह क्या करता है, और दबी हुई स्थिति बताती है कि वह चालू है या नहीं। लेबल कभी नहीं बदलता। स्क्रीन पर स्थिति भराव, सही का निशान और आइकन दिखाते हैं; सहायक तकनीक को यह aria-pressed बताता है।
- डब्ल्यूसीएजी मानदंड
- 6
- कीबोर्ड नियम
- 3
- जाँच का तरीक़ा
- axe, कीबोर्ड और इंस्पेक्टर
लाइव डेमो
आज़माएँ
इसे माउस, कीबोर्ड या स्क्रीन रीडर से इस्तेमाल करें। साथ का इंस्पेक्टर दिखाता है कि आपके इस्तेमाल के दौरान ब्राउज़र सहायक तकनीक को क्या बताता है: फ़ोकस, स्थिति में बदलाव और घोषणाएँ।
जावास्क्रिप्ट के बिना डेमो उतना ही काम करता है जितना उसका एचटीएमएल; इंस्पेक्टर के लिए जावास्क्रिप्ट चाहिए।
कीबोर्ड
जिन कुंजियों पर यह काम करता है
हर क्रिया पॉइंटर के बिना काम करती है।
| कुंजी | यह क्या करती है |
|---|---|
| TabयाShiftTab | बोल्ड, इटैलिक, अंडरलाइन, नोट और सूचनाएँ म्यूट करें के बीच जाता है। |
| EnterयाSpace | फ़ोकस वाले टॉगल को चालू या बंद करता है। नोट तुरंत वह स्टाइल ले लेता है या छोड़ देता है। |
| CtrlBयाCtrlIयाCtrlU | नोट में, टेक्स्ट छोड़े बिना बोल्ड, इटैलिक या अंडरलाइन दबाता है; स्टेटस मैसेज बताता है कि क्या बदला। |
स्क्रीन रीडर
यह क्या घोषित करता है
मार्कअप की भूमिकाओं, नामों और स्थितियों से लिखा गया।
| कब | अपेक्षित घोषणा |
|---|---|
| फ़ोकस बोल्ड पर पहुँचता है | बोल्ड, टॉगल बटन, दबा हुआ नहीं |
| Space उसे दबाता है | दबा हुआ |
| नोट में Ctrl+I दबाया जाता है | इटैलिक चालू |
| फ़ोकस म्यूट बटन पर पहुँचता है | सूचनाएँ म्यूट करें, टॉगल बटन, दबा हुआ नहीं। आवाज़ें और बैनर रुक जाते हैं। संदेश फिर भी आते रहते हैं। |
| Enter उसे दबाता है | दबा हुआ (नाम सूचनाएँ म्यूट करें ही रहता है) |
ये अपेक्षित घोषणाएँ हैं, रिकॉर्डिंग नहीं। स्क्रीन रीडर और ब्राउज़र के हिसाब से शब्द और क्रम बदलते हैं।
कोड
कोड कॉपी करें
वही फ़ाइलें जिन पर यह डेमो चलता है। स्टाइल एक प्रीफ़िक्स के साथ परोसी जाती हैं जो इस साइट की अपनी स्टाइल को डेमो से दूर रखता है; आप जो कॉपी करते हैं वह मूल है।
<div class="ap-toggle-button" data-ap-toggle-button>
<div class="ap-toggle-button__top">
<h3 class="ap-toggle-button__name" id="toggle-button-note-name">Saturday plans</h3>
<p class="ap-toggle-button__meta">Note · Shared with Meera</p>
</div>
<div class="ap-toggle-button__strip" role="group" aria-label="Note style">
<button type="button" class="ap-toggle-button__btn" aria-pressed="false" aria-keyshortcuts="Control+B" data-ap-style="bold">
<svg class="ap-toggle-button__icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M7 5h6a3.5 3.5 0 0 1 0 7H7Z"/><path d="M7 12h7a3.5 3.5 0 0 1 0 7H7Z"/></svg>
<span>Bold</span>
<svg class="ap-toggle-button__tick" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="m6 12.5 4 4 8-9"/></svg>
</button>
<button type="button" class="ap-toggle-button__btn" aria-pressed="false" aria-keyshortcuts="Control+I" data-ap-style="italic">
<svg class="ap-toggle-button__icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M10 5h8M6 19h8M14 5l-4 14"/></svg>
<span>Italic</span>
<svg class="ap-toggle-button__tick" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="m6 12.5 4 4 8-9"/></svg>
</button>
<button type="button" class="ap-toggle-button__btn" aria-pressed="false" aria-keyshortcuts="Control+U" data-ap-style="underline">
<svg class="ap-toggle-button__icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M7 4v7a5 5 0 0 0 10 0V4"/><path d="M5 20h14"/></svg>
<span>Underline</span>
<svg class="ap-toggle-button__tick" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="m6 12.5 4 4 8-9"/></svg>
</button>
</div>
<div class="ap-toggle-button__note" id="toggle-button-note" role="textbox" aria-multiline="true" aria-labelledby="toggle-button-note-name" contenteditable="plaintext-only" spellcheck="false" data-ap-note>Pick up the cake from Lakshmi Bakery before six, and bring candles for Meera's birthday.</div>
<p class="ap-toggle-button__sr" role="status" data-ap-status></p>
<div class="ap-toggle-button__setting">
<div class="ap-toggle-button__copy">
<p class="ap-toggle-button__k">Family group</p>
<p class="ap-toggle-button__hint" id="toggle-button-mute-hint">Sounds and banners pause. Messages still arrive.</p>
</div>
<button type="button" class="ap-toggle-button__btn ap-toggle-button__mute" aria-pressed="false" aria-describedby="toggle-button-mute-hint">
<svg class="ap-toggle-button__icon ap-toggle-button__bell" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M6 16v-5a6 6 0 0 1 12 0v5l1.5 2h-15Z"/><path d="M10 20.5a2 2 0 0 0 4 0"/></svg>
<svg class="ap-toggle-button__icon ap-toggle-button__bell-off" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M8.6 5.6A6 6 0 0 1 18 11v4"/><path d="M6 11v5l-1.5 2H17"/><path d="M10 20.5a2 2 0 0 0 4 0"/><path d="m4 4 16 16"/></svg>
<span>Mute notifications</span>
</button>
</div>
</div>
/* Toggle buttons. Uses the --ap-* design tokens. */
.ap-toggle-button {
container-type: inline-size;
width: min(100%, 560px);
margin-inline: auto;
border: 1px solid var(--ap-border);
border-radius: var(--ap-radius-lg);
background: var(--ap-surface);
box-shadow: var(--ap-shadow-md);
}
.ap-toggle-button__top {
padding: 18px 20px 0;
}
.ap-toggle-button__name {
margin: 0;
color: var(--ap-text);
font-size: 1.0625rem;
font-weight: 650;
line-height: 1.3;
}
.ap-toggle-button__meta {
margin: 2px 0 0;
color: var(--ap-text-3);
font-size: .875rem;
}
.ap-toggle-button__strip {
display: flex;
flex-wrap: wrap;
gap: 8px;
padding: 14px 20px 0;
}
/* The toggle: an outlined button that fills and gains a check when pressed. */
.ap-toggle-button__btn {
position: relative;
display: inline-flex;
align-items: center;
justify-content: center;
gap: 8px;
min-height: var(--ap-target);
padding: 0 14px;
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;
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-toggle-button__strip .ap-toggle-button__btn {
flex: 1 1 0;
}
.ap-toggle-button__btn:hover {
background: var(--ap-surface-2);
}
.ap-toggle-button__btn:focus-visible {
outline: 2px solid var(--ap-focus);
outline-offset: 2px;
}
.ap-toggle-button__btn[aria-pressed="true"] {
border-color: var(--ap-accent);
background: var(--ap-accent-soft);
color: var(--ap-accent-soft-text);
box-shadow: inset 0 0 0 1px var(--ap-accent);
}
.ap-toggle-button__icon {
width: 18px;
height: 18px;
flex-shrink: 0;
fill: none;
stroke: currentColor;
stroke-width: 2.25;
stroke-linecap: round;
stroke-linejoin: round;
}
/* The check: a badge on the corner, so pressing never changes the width. */
.ap-toggle-button__tick {
position: absolute;
top: -7px;
right: -7px;
width: 18px;
height: 18px;
padding: 3px;
border-radius: var(--ap-radius-full);
background: var(--ap-accent);
box-shadow: 0 0 0 2px var(--ap-surface);
fill: none;
stroke: var(--ap-on-accent);
stroke-width: 3;
stroke-linecap: round;
stroke-linejoin: round;
opacity: 0;
transform: scale(.6);
transition: opacity var(--ap-duration) var(--ap-ease), transform var(--ap-duration) var(--ap-ease);
}
.ap-toggle-button__btn[aria-pressed="true"] .ap-toggle-button__tick {
opacity: 1;
transform: none;
}
/* The note the buttons format. */
.ap-toggle-button__note {
min-height: 96px;
margin: 14px 20px 20px;
padding: 12px 14px;
border: 1px solid var(--ap-border-strong);
border-radius: var(--ap-radius-sm);
background: var(--ap-surface);
color: var(--ap-text);
font-size: 1rem;
line-height: 1.6;
white-space: pre-wrap;
overflow-wrap: anywhere;
cursor: text;
}
.ap-toggle-button__note:focus-visible {
outline: 2px solid var(--ap-focus);
outline-offset: 1px;
border-color: var(--ap-focus);
}
.ap-toggle-button__note.is-bold { font-weight: 700; }
.ap-toggle-button__note.is-italic { font-style: italic; }
.ap-toggle-button__note.is-underline {
text-decoration: underline;
text-decoration-thickness: 1.5px;
text-underline-offset: 3px;
}
/* Mute: the same toggle with a label; the bell is crossed out when pressed. */
.ap-toggle-button__setting {
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: space-between;
gap: 12px 16px;
padding: 16px 20px 18px;
border-top: 1px solid var(--ap-border);
background: var(--ap-surface-2);
border-radius: 0 0 var(--ap-radius-lg) var(--ap-radius-lg);
}
.ap-toggle-button__copy {
flex: 1 1 180px;
min-width: 0;
}
.ap-toggle-button__k {
margin: 0;
color: var(--ap-text);
font-weight: 600;
}
.ap-toggle-button__hint {
margin: 2px 0 0;
color: var(--ap-text-3);
font-size: .875rem;
line-height: 1.45;
}
.ap-toggle-button__bell-off,
.ap-toggle-button__mute[aria-pressed="true"] .ap-toggle-button__bell {
display: none;
}
.ap-toggle-button__mute[aria-pressed="true"] .ap-toggle-button__bell-off {
display: block;
}
.ap-toggle-button__sr {
position: absolute;
width: 1px;
height: 1px;
margin: -1px;
padding: 0;
overflow: hidden;
clip-path: inset(50%);
white-space: nowrap;
border: 0;
}
/* Narrow: the three style buttons stay on one row, icon over label. */
@container (max-width: 420px) {
.ap-toggle-button__strip {
gap: 6px;
padding-inline: 16px;
}
.ap-toggle-button__strip .ap-toggle-button__btn {
flex-direction: column;
gap: 2px;
min-height: 56px;
padding: 6px 4px;
font-size: .8125rem;
}
.ap-toggle-button__top { padding-inline: 16px; }
.ap-toggle-button__note { margin-inline: 16px; }
.ap-toggle-button__setting { padding-inline: 16px; }
}
@media (prefers-reduced-motion: reduce) {
.ap-toggle-button__btn,
.ap-toggle-button__tick { transition: none; }
}
/**
* Toggle buttons: buttons with aria-pressed whose label never changes.
*
* Markup: [data-ap-toggle-button] holding buttons with aria-pressed. A button
* with data-ap-style="bold|italic|underline" also sets class is-<style> on
* the [data-ap-note] text box, and Ctrl+B / Ctrl+I / Ctrl+U (or Cmd on a
* Mac) press it from anywhere in the root. A visually hidden role=status
* [data-ap-status] reports what a shortcut changed.
*/
const KEYS = { b: "bold", i: "italic", u: "underline" };
const SAYS = {
bold: ["Bold on", "Bold off"],
italic: ["Italic on", "Italic off"],
underline: ["Underline on", "Underline off"],
};
export function init(root) {
const note = root.querySelector("[data-ap-note]");
const status = root.querySelector("[data-ap-status]");
let sayTimer = 0;
function toggle(button) {
const on = button.getAttribute("aria-pressed") !== "true";
button.setAttribute("aria-pressed", String(on));
const style = button.dataset.apStyle;
if (style && note) note.classList.toggle(`is-${style}`, on);
return on;
}
function onClick(event) {
const button = event.target.closest("button[aria-pressed]");
if (button && root.contains(button)) toggle(button);
}
function onKeydown(event) {
if (!(event.ctrlKey || event.metaKey) || event.altKey || event.shiftKey) return;
const style = KEYS[event.key.toLowerCase()];
const button = style && root.querySelector(`[data-ap-style="${style}"]`);
if (!button) return;
// Ours, not the browser's (Ctrl+U is "view source" in some browsers).
event.preventDefault();
const on = toggle(button);
// Focus is elsewhere, so the button's own state change goes unheard.
status.textContent = "";
clearTimeout(sayTimer);
sayTimer = setTimeout(() => { status.textContent = SAYS[style][on ? 0 : 1]; }, 60);
}
root.addEventListener("click", onClick);
root.addEventListener("keydown", onKeydown);
return () => {
clearTimeout(sayTimer);
root.removeEventListener("click", onClick);
root.removeEventListener("keydown", onKeydown);
};
}
for (const root of document.querySelectorAll("[data-ap-toggle-button]")) 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.4.1 रंग का उपयोग
स्तर A
दबा हुआ बटन अपना भराव बदलता है, उस पर सही का निशान और किनारा आता है, और म्यूट की घंटी कट जाती है, इसलिए स्थिति कभी सिर्फ़ रंग पर निर्भर नहीं होती।
-
1.4.11 गैर-टेक्स्ट कंट्रास्ट
स्तर AA
हर बटन का किनारा कार्ड के मुक़ाबले 3:1 पार करता है, और दबे हुए बटन का किनारा एक्सेंट रंग में है, जो भी 3:1 पार करता है।
-
2.1.1 कीबोर्ड
स्तर A
हर टॉगल Enter और Space से चलता है, और फ़ॉर्मैटिंग शॉर्टकट नोट के अंदर से काम करते हैं।
-
2.4.7 फ़ोकस दिखाई देना
स्तर AA
हर बटन दो पिक्सेल की फ़ोकस रिंग दिखाता है, और नोट में टाइप करते समय नोट भी दिखाता है।
-
4.1.2 नाम, भूमिका, मान
स्तर A
aria-pressed हर बटन को उसकी स्थिति के साथ टॉगल के रूप में बताता है; नाम कभी नहीं बदलते, इसलिए स्थिति कभी दो बार नहीं कही जाती।
-
4.1.3 स्टेटस मैसेज
स्तर AA
शॉर्टकट उस बटन को बदलता है जिस पर फ़ोकस नहीं है, इसलिए स्टेटस मैसेज "बोल्ड चालू" या "बोल्ड बंद" कहता है।
उपयोग
इसे कब इस्तेमाल करें
इसे अपनाएँ
- टूल की वे स्थितियाँ जो बंद किए जाने तक चालू रहती हैं, जैसे बोल्ड टेक्स्ट, ग्रिड ओवरले या म्यूट।
- स्वतंत्र विकल्पों की एक पंक्ति, जिसमें एक साथ कितने भी चालू हो सकते हैं।
कुछ और इस्तेमाल करें
- सेटिंग की सूची में लाइट के स्विच की तरह असर करने वाली सेटिंग: वहाँ स्विच ज़्यादा स्वाभाविक लगता है।
- कई में से एक विकल्प चुनना, जैसे टेक्स्ट का संरेखण: रेडियो ग्रुप या सेगमेंटेड कंट्रोल इस्तेमाल करें।
- कुछ खोलने या दिखाने वाला बटन: aria-pressed नहीं, aria-expanded इस्तेमाल करें।
आम विफलताएँ
आमतौर पर यह कहाँ गलत होता है
स्थिति की जगह बदलता लेबल
जो बटन बिना दबी हुई स्थिति के पहले "म्यूट" और फिर "अनम्यूट" पढ़ा जाए, वह लोगों को अंदाज़ा लगाने पर छोड़ देता है कि लेबल स्थिति है या काम। एक ही लेबल रखें और चालू या बंद aria-pressed को बताने दें।
बदलता लेबल और aria-pressed एक साथ
"अनम्यूट, टॉगल बटन, दबा हुआ" एक पहेली है। एक तरीका चुनें: aria-pressed के साथ स्थिर लेबल, जैसा यहाँ है, या बिना दबी हुई स्थिति के बदलता लेबल।
दबी हुई स्थिति सिर्फ़ थोड़े गहरे भराव से
रंग की हल्की-सी बदलाहट कई लोगों को दिखती ही नहीं। यहाँ दबे हुए बटनों पर सही का निशान और गहरा किनारा भी आता है, और म्यूट का आइकन बदल जाता है।
स्थिति के लिए क्लास वाला सजा हुआ div
"active" क्लास बदलने वाला div सहायक तकनीक को कुछ नहीं बताता। aria-pressed वाले बटन की घोषणा उसकी स्थिति के साथ टॉगल बटन के रूप में होती है।
चुपचाप बदलाव करने वाले शॉर्टकट
नोट में Ctrl+B उस बटन को दबाता है जिस पर फ़ोकस नहीं है, इसलिए अपने आप किसी बात की घोषणा नहीं होती। यहाँ स्टेटस मैसेज बताता है कि क्या बदला।
नोट्स
इसे बनाना
- aria-pressed "true" या "false" लेता है, या "mixed" जब कोई स्टाइल चुने गए हिस्से के सिर्फ़ एक भाग पर हो। एट्रिब्यूट पूरी तरह हटा दें, तो बटन एक साधारण बटन रह जाता है।
- पूरे एडिटर में दबी हुई स्थिति कर्सर के नीचे के टेक्स्ट के हिसाब से बदलती है, और यह पट्टी एक टैब स्टॉप वाले टूलबार में होनी चाहिए; टूलबार पैटर्न देखें।
- नोट contenteditable="plaintext-only" इस्तेमाल करता है, इसलिए पेस्ट करने से ऐसी फ़ॉर्मैटिंग नहीं आ सकती जिसके बारे में बटन नहीं जानते।
- म्यूट उतनी ही अच्छी तरह एक स्विच भी हो सकता है। टूल की स्थितियों के लिए टॉगल बटन और सेटिंग के लिए स्विच इस्तेमाल करें, और एक प्रोडक्ट में एक जैसा रहें।
स्रोत: WAI-एआरआईए ऑथरिंग प्रैक्टिसेज़: बटन · WAI-एआरआईए 1.2: aria-pressed एट्रिब्यूट
लाइट और डार्क थीम में, डेस्कटॉप और फ़ोन की चौड़ाई पर axe से और कीबोर्ड से जाँचा गया। अभी हर स्क्रीन रीडर और ब्राउज़र जोड़ी के साथ नहीं परखा गया। सुधार बताएँ