feat(DateTimeInput): add calendar picker functionality to DateTimeInput component

- Introduced a ref to manage the input element for triggering the native calendar picker.
- Enhanced the Calendar icon with a click handler to open the date picker, improving user interaction.
- Updated styles for the Calendar icon to include hover effects for better visual feedback.
This commit is contained in:
Julien Froidefond
2025-10-10 08:24:33 +02:00
parent 52d8332f0c
commit e7cbd56e89

View File

@@ -1,6 +1,7 @@
'use client';
import { Calendar } from 'lucide-react';
import { useRef } from 'react';
import {
formatDateForDateTimeInput,
parseDateTimeInput,
@@ -23,6 +24,8 @@ export function DateTimeInput({
className = '',
onFocus,
}: DateTimeInputProps) {
const inputRef = useRef<HTMLInputElement>(null);
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const newValue = e.target.value
? parseDateTimeInput(e.target.value)
@@ -30,13 +33,22 @@ export function DateTimeInput({
onChange(newValue);
};
const handleCalendarClick = () => {
if (!disabled && inputRef.current) {
// Déclencher le calendrier natif du navigateur
inputRef.current.showPicker?.();
}
};
return (
<div className={`relative flex items-center ${className}`}>
<Calendar
size={16}
className="absolute left-3 text-[var(--muted-foreground)] pointer-events-none z-10"
className="absolute left-3 text-[var(--muted-foreground)] cursor-pointer z-10 hover:text-[var(--primary)] transition-colors"
onClick={handleCalendarClick}
/>
<input
ref={inputRef}
type="datetime-local"
value={value ? formatDateForDateTimeInput(value) : ''}
onChange={handleChange}