Comportamiento

Cerrar al Seleccionar

Cuando shouldCloseOnSelect está habilitado, el selector confirma y se cierra automáticamente cuando se hace clic en un preajuste.

ℹ️ Info

Para selectores con hora habilitada, shouldCloseOnSelect solo se aplica a los clics en preajustes, no a los clics en fechas, ya que el usuario todavía necesita establecer la hora.

import { useState } from "react";
import "react-date-range-picker-styled/rdrp-styles.css";
import { DateRangeTimePicker } from "react-date-range-picker-styled";
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últiples Meses

Muestra más de los dos meses predeterminados uno al lado del otro.

import { useState } from "react";
import "react-date-range-picker-styled/rdrp-styles.css";
import { DateRangeTimePicker } from "react-date-range-picker-styled";
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 }}
/>
);
}

Integración con Formularios

Usa la prop name para incluir inputs ocultos para el envío de formularios nativos.

💡 Tip

El estilo del botón de envío en este ejemplo es personalizado; la biblioteca solo proporciona el selector de fechas.

import { type SubmitEvent, useState } from "react";
import "react-date-range-picker-styled/rdrp-styles.css";
import { DateRangeTimePicker } from "react-date-range-picker-styled";
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>
);
}