सुलभता पैटर्न · फ़ॉर्म इनपुट
टाइम पिकर
ज़्यादातर लोग कुछ गिने-चुने समयों में से एक चाहते हैं, इसलिए सुझाव एक नेटिव रेडियो ग्रुप हैं: एक Tab स्टॉप, चुनने के लिए ऐरो कुंजियाँ, और निष्क्रिय समय छोड़ दिए जाते हैं, उनका कारण बगल में लिखा रहता है। बाक़ी हर समय के लिए नेटिव टाइम फ़ील्ड है; स्क्रिप्ट उसे खुलने के घंटों, पंद्रह मिनट के अंतराल और बुक हो चुके स्लॉट से जाँचती है, और एक स्टेटस मैसेज बुकिंग की पुष्टि करता है।
- डब्ल्यूसीएजी मानदंड
- 7
- कीबोर्ड नियम
- 6
- जाँच का तरीक़ा
- axe, कीबोर्ड और इंस्पेक्टर
लाइव डेमो
आज़माएँ
इसे माउस, कीबोर्ड या स्क्रीन रीडर से इस्तेमाल करें। साथ का इंस्पेक्टर दिखाता है कि आपके इस्तेमाल के दौरान ब्राउज़र सहायक तकनीक को क्या बताता है: फ़ोकस, स्थिति में बदलाव और घोषणाएँ।
जावास्क्रिप्ट के बिना डेमो उतना ही काम करता है जितना उसका एचटीएमएल; इंस्पेक्टर के लिए जावास्क्रिप्ट चाहिए।
कीबोर्ड
जिन कुंजियों पर यह काम करता है
हर क्रिया पॉइंटर के बिना काम करती है।
| कुंजी | यह क्या करती है |
|---|---|
| Tab | सुझाए गए समयों में जाता है (चुने गए पर, या पहले ख़ाली पर), फिर टाइम फ़ील्ड और बटन पर। |
| Arrow DownयाArrow Right | अगला ख़ाली समय चुनता है, लिए जा चुके समय छोड़ते हुए और आख़िर में घूमकर शुरू पर आते हुए। |
| Arrow UpयाArrow Left | पिछला ख़ाली समय चुनता है। |
| Space | जब अभी कुछ न चुना हो, तब फ़ोकस वाला समय चुनता है। |
| Arrow UpयाArrow Down | टाइम फ़ील्ड में, फ़ोकस वाला घंटा, मिनट या am/pm हिस्सा बदलता है। |
| Enter | बुकिंग पक्की करता है, या बताता है कि क्या छूटा है और फ़ोकस वहाँ ले जाता है। |
स्क्रीन रीडर
यह क्या घोषित करता है
मार्कअप की भूमिकाओं, नामों और स्थितियों से लिखा गया।
| कब | अपेक्षित घोषणा |
|---|---|
| Tab सुझाए गए समयों तक पहुँचता है | सुझाए गए समय, समूह। 09:00, रेडियो बटन, चुना नहीं गया |
| 09:00 से नीचे का ऐरो | 11:00, रेडियो बटन, चुना हुआ (10:00 लिया जा चुका है, इसलिए छूट जाता है) |
| ब्राउज़ मोड में लिया जा चुका समय पढ़ना | 10:00 बुक है, रेडियो बटन, अनुपलब्ध |
| बुकिंग पक्की होती है | कल के लिए बुक हुआ, समय: 11:00 |
| टाइम फ़ील्ड में Enter, ऐसे समय पर जो किसी बुकिंग से टकराता है | वह समय एक बुक हो चुके स्लॉट से टकराता है। कोई और चुनें। |
ये अपेक्षित घोषणाएँ हैं, रिकॉर्डिंग नहीं। स्क्रीन रीडर और ब्राउज़र के हिसाब से शब्द और क्रम बदलते हैं।
कोड
कोड कॉपी करें
वही फ़ाइलें जिन पर यह डेमो चलता है। स्टाइल एक प्रीफ़िक्स के साथ परोसी जाती हैं जो इस साइट की अपनी स्टाइल को डेमो से दूर रखता है; आप जो कॉपी करते हैं वह मूल है।
<form class="ap-time-picker" data-ap-time-picker data-region="IN" novalidate>
<div class="ap-time-picker__intro">
<span class="ap-time-picker__avatar" aria-hidden="true">KM</span>
<div>
<h3 class="ap-time-picker__who">Video call with Dr Kavya Menon</h3>
<p class="ap-time-picker__meta">Tomorrow · 30 minutes · times in IST</p>
</div>
</div>
<fieldset class="ap-time-picker__set" aria-describedby="time-picker-slot-error">
<legend class="ap-time-picker__legend">Suggested times</legend>
<p class="ap-hint">Times that are taken say why, and cannot be chosen.</p>
<p class="ap-error ap-time-picker__error" id="time-picker-slot-error" aria-live="polite"><svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><circle cx="12" cy="12" r="9"/><path d="M12 7.5v5.5M12 16.5h.01"/></svg><span data-ap-slot-error></span></p>
<div class="ap-time-picker__grid">
<label class="ap-time-picker__slot">
<input type="radio" name="time-picker-slot" value="09:00" />
<span class="ap-time-picker__time" data-ap-time="09:00">09:00</span>
<svg class="ap-time-picker__tick" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="m6 12.5 4 4 8-9"/></svg>
</label>
<label class="ap-time-picker__slot">
<input type="radio" name="time-picker-slot" value="10:00" disabled data-minutes="30" />
<span class="ap-time-picker__time" data-ap-time="10:00">10:00</span>
<span class="ap-time-picker__why">Booked</span>
</label>
<label class="ap-time-picker__slot">
<input type="radio" name="time-picker-slot" value="11:00" />
<span class="ap-time-picker__time" data-ap-time="11:00">11:00</span>
<svg class="ap-time-picker__tick" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="m6 12.5 4 4 8-9"/></svg>
</label>
<label class="ap-time-picker__slot">
<input type="radio" name="time-picker-slot" value="12:00" />
<span class="ap-time-picker__time" data-ap-time="12:00">12:00</span>
<svg class="ap-time-picker__tick" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="m6 12.5 4 4 8-9"/></svg>
</label>
<label class="ap-time-picker__slot">
<input type="radio" name="time-picker-slot" value="13:00" disabled data-minutes="60" />
<span class="ap-time-picker__time" data-ap-time="13:00">13:00</span>
<span class="ap-time-picker__why">Lunch break</span>
</label>
<label class="ap-time-picker__slot">
<input type="radio" name="time-picker-slot" value="14:00" />
<span class="ap-time-picker__time" data-ap-time="14:00">14:00</span>
<svg class="ap-time-picker__tick" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="m6 12.5 4 4 8-9"/></svg>
</label>
<label class="ap-time-picker__slot">
<input type="radio" name="time-picker-slot" value="15:00" />
<span class="ap-time-picker__time" data-ap-time="15:00">15:00</span>
<svg class="ap-time-picker__tick" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="m6 12.5 4 4 8-9"/></svg>
</label>
<label class="ap-time-picker__slot">
<input type="radio" name="time-picker-slot" value="16:00" disabled data-minutes="30" />
<span class="ap-time-picker__time" data-ap-time="16:00">16:00</span>
<span class="ap-time-picker__why">Booked</span>
</label>
<label class="ap-time-picker__slot">
<input type="radio" name="time-picker-slot" value="17:00" />
<span class="ap-time-picker__time" data-ap-time="17:00">17:00</span>
<svg class="ap-time-picker__tick" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="m6 12.5 4 4 8-9"/></svg>
</label>
<label class="ap-time-picker__slot">
<input type="radio" name="time-picker-slot" value="18:00" />
<span class="ap-time-picker__time" data-ap-time="18:00">18:00</span>
<svg class="ap-time-picker__tick" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="m6 12.5 4 4 8-9"/></svg>
</label>
</div>
</fieldset>
<div class="ap-field ap-time-picker__other">
<label class="ap-label" for="time-picker-other">Another time</label>
<p class="ap-hint" id="time-picker-other-hint" data-ap-hint>Between 09:00 and 18:00, on the quarter hour.</p>
<input class="ap-input ap-time-picker__input" id="time-picker-other" type="time" min="09:00" max="18:00" step="900" aria-describedby="time-picker-other-hint time-picker-other-error" />
<p class="ap-error ap-time-picker__error" id="time-picker-other-error" aria-live="polite"><svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><circle cx="12" cy="12" r="9"/><path d="M12 7.5v5.5M12 16.5h.01"/></svg><span data-ap-other-error></span></p>
</div>
<button type="submit" class="ap-btn ap-btn--primary ap-time-picker__go">Confirm time</button>
<p class="ap-time-picker__done" role="status"><svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><circle cx="12" cy="12" r="9"/><path d="m8 12.5 3 3 5-6"/></svg><span data-ap-done></span></p>
</form>
/* 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; }
}
/* Time picker. Uses the --ap-* design tokens and the shared primitives. */
.ap-time-picker {
container-type: inline-size;
display: grid;
gap: 22px;
width: min(100%, 540px);
margin-inline: auto;
padding: 22px 24px 24px;
border: 1px solid var(--ap-border);
border-radius: var(--ap-radius-lg);
background: var(--ap-surface);
color: var(--ap-text);
box-shadow: var(--ap-shadow-md);
font-family: var(--ap-font);
}
/* Who the call is with */
.ap-time-picker__intro {
display: flex;
align-items: center;
gap: 14px;
padding-bottom: 18px;
border-bottom: 1px solid var(--ap-border);
}
.ap-time-picker__avatar {
display: grid;
place-items: center;
width: 44px;
height: 44px;
flex-shrink: 0;
border-radius: var(--ap-radius-full);
background: var(--ap-accent-soft);
color: var(--ap-accent-soft-text);
font-size: .875rem;
font-weight: 700;
letter-spacing: .02em;
}
.ap-time-picker__who {
margin: 0;
font-family: var(--ap-font);
font-size: 1rem;
font-weight: 650;
line-height: 1.35;
}
.ap-time-picker__meta {
margin: 2px 0 0;
color: var(--ap-text-3);
font-size: .875rem;
}
/* The suggested times */
.ap-time-picker__set {
display: grid;
gap: 6px;
min-width: 0;
margin: 0;
padding: 0;
border: 0;
}
.ap-time-picker__legend {
margin-bottom: 6px;
padding: 0;
color: var(--ap-text);
font-size: .9375rem;
font-weight: 650;
}
.ap-time-picker__grid {
display: grid;
grid-template-columns: repeat(5, minmax(0, 1fr));
gap: 8px;
margin-top: 6px;
}
@container (max-width: 470px) {
.ap-time-picker { padding: 18px 16px 20px; }
.ap-time-picker__grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
.ap-time-picker__slot {
position: relative;
display: grid;
place-content: center;
justify-items: center;
gap: 1px;
min-height: 52px;
padding: 6px 4px;
border: 1px solid var(--ap-border-strong);
border-radius: var(--ap-radius-sm);
background: var(--ap-surface);
color: var(--ap-text);
text-align: center;
cursor: pointer;
transition: background-color var(--ap-duration) var(--ap-ease), border-color var(--ap-duration) var(--ap-ease);
}
/* The real radio covers the card: it takes the clicks and the focus. */
.ap-time-picker__slot input {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
margin: 0;
opacity: 0;
cursor: inherit;
}
.ap-time-picker__slot:hover {
background: var(--ap-surface-2);
}
.ap-time-picker__slot:has(input:focus-visible) {
outline: 2px solid var(--ap-focus);
outline-offset: 2px;
}
.ap-time-picker__time {
font-size: .9375rem;
font-weight: 550;
font-variant-numeric: tabular-nums;
white-space: nowrap;
}
.ap-time-picker__tick {
position: absolute;
top: 4px;
right: 4px;
width: 16px;
height: 16px;
padding: 2px;
border-radius: var(--ap-radius-full);
background: var(--ap-accent);
fill: none;
stroke: var(--ap-on-accent);
stroke-width: 3.5;
stroke-linecap: round;
stroke-linejoin: round;
visibility: hidden;
}
/* Chosen: thicker accent border, soft fill, bold type and a tick */
.ap-time-picker__slot:has(input:checked) {
border-color: var(--ap-accent);
background: var(--ap-accent-soft);
box-shadow: inset 0 0 0 1px var(--ap-accent);
color: var(--ap-accent-soft-text);
}
.ap-time-picker__slot:has(input:checked) .ap-time-picker__time {
font-weight: 750;
}
.ap-time-picker__slot:has(input:checked) .ap-time-picker__tick {
visibility: visible;
}
/* Taken: dashed edge, struck-through time, the reason in words */
.ap-time-picker__slot:has(input:disabled) {
border-style: dashed;
background: var(--ap-surface-2);
color: var(--ap-text-3);
cursor: not-allowed;
}
.ap-time-picker__slot:has(input:disabled) .ap-time-picker__time {
text-decoration: line-through;
}
.ap-time-picker__why {
color: var(--ap-text-3);
font-size: .75rem;
font-weight: 600;
line-height: 1.25;
}
/* Another time */
.ap-time-picker__input {
width: min(100%, 12rem);
font-variant-numeric: tabular-nums;
}
.ap-time-picker__input::-webkit-calendar-picker-indicator {
cursor: pointer;
}
/* Errors are live regions: they stay in the page, taking no room until they have words. */
.ap-time-picker__error svg {
width: 18px;
height: 18px;
flex-shrink: 0;
margin-top: 1px;
fill: none;
stroke: currentColor;
stroke-width: 2;
stroke-linecap: round;
}
.ap-time-picker__error:has(> span:empty) {
margin-top: -6px;
}
.ap-time-picker__error:has(> span:empty) svg {
display: none;
}
.ap-time-picker__go {
justify-self: start;
min-height: var(--ap-target);
padding: 0 22px;
}
.ap-time-picker__done {
display: flex;
align-items: center;
gap: 10px;
margin: -6px 0 0;
padding: 12px 14px;
border-radius: var(--ap-radius-sm);
background: var(--ap-success-soft);
color: var(--ap-success);
font-weight: 600;
line-height: 1.4;
}
/* The status stays in the page while empty, so its first message is heard. */
.ap-time-picker__done:has(> span:empty) {
margin-top: -22px;
padding: 0;
background: transparent;
}
.ap-time-picker__done:has(> span:empty) svg {
display: none;
}
.ap-time-picker__done svg {
width: 20px;
height: 20px;
flex-shrink: 0;
fill: none;
stroke: currentColor;
stroke-width: 2;
stroke-linecap: round;
stroke-linejoin: round;
}
.ap-time-picker__done strong {
font-weight: 750;
}
@media (prefers-reduced-motion: reduce) {
.ap-time-picker__slot { transition: none; }
}
/**
* Time picker: suggested times as a native radio group (taken ones disabled,
* with the reason in their label), a native input type=time for any other
* time, and a status message that confirms the booking.
*
* Markup: form[data-ap-time-picker][novalidate] holding radios (value HH:MM;
* disabled ones carry data-minutes, the time they block) with a
* [data-ap-time] element each, a fieldset error [data-ap-slot-error], an
* input[type=time] with min, max and step, its hint [data-ap-hint] and error
* [data-ap-other-error], a submit button, and p[role=status] > [data-ap-done].
* Add data-12h to the root to write times on a 12-hour clock.
*/
const SLOT_MINUTES = 30;
const TEXT = {
none: "Choose a suggested time or enter one.",
bad: "Enter a full time, with hours and minutes.",
taken: "That time overlaps a booked slot. Choose another.",
range: { 24: "Choose a time between 09:00 and 18:00.", 12: "Choose a time between 9:00 am and 6:00 pm." },
step: { 24: "Use a time on the quarter hour, like 14:15.", 12: "Use a time on the quarter hour, like 2:15 pm." },
hint: { 24: "Between 09:00 and 18:00, on the quarter hour.", 12: "Between 9:00 am and 6:00 pm, on the quarter hour." },
done: "Booked for tomorrow at",
};
const minutesOf = (hhmm) => {
const [h, m] = hhmm.split(":").map(Number);
return h * 60 + m;
};
export function init(root) {
const radios = [...root.querySelectorAll("input[type=radio]")];
const other = root.querySelector("input[type=time]");
const hint = root.querySelector("[data-ap-hint]");
const slotError = root.querySelector("[data-ap-slot-error]");
const otherError = root.querySelector("[data-ap-other-error]");
const done = root.querySelector("[data-ap-done]");
const clock = () => (root.hasAttribute("data-12h") ? 12 : 24);
// The times nobody can book, read from the disabled radios.
const taken = radios.filter((r) => r.disabled).map((r) => {
const start = minutesOf(r.value);
return [start, start + Number(r.dataset.minutes || SLOT_MINUTES)];
});
function format(hhmm) {
const [h, m] = hhmm.split(":").map(Number);
const lang = root.closest("[lang]")?.lang || navigator.language;
const region = root.dataset.region;
const locale = region && !lang.includes("-") ? `${lang}-${region}` : lang;
const options = clock() === 12
? { hour: "numeric", minute: "2-digit", hour12: true }
: { hour: "2-digit", minute: "2-digit", hourCycle: "h23" };
try {
return new Intl.DateTimeFormat(locale, options).format(new Date(2000, 0, 1, h, m));
} catch {
return hhmm;
}
}
// Write every time on the chosen clock.
for (const el of root.querySelectorAll("[data-ap-time]")) el.textContent = format(el.dataset.apTime);
hint.textContent = TEXT.hint[clock()];
function setError(target, field, message) {
if (target.textContent !== message) target.textContent = message;
if (!field) return;
if (message) field.setAttribute("aria-invalid", "true");
else field.removeAttribute("aria-invalid");
}
/** What is wrong with the typed time, or "" when it can be booked. */
function checkOther() {
const v = other.validity;
if (v.badInput) return TEXT.bad;
if (v.rangeUnderflow || v.rangeOverflow) return TEXT.range[clock()];
if (v.stepMismatch) return TEXT.step[clock()];
const start = minutesOf(other.value);
const end = start + SLOT_MINUTES;
if (taken.some(([a, b]) => start < b && end > a)) return TEXT.taken;
return "";
}
function confirm(hhmm) {
const time = document.createElement("strong");
time.textContent = format(hhmm);
const words = document.createElement("span");
words.textContent = TEXT.done;
done.replaceChildren(words, " ", time);
}
function onSubmit(event) {
event.preventDefault();
setError(slotError, null, "");
const typed = other.value || other.validity.badInput;
if (typed) {
const problem = checkOther();
setError(otherError, other, problem);
if (problem) {
done.replaceChildren();
other.focus();
return;
}
confirm(other.value);
return;
}
setError(otherError, other, "");
const chosen = radios.find((r) => r.checked);
if (!chosen) {
done.replaceChildren();
setError(slotError, null, TEXT.none);
radios.find((r) => !r.disabled)?.focus();
return;
}
confirm(chosen.value);
}
// A suggested time and a typed one cannot both stand: choosing one clears the other.
function onChange(event) {
const el = event.target;
if (el.type === "radio" && el.checked) {
other.value = "";
setError(otherError, other, "");
setError(slotError, null, "");
done.replaceChildren();
}
}
function onInput(event) {
if (event.target !== other) return;
if (other.value) for (const r of radios) r.checked = false;
setError(slotError, null, "");
done.replaceChildren();
// An error already showing is updated as the time is fixed, never added while typing.
if (otherError.textContent) setError(otherError, other, other.value ? checkOther() : "");
}
root.addEventListener("submit", onSubmit);
root.addEventListener("change", onChange);
root.addEventListener("input", onInput);
return () => {
root.removeEventListener("submit", onSubmit);
root.removeEventListener("change", onChange);
root.removeEventListener("input", onInput);
};
}
for (const root of document.querySelectorAll("[data-ap-time-picker]")) 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
समय legend वाले fieldset में हैं, और हर कारण अपने समय के लेबल का हिस्सा है, इसलिए समूह और कारण दोनों कोड में हैं।
-
1.4.1 रंग का उपयोग
स्तर A
चुने गए समय पर सही का निशान, मोटी किनारी और मोटे अक्षर हैं; लिए जा चुके समयों पर रेखा खिंची है और वे शब्दों में कारण बताते हैं।
-
2.1.1 कीबोर्ड
स्तर A
नेटिव रेडियो बटन और नेटिव टाइम फ़ील्ड: हर हिस्सा बिना अतिरिक्त कोड के कीबोर्ड से चलता है।
-
2.5.8 टारगेट साइज़ (न्यूनतम)
स्तर AA
हर समय कम से कम 44 पिक्सेल ऊँचा पूरा कार्ड है, इसलिए उँगली से छूना आसान है।
-
3.3.1 त्रुटि पहचान
स्तर A
खुलने के घंटों से बाहर का, पंद्रह मिनट के अंतराल से हटकर, या बुक हो चुके स्लॉट पर पड़ने वाला समय टेक्स्ट में बताया जाता है, और फ़ील्ड अमान्य चिह्नित होता है।
-
3.3.2 लेबल या निर्देश
स्तर A
legend, लेबल और संकेत पहले ही बता देते हैं कि क्या चुना जा सकता है, किसी के ग़लती करने से पहले।
-
4.1.3 स्टेटस मैसेज
स्तर AA
पुष्टि और हर त्रुटि polite लाइव संदेश हैं, इसलिए फ़ील्ड में Enter दबाने का जवाब मिलता है, भले ही फ़ोकस अपनी जगह रहे।
उपयोग
इसे कब इस्तेमाल करें
इसे अपनाएँ
- समयों की छोटी सूची से बुकिंग, जैसे अपॉइंटमेंट, डिलीवरी या टेबल रिज़र्वेशन।
- जब ज़्यादातर लोग सुझाया गया समय लेते हैं पर कुछ को कोई और चाहिए।
कुछ और इस्तेमाल करें
- दिन का कोई भी समय, बिना नियमों के: अकेला नेटिव टाइम फ़ील्ड काफ़ी है।
- कई दिनों में फैली स्लॉट की लंबी सूचियाँ: पहले दिन चुनें, फिर उसके समय दिखाएँ।
- अवधि, जैसे 90 मिनट का टाइमर: घंटों और मिनटों के लिए नंबर फ़ील्ड इस्तेमाल करें।
आम विफलताएँ
आमतौर पर यह कहाँ गलत होता है
लिए जा चुके समय जो ग़ायब हो जाते हैं
बुक हो चुके समय हटाने से ऐसे ख़ाली स्थान बचते हैं जिन्हें कोई समझ नहीं पाता। यहाँ वे अपनी जगह रहते हैं, निष्क्रिय, और कारण समय के नीचे लिखा रहता है।
कारण जो सिर्फ़ होवर पर दिखता है
निष्क्रिय कंट्रोल पर टूलटिप तक कीबोर्ड या टच से नहीं पहुँचा जा सकता। यहाँ कारण लेबल के अंदर सादा टेक्स्ट है।
बटनों की कतार के रूप में समय
बटन नहीं बताते कि कौन सा चुना गया है या कुल कितने हैं। fieldset में रेडियो बटन दोनों बताते हैं, और ऐरो कुंजियाँ मुफ़्त में मिलती हैं।
कस्टम घड़ी का डायल
डायल पिकर में खींचना और सटीक निशाना लगाना पड़ता है। नेटिव टाइम फ़ील्ड पहले से कीबोर्ड, स्क्रीन रीडर और हर फ़ोन के अपने पिकर के साथ चलता है।
त्रुटियाँ जो सिर्फ़ "अमान्य समय" कहती हैं
लोगों को जानना होता है कि क्या बदलें। हर संदेश नियम का नाम लेता है: खुलने के घंटे, पंद्रह मिनट का अंतराल, या किसी बुकिंग से टकराव।
कोई पुष्टि नहीं
पक्का करें दबाकर कुछ न सुनना लोगों को असमंजस में छोड़ देता है। एक स्टेटस मैसेज बुक हुआ समय दोहराता है।
नोट्स
इसे बनाना
- नेटिव टाइम फ़ील्ड ब्राउज़र की अपनी सेटिंग के हिसाब से 12 या 24 घंटे दिखाता है; उसका मान हमेशा 24-घंटे का HH:MM होता है, इसलिए वही जाँचें, स्क्रीन पर दिखा टेक्स्ट कभी नहीं।
- ऊपर का 12-घंटे वाला विकल्प बदलता है कि स्क्रिप्ट समय कैसे लिखती है (Intl.DateTimeFormat से); रेडियो के मान और नियम 24-घंटे के समय में ही रहते हैं।
- निष्क्रिय रेडियो बटन ऐरो कुंजियों और Tab से छूट जाते हैं, इसलिए कारण फ़ोकस के बाहर भी होना चाहिए: समयों के ऊपर का संकेत बताता है कि लिए जा चुके समय अपना कारण ख़ुद बताते हैं।
- बुक हो चुके स्लॉट निष्क्रिय रेडियो और उनके data-minutes से पढ़े जाते हैं, इसलिए फ़ील्ड की टकराव जाँच और कार्ड कभी असहमत नहीं हो सकते।
- फ़ॉर्म पर novalidate है: ब्राउज़र के अपने बुलबुलों की जगह aria-describedby से हर फ़ील्ड से जुड़े संदेश आते हैं।
स्रोत: WAI-एआरआईए ऑथरिंग प्रैक्टिसेज़: रेडियो ग्रुप · MDN: टाइम इनपुट (input type="time")
लाइट और डार्क थीम में, डेस्कटॉप और फ़ोन की चौड़ाई पर axe से और कीबोर्ड से जाँचा गया। अभी हर स्क्रीन रीडर और ब्राउज़र जोड़ी के साथ नहीं परखा गया। सुधार बताएँ