StealThis .dev

Date Picker

Calendar date picker with month navigation, range selection, disabled dates, and an input trigger — keyboard accessible.

Open in Lab
css vanilla-js
Targets: JS HTML

Code

Date Picker

A full calendar date picker with month navigation, single-date and range selection, disabled past dates, and an inline variant. No external libraries.

Variants

  • Single date — click an input to open a calendar dropdown, select a date, input updates
  • Date range — two inputs (start / end); first click sets start, second click sets end, hover highlights the range
  • Inline calendar — always visible, no trigger input

How it works

  1. The calendar grid is generated dynamically: first-day offset + days-in-month cells, padded with previous/next month ghost days
  2. Month navigation arrows call changeMonth(delta) which re-renders the grid
  3. For range mode, two state variables track rangeStart and rangeEnd; mouseover on a day cell updates a hoverDate used for the in-range highlight
  4. Past dates receive the disabled attribute and class; they are skipped during keyboard navigation
  5. Arrow keys move focus cell-by-cell; Enter selects; Escape closes the dropdown

Day cell states

  • Today — dot indicator below the number
  • Selected / range endpoints — solid accent background
  • In-range — light accent tint background
  • Disabled — muted text, not interactive