DateInput
A calendar component for date selection with support for single, range, and multiple date picking
Installation
Terminal
Import
Component.tsx
Basic
`DateInput` is a sophisticated date input component with intelligent parsing, prediction, and keyboard navigation.
Features:
- Intelligent date parsing with natural language support (today, tomorrow, yesterday)
- Multiple format support (ISO, localized, custom date-fns formats)
- Keyboard navigation (arrow keys, shortcuts) and mouse drag interaction
- Real-time prediction and validation with smart date correction
- Internationalization support with multiple locales
- English month name recognition (jan, feb, march, etc.)
- Flexible input modes with customizable prefix icons
- Seamless integration with calendar components
Usage:
- Use for date entry in forms, filters, and date selection interfaces
- Combine with calendar popovers for enhanced date selection
- Leverage natural language parsing for improved user experience
- Support multiple locales for international applications
Best Practices:
- Choose appropriate date formats for your target audience
- Provide clear placeholder text to guide user input
- Use consistent date formats across your application
- Test with various locales if supporting international users
Accessibility:
- Full keyboard navigation support with arrow keys and shortcuts
- Screen reader friendly with proper ARIA labels
- Focus management and proper error handling
- Semantic HTML input elements for optimal accessibility
Basic: Shows the default DateInput usage.
- Demonstrates a simple date input with default styling and behavior.
- Use as a starting point for date input implementation.
States
States: Demonstrates all interactive states of the DateInput component.
- Shows normal, disabled, readOnly, and custom prefix configurations.
- Displays how the component behaves in different states.
- Useful for testing component behavior across various conditions.
Read Only
ReadOnly: Demonstrates the DateInput component in readOnly mode.
- Prevents value changes while allowing focus and selection
- Maintains normal visual appearance (unlike disabled)
- Useful for displaying non-editable date information
Current Value:
1/24/2026
Change Count:
0
💡 Try changing the readonly date input - the value should not change and the change count should remain at 0. Only the normal input will change the value.
Size
Size: Demonstrates the different size options for the DateInput component.
- Shows the large size variant for prominent date selection interfaces.
- Useful for adapting the component to different UI layouts and emphasis levels.
Variable
Variable: Demonstrates the DateInput component with dark theme variant.
- Shows the dark variant styling for use in dark theme contexts.
- Useful for applications with multiple theme options or dark mode support.
Drag Interaction
DragInteraction: Demonstrates the mouse drag interaction feature of the DateInput component.
- Shows how to click and drag the calendar icon to adjust dates.
- Displays modifier keys (Shift, Ctrl/Cmd) for different drag increments.
- Provides an intuitive mouse-based alternative to keyboard navigation.
🖱️ Drag Interaction
• Click and drag the calendar icon to adjust date
• Hold Shift key to drag 1 week
• Hold Ctrl/Cmd key to drag 1 month
Formats
Formats: Demonstrates various date format options supported by the DateInput component.
- Shows ISO format (yyyy-MM-dd), localized formats, and custom date-fns patterns.
- Displays how different formats render with various locales.
- Useful for understanding format flexibility and localization support.
Variable Length Formats
VariableLengthFormats: Demonstrates the flexible date format support with variable length patterns.
- Shows how the component handles different year, month, and day format lengths.
- Displays various international formats with different separators and structures.
- Includes a comprehensive guide to date-fns format patterns and usage tips.
📏 Variable Length Formats
DateInput now supports any date-fns format string, including different length years, months, etc.
Format:
Example: 2025年12月31日
yyyy年MM月dd日Example: 2025年12月31日
Current Value: None
Format:
Example: 25年12月31日
yy年M月d日Example: 25年12月31日
Current Value: None
Format:
Example: 2025年1月5日
yyyy年M月d日Example: 2025年1月5日
Current Value: None
Format:
Example: December 25, 2025
MMMM dd, yyyyExample: December 25, 2025
Current Value: None
Format:
Example: Dec 25, 25
MMM dd, yyExample: Dec 25, 25
Current Value: None
Format:
Example: 12/25/25
M/d/yyExample: 12/25/25
Current Value: None
Format:
Example: Déc 25 2025
MMM d yyyyExample: Déc 25 2025
Current Value: None
Format:
Example: 25.12.2025
dd.MM.yyyyExample: 25.12.2025
Current Value: None
📖 Format Description
Year Format
yyyy → 2025 (4-digit year)yy → 25 (2-digit year)Month Format
MMMM → December (full month name)MMM → Dec (short month name)MM → 12 (2-digit month)M → 12 (1-2 digit month)Day Format
dd → 31 (2-digit day)d → 31 (1-2 digit day)Separator Format
- → 2025-12-31/ → 12/31/2025. → 31.12.2025年月日 → 2025年12月31日💡 Usage Tips
Now you can use any date-fns format string directly, no longer limited by predefined formats. View full format options:date-fns format documentation
Prediction
Prediction: Demonstrates the intelligent prediction and real-time highlighting features.
- Shows real-time prediction suggestions as users type.
- Displays intelligent number format recognition and completion.
- Demonstrates keyboard interaction with prediction prompts.
- Includes automatic formatting and error correction capabilities.
🎨 Real-time Highlight
• Number automatically highlights
• Shortcut key color change prompt
• Intelligent recognition of input content
💡 Intelligent Prediction
• Real-time prediction prompt box ✅
• Number format recognition ✅
• Intelligent completion suggestions ✅
⌨️ Keyboard Interaction
• Enter Confirm input
• Esc Hide prompt
• Automatic formatting when focus is lost
🔄 Formatting
• Automatic formatting output
• Intelligent error correction
• Real-time content synchronization
Shortcut Keys
ShortcutKeys: Demonstrates the natural language shortcut key support.
- Shows how to use text shortcuts like "today", "yesterday", "tomorrow".
- Displays multilingual support for shortcut keys (English and Chinese).
- Demonstrates relative date shortcuts like "this week", "this month".
- Useful for users who prefer typing natural language date expressions.
⚡ Shortcut Key Highlight Demo
Today
Input:
t or Today or 今天Yesterday
Input:
y or Yesterday or 昨天Tomorrow
Input:
tm or Tomorrow or 明天This Week
Input:
w or This Week or 本周This Month
Input:
m or This Month or 本月English Month Support
EnglishMonthSupport: Demonstrates the English month name recognition feature.
- Shows support for full month names, abbreviations, and various formats.
- Displays flexible date input patterns like "may 15", "15 may", "may 15, 2024".
- Demonstrates intelligent parsing of month names with dots and variants.
- Useful for international users who prefer English month names.
🌍 English Month Recognition
📝 支持格式
•
may → May 1st•
may 15 → May 15th•
15 may → May 15th•
may 15, 2024 → May 15th, 2024•
15 may 2024 → May 15th, 2024•
may 15th → May 15th📚 Month Abbreviations
•
jan → January•
feb → February•
mar → March•
apr → April•
may → May•
jun → June•
jul → July•
aug → August🎯 Intelligent Recognition
Full Name
january, february...
Abbreviations
jan, feb, mar...
With Dots
jan., feb., mar.
Variants
sept, sept.
💡 Tips
Support mixed input of English and Chinese, automatically recognize the best match. When inputting, it will display the segmented effect and prediction prompt in real time.
Smart Date Correction
SmartDateCorrection: Demonstrates the intelligent date correction feature.
- Shows how invalid dates are automatically corrected to valid dates.
- Displays correction rules for dates exceeding month limits, invalid months, and leap years.
- Demonstrates seamless user experience without error prompts.
- Useful for preventing user frustration with invalid date inputs.
🔧 Smart Date Correction
When an invalid date is entered, the system will automatically correct it to the last day of the month, ensuring that the date is always valid. ✨ Now fixed!
❌ Invalid Date Input
•
2025-04-31 → 2025-04-30 (April has 30 days)•
2025-02-30 → 2025-02-28 (February has 28 days)•
2024-02-30 → 2024-02-29 (February 29th in leap year)•
2025-13-15 → 2025-12-15 (No 13th month)•
2025-06-00 → 2025-06-01 (No 0th day)✅ Smart Correction Rules
• Date exceeds the number of days in the month → Corrected to the last day of the month
• Month greater than 12 → Corrected to December
• Month less than 1 → Corrected to January
• Date less than 1 → Corrected to 1st
• Automatically handle February 29th in leap year
�� Test Examples
April 31st
Input:
20250431→ 2025-04-30
February 30th
Input:
20250230→ 2025-02-28
13th month 15th
Input:
20251315→ 2025-12-15
June 0th
Input:
20250600→ 2025-06-01
Leap year February 29th
Input:
20240230→ 2024-02-29
September 31st
Input:
20250931→ 2025-09-30
✨ Intelligent Features
No matter what invalid date is entered, the system will automatically correct it to the nearest valid date, ensuring a smooth user experience without error prompts. 🚀 Fixed and working properly!
Internationalization Support
InternationalizationSupport: Demonstrates comprehensive internationalization support.
- Shows DateInput working with multiple locales (Chinese, English, German, French).
- Displays natural language parsing in different languages.
- Demonstrates locale-specific date formatting and display.
- Includes usage examples and integration code snippets.
🌍 Internationalization Support
The DateInput component now supports multiple language regions, correctly parsing and formatting natural language input in different languages.
支持的中文输入:
• 今天、明天、昨天
• 本周、下周、上周
• 本月、下月、上月
• 2024年12月25日
Current: None
Supported English input:
• today, tomorrow, yesterday
• this week, next week
• this month, next month
• Dec 25, 2024
Current: None
Deutsche Formate:
• 25.12.2024 (Standard)
• Dezember 25, 2024
• 25. Dezember 2024
• Dezember 25, 2024
• 25. Dezember 2024
Aktuell: Keine
Formats français:
• 25/12/2024 (Standard)
• 25 décembre 2024
• décembre 25, 2024
• 25 décembre 2024
• décembre 25, 2024
Actuel: Aucun
🚀 Usage
Simply pass the
locale property to enable support for the corresponding language:import { zhCN, enUS } from 'date-fns/locale'
<DateInput locale={zhCN} placeholder="输入中文日期..." />
<DateInput locale={enUS} placeholder="Enter English date..." />Combined
Combined: Demonstrates a complete integration example with calendar popover.
- Shows DateInput integrated with MonthCalendar in a popover.
- Displays both single date input and date range input functionality.
- Demonstrates locale switching and proper state management.
- Useful as a reference for real-world implementation patterns.
Select Date
API reference
| MonthCalendar | Type | Default |
|---|---|---|
className | string |undefined | - |
currentMonth | Date |undefined | - |
dateComparisonMode | undefined |"exact-time" |"date-only" | - |
defaultValue | CalendarValue |undefined | - |
disabledDates | Date[] |undefined | - |
fixedGrid | boolean |undefined | - |
highlightDates | Date[] |undefined | - |
highlightToday | boolean |undefined | - |
locale | string |Locale |undefined | - |
maxDate | Date |undefined | - |
minDate | Date |undefined | - |
onChange | ((value: CalendarValue) => void) |undefined | - |
onMonthChange | ((month: Date) => void) |undefined | - |
readOnly | boolean |undefined | - |
selectionMode | undefined |"single" |"multiple" |"range" | - |
showOutsideDays | boolean |undefined | - |
showWeekNumbers | boolean |undefined | - |
timeZone | string |undefined | - |
value | CalendarValue |undefined | - |
weekStartsOn | undefined |0 |1 |2 |3 |4 |5 |6 | - |
weekdayNames | string[] |undefined | - |
direction | undefined |"horizontal" |"vertical" | - |
variant | undefined |"default" |"dark" | - |
| DateInputValue | Type | Default |
value | Date |null |undefined | - |
onChange | ((date: Date |null) => void) |undefined | - |
format | string |undefined | - |
size | undefined |"default" |"large" | - |
selected | boolean |undefined | - |
className | string |undefined | - |
focusSelection | undefined |"none" |"all" |"end" | - |
onIsEditingChange | ((isEditing: boolean) => void) |undefined | - |
variant | undefined |"default" |"light" |"dark" |"reset" | - |
enableCache | boolean |undefined | true |
enableKeyboardNavigation | boolean |undefined | true |
enablePrediction | boolean |undefined | false |
enableProfiling | boolean |undefined | false |
locale | string |Locale |undefined | - |
maxDate | Date |undefined | - |
minDate | Date |undefined | - |
onEnterKeyDown | (() => void) |undefined | - |
prefixElement | ReactNode | - |
suffixElement | ReactNode | - |
| DateRangeInput | Type | Default |
endDisabled | boolean |undefined | - |
endPlaceholder | string |undefined | - |
endSuffixElement | ReactNode | - |
endValue | Date |null |undefined | - |
format | string |undefined | - |
locale | string |Locale |undefined | - |
maxDate | Date |undefined | - |
minDate | Date |undefined | - |
onEndChange | ((date: Date |null) => void) |undefined | - |
onEndFocus | (() => void) |undefined | - |
onEnterKeyDown | (() => void) |undefined | - |
onStartChange | ((date: Date |null) => void) |undefined | - |
onStartFocus | (() => void) |undefined | - |
rangePrecision | number |undefined | 1 - Minimum unit is 1 day |
startDisabled | boolean |undefined | - |
startPlaceholder | string |undefined | - |
startSuffixElement | ReactNode | - |
startValue | Date |null |undefined | - |
size | undefined |"default" |"large" | - |
selected | boolean |undefined | - |
className | string |undefined | - |
focusSelection | undefined |"none" |"all" |"end" | - |
onIsEditingChange | ((isEditing: boolean) => void) |undefined | - |
variant | undefined |"default" |"light" |"dark" |"reset" | - |
| TimeCalendar | Type | Default |
className | string |undefined | - |
hourStep | number |undefined | - |
minuteStep | number |undefined | - |
open | boolean |undefined | - |
onOpenChange | ((open: boolean) => void) |undefined | - |
closeOnSelect | boolean |undefined | - |
triggerRef | RefObject<HTMLElement> |undefined | - |
triggerSelector | string |undefined | - |
defaultValue | Date |null |undefined | - |
disabled | boolean |undefined | - |
format | string |undefined | - |
locale | string |Locale |undefined | - |
maxTime | Date |undefined | - |
minTime | Date |undefined | - |
onChange | ((time: Date |null) => void) |undefined | - |
readOnly | boolean |undefined | - |
value | Date |null |undefined | - |
metaStep | number |undefined | - |
shiftStep | number |undefined | - |
step | number |undefined | - |
offset | number |undefined | - |
placement | undefined |"top" |"right" |"bottom" |"left" |"top-start" |"top-end" |"right-start" |"right-end" |"bottom-start" |"bottom-end" |"left-start" |"left-end" | - |
matchTriggerWidth | boolean |undefined | - |
variant | undefined |"default" |"light" |"reset" | - |
| TimeInputValue | Type | Default |
value | Date |null |undefined | - |
onChange | ((time: Date |null) => void) |undefined | - |
format | string |undefined | - |
defaultValue | Date |null |undefined | - |
step | number |undefined | - |
size | undefined |"default" |"large" | - |
selected | boolean |undefined | - |
className | string |undefined | - |
focusSelection | undefined |"none" |"all" |"end" | - |
onIsEditingChange | ((isEditing: boolean) => void) |undefined | - |
variant | undefined |"default" |"light" |"dark" |"reset" | - |
prefixElement | ReactNode | - |
suffixElement | ReactNode | - |
locale | string |Locale |undefined | - |
maxTime | Date |undefined | - |
minTime | Date |undefined | - |
metaStep | number |undefined | - |
shiftStep | number |undefined | - |
enableCache | boolean |undefined | - |
enableKeyboardNavigation | boolean |undefined | - |
enableProfiling | boolean |undefined | - |
onEnterKeyDown | (() => void) |undefined | - |
| TimeRangeInput | Type | Default |
endDisabled | boolean |undefined | - |
endPlaceholder | string |undefined | - |
endSuffixElement | ReactNode | - |
endValue | Date |null |undefined | - |
format | string |undefined | - |
locale | string |Locale |undefined | - |
maxTime | Date |undefined | - |
minTime | Date |undefined | - |
onEndChange | ((time: Date |null) => void) |undefined | - |
onEndFocus | (() => void) |undefined | - |
onEnterKeyDown | (() => void) |undefined | - |
onStartChange | ((time: Date |null) => void) |undefined | - |
onStartFocus | (() => void) |undefined | - |
startDisabled | boolean |undefined | - |
startPlaceholder | string |undefined | - |
startSuffixElement | ReactNode | - |
startValue | Date |null |undefined | - |
size | undefined |"default" |"large" | - |
selected | boolean |undefined | - |
className | string |undefined | - |
focusSelection | undefined |"none" |"all" |"end" | - |
onIsEditingChange | ((isEditing: boolean) => void) |undefined | - |
variant | undefined |"default" |"light" |"dark" |"reset" | - |
| QuarterCalendar | Type | Default |
currentYear | number |undefined | - |
defaultValue | Quarter |undefined | - |
disabled | boolean |undefined | - |
disabledQuarters | { quarter: number; year: number; }[] |undefined | - |
locale | string |Locale |undefined | - |
maxYear | number |undefined | - |
minYear | number |undefined | - |
onChange | ((quarter: Quarter |null) => void) |undefined | - |
readOnly | boolean |undefined | - |
startYear | number |undefined | - |
value | Quarter |null |undefined | - |
onNavigate | ((direction: "prev" |"next", newYear: number) => void) |undefined | - |
className | string |undefined | - |
variant | undefined |"default" |"dark" | - |
| YearCalendar | Type | Default |
currentYear | Date |undefined | - |
defaultValue | Date |undefined | - |
disabled | boolean |undefined | - |
disabledYears | Date[] |undefined | - |
locale | string |Locale |undefined | - |
maxYear | Date |undefined | - |
minYear | Date |undefined | - |
onChange | ((year: Date |null) => void) |undefined | - |
readOnly | boolean |undefined | - |
startYear | Date |undefined | - |
value | Date |null |undefined | - |
yearCount | number |undefined | - |
onNavigate | ((direction: "prev" |"next", newStartYear: Date) => void) |undefined | - |
className | string |undefined | - |
variant | undefined |"default" |"dark" | - |
| inferSelectionMode | Type | Default |
end | Date | - |
start | Date | - |
| inferMonthFromValue | Type | Default |
end | Date | - |
start | Date | - |
| formatQuarter | Type | Default |
label | string | - |
months | string[] | - |
quarter | 1 |2 |3 |4 | - |
year | number | - |
| getQuarterDateRange | Type | Default |
label | string | - |
months | string[] | - |
quarter | 1 |2 |3 |4 | - |
year | number | - |
| timeToDate | Type | Default |
hour | number | - |
minute | number | - |
| useDateInput | Type | Default |
onPressEnd | (((event: PressEvent) => void) & ((e: PointerEvent) => void)) |undefined | - |
onPressStart | (((event: PressEvent) => void) & ((e: PointerEvent) => void)) |undefined | - |
readOnly | boolean |undefined | - |
ref | Ref<HTMLInputElement> |undefined | - |
defaultValue | Date |null |undefined | - |
disabled | boolean |undefined | - |
format | string |undefined | - |
locale | string |Locale |undefined | - |
maxDate | Date |undefined | - |
minDate | Date |undefined | - |
onChange | ((date: Date |null) => void) |undefined | - |
value | Date |null |undefined | - |
metaStep | number |undefined | - |
shiftStep | number |undefined | - |
step | number |undefined | - |
enableCache | boolean |undefined | - |
enableKeyboardNavigation | boolean |undefined | - |
enablePrediction | boolean |undefined | - |
enableProfiling | boolean |undefined | - |
onEnterKeyDown | (() => void) |undefined | - |
| useTimeInput | Type | Default |
onPressEnd | (((event: PressEvent) => void) & ((e: PointerEvent) => void)) |undefined | - |
onPressStart | (((event: PressEvent) => void) & ((e: PointerEvent) => void)) |undefined | - |
readOnly | boolean |undefined | - |
ref | Ref<HTMLInputElement> |undefined | - |
defaultValue | Date |null |undefined | - |
disabled | boolean |undefined | - |
format | string |undefined | - |
locale | string |Locale |undefined | - |
maxTime | Date |undefined | - |
minTime | Date |undefined | - |
onChange | ((time: Date |null) => void) |undefined | - |
value | Date |null |undefined | - |
metaStep | number |undefined | - |
shiftStep | number |undefined | - |
step | number |undefined | - |
enableCache | boolean |undefined | - |
enableKeyboardNavigation | boolean |undefined | - |
enableProfiling | boolean |undefined | - |
onEnterKeyDown | (() => void) |undefined | - |