Comportamento
Fechar ao Selecionar
Quando shouldCloseOnSelect está ativado, o seletor confirma e fecha automaticamente quando uma predefinição é clicada.
ℹ️ Info
Para seletores com hora ativada, shouldCloseOnSelect se aplica apenas a cliques em predefinições
— não a cliques em datas, já que o usuário ainda precisa definir a hora.
import { useState } from "react";import { DateRangeTimePicker } from "react-date-range-picker-tailwind4";
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 }} /> );}Múltiplos Meses
Exiba mais do que os dois meses padrão, lado a lado.
import { useState } from "react";import { DateRangeTimePicker } from "react-date-range-picker-tailwind4";
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 }} /> );}Integração com Formulário
Use a prop name para incluir inputs ocultos para submissão de formulário nativo.
💡 Tip
O estilo do botão de submissão neste exemplo é personalizado — a biblioteca fornece apenas o seletor de data.
import { type SubmitEvent, useState } from "react";import { DateRangeTimePicker } from "react-date-range-picker-tailwind4";
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> );}