Comportamento
Chiudi alla Selezione
Quando shouldCloseOnSelect è abilitato, il selettore conferma e si chiude automaticamente quando viene cliccato un predefinito.
ℹ️ Info
Per i selettori con orario abilitato, shouldCloseOnSelect si applica solo ai clic sui
predefiniti, non ai clic sulle date, poiché l’utente deve ancora impostare l’orario.
import { useState } from "react";import { DateRangeTimePicker } from "react-date-range-picker-tailwind3";
function ShouldCloseOnSelect() { const [value, setValue] = useState<{ start: Date | null; end: Date | null }>({ start: null, end: null, });
return ( <DateRangeTimePicker value={value} onChange={setValue} shouldCloseOnSelect time={{ minuteStep: 5 }} /> );}Mesi Multipli
Visualizza più dei due mesi predefiniti uno accanto all’altro.
import { useState } from "react";import { DateRangeTimePicker } from "react-date-range-picker-tailwind3";
function MultiMonth() { const [value, setValue] = useState<{ start: Date | null; end: Date | null }>({ start: null, end: null, });
return ( <DateRangeTimePicker value={value} onChange={setValue} numberOfMonths={3} time={{ minuteStep: 5 }} /> );}Integrazione con Form
Usa la prop name per includere input nascosti per l’invio nativo del form.
💡 Tip
Lo stile del pulsante di invio in questo esempio è personalizzato: la libreria fornisce solo il selettore di date.
import { type SubmitEvent, useState } from "react";import { DateRangeTimePicker } from "react-date-range-picker-tailwind3";
function FormIntegration() { const [value, setValue] = useState<{ start: Date | null; end: Date | null }>({ start: null, end: null, });
const handleSubmit = (e: SubmitEvent<HTMLFormElement>) => { e.preventDefault(); const formData = new FormData(e.currentTarget); const start = formData.get("booking"); const end = formData.get("booking-end"); alert( `Submitted range: ${typeof start === "string" ? start : ""} ~ ${typeof end === "string" ? end : ""}`, ); };
return ( <form onSubmit={handleSubmit} style={{ display: "flex", alignItems: "center", gap: 8 }}> <DateRangeTimePicker value={value} onChange={setValue} name="booking" time={{ minuteStep: 5 }} /> <button type="submit" style={{ padding: "6px 14px", border: "1px solid #d1d5db", borderRadius: 6, background: "#3b82f6", color: "#fff", cursor: "pointer", fontSize: 13, }} > Submit </button> </form> );}