跳到正文
cccskills
免费在 GitHub 公开

date-input

Use when implementing enter dates in a structured text format.

中文简介正在准备中。当前显示原文说明。

查看安装方法

包含的文件(2)

  • SKILL.md5.5 KB
  • references/pattern.md22.5 KB

SKILL.md(原文)

安装前可以查看交给 AI 代理的指令内容。

Date Input

Enter dates in a structured text format

What it solves

A Date Input is a form field specifically designed for entering date values. It encompasses two primary implementation approaches: the native <input type="date"> control (which renders the browser's built-in date picker), and structured text inputs using masked or segmented fields (e.g., MM/DD/YYYY format with auto-advance between day, month, and year segments). Date Input is distinct from a Date Picker in that it focuses on direct keyboard entry of a date value rather than calendar-based visual selection. It is the preferred approach for entering known dates (birth dates, expiry dates) where a calendar view adds unnecessary complexity.

When to use

  • Known, precise dates – Birth dates, passport expiry dates, credit card expiry.
  • Historical dates – Events or records well in the past where calendar navigation would be tedious.
  • Age or duration entry – When users know the exact date without needing visual calendar context.
  • High-frequency data entry – Forms where users enter many dates quickly benefit from direct text entry.
  • Date of birth – Users always know this value; no calendar navigation needed.

When to avoid

  • Scheduling and appointments – Use a Date Picker to show availability and context.
  • Relative date selection – "Next Monday", "In 3 weeks" — use natural language or a date picker.
  • Date ranges – Use a Date Range component instead.
  • When users need to see surrounding dates – Calendar view is more helpful.

Implementation workflow

  1. Confirm the pattern matches the problem and constraints before copying the example.
  2. Start from the anatomy and examples in references/pattern.md, then choose the smallest viable variation.
  3. Apply accessibility, performance, and interaction guardrails before layering visual polish.
  4. Use the testing guidance to verify behavior across keyboard, screen reader, responsive, and failure scenarios.

Accessibility guardrails

Keyboard Interaction Pattern

KeyAction
TabMoves focus to the date input or next segment
Shift + TabMoves focus to the previous input or segment
0–9Enters numeric digits in native input or current segment
Arrow Up / DownIncrements / decrements date value in native date input
Arrow Left / RightMoves between date parts in native input; navigates segments manually
BackspaceClears current segment value; moves to previous segment if empty
DeleteClears current segment without moving focus

Performance guardrails

  • Initial render: < 50ms for date input
  • Segment auto-advance: < 16ms (single frame)
  • Date validation: < 5ms for assembled date
  • Error display: < 150ms after blur
  • Memory usage: < 3KB per date input instance

Common mistakes

Undefined Date Format

The Problem: Providing an input without indicating expected format causes user errors, especially in international contexts.

<!-- Bad: No format hint -->
<label for="dob">Date of birth</label>
<input type="text" id="dob" placeholder="Enter date" />

How to Fix It? Always specify format in label or helper text.

<!-- Good -->
<label for="dob">Date of birth (MM/DD/YYYY)</label>
<input type="text" id="dob" inputmode="numeric" placeholder="MM/DD/YYYY" aria-describedby="dob-help" />
<p id="dob-help">Example: 01/15/1990</p>

Validating Segments Independently Without Cross-Validation

The Problem: Checking only that day ≤ 31, month ≤ 12, and year is 4 digits misses invalid dates like February 30 or April 31.

How to Fix It? Always validate the assembled date as a whole.

function validateDate(month, day, year) {
  const date = new Date(year, month - 1, day);
  return (
    date.getFullYear() === Number(year) &&
    date.getMonth() === Number(month) - 1 &&
    date.getDate() === Number(day)
  );
}

Not Handling the Native Date Input Value Format

The Problem: <input type="date"> always stores values as YYYY-MM-DD regardless of display locale, but developers often try to parse the displayed format instead.

How to Fix It? Always read from input.value (ISO format) or input.valueAsDate.

// Good: read ISO value, format for display separately
const dateInput = document.getElementById('my-date');
const isoValue = dateInput.value; // "2026-03-12"
const dateObject = dateInput.valueAsDate; // Date object

Related patterns


For full implementation detail, examples, and testing notes, see references/pattern.md.

Pattern page: https://uxpatterns.dev/patterns/forms/date-input

评价

还没有评价。欢迎分享你的使用感受。

评论

无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。

还没有评论。来写第一条吧。

提交后会立即公开。请勿填写邮箱、电话等个人信息。URL 最多 2 个。

0 / 1000 字

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

同一仓库的技能

accordion

免费

Use when implementing expand and collapse content sections.

中文简介正在准备中。当前显示原文说明。

thedaviddias/ux-patterns-for-developers2662026年10月5日 更新

Use when implementing user account configuration and preferences.

中文简介正在准备中。当前显示原文说明。

thedaviddias/ux-patterns-for-developers2662026年10月5日 更新

Use when implementing social activity and updates stream.

中文简介正在准备中。当前显示原文说明。

thedaviddias/ux-patterns-for-developers2662026年10月5日 更新

ai-chat

免费

Use when implementing conversational AI chat interfaces.

中文简介正在准备中。当前显示原文说明。

thedaviddias/ux-patterns-for-developers2662026年10月5日 更新

Use when implementing handling AI-specific errors.

中文简介正在准备中。当前显示原文说明。

thedaviddias/ux-patterns-for-developers2662026年10月5日 更新

Use when implementing loading states for AI operations.

中文简介正在准备中。当前显示原文说明。

thedaviddias/ux-patterns-for-developers2662026年10月5日 更新

查看 thedaviddias 的全部技能

报告此技能的问题