Zachowanie

Zamykanie po wybraniu

Gdy opcja shouldCloseOnSelect jest włączona, wybierak automatycznie zatwierdza wybór i zamyka się po kliknięciu daty.

import { useState } from "react";
import { DateTimePicker } from "react-date-range-picker-styled";
import "react-date-range-picker-styled/rdrp-styles.css";
function ShouldCloseOnSelect() {
const [value, setValue] = useState<Date | null>(null);
return (
<DateTimePicker
value={value}
onChange={setValue}
shouldCloseOnSelect
time={{ minuteStep: 5 }}
/>
);
}

Wiele miesięcy

Wyświetlaj wiele miesięcy obok siebie.

import { useState } from "react";
import { DateTimePicker } from "react-date-range-picker-styled";
import "react-date-range-picker-styled/rdrp-styles.css";
function MultiMonth() {
const [value, setValue] = useState<Date | null>(null);
return (
<DateTimePicker value={value} onChange={setValue} numberOfMonths={2} time={{ minuteStep: 5 }} />
);
}

Integracja z formularzem

Użyj właściwości name, aby dodać ukryte pole (input) dla natywnego przesyłania formularza.

💡 Tip

Style przycisku przesyłania w tym przykładzie są niestandardowe — biblioteka dostarcza tylko wybierak dat.

import { type SubmitEvent, useState } from "react";
import { DateTimePicker } from "react-date-range-picker-styled";
import "react-date-range-picker-styled/rdrp-styles.css";
function FormIntegration() {
const [value, setValue] = useState<Date | null>(null);
const handleSubmit = (e: SubmitEvent<HTMLFormElement>) => {
e.preventDefault();
const formData = new FormData(e.currentTarget);
const appointment = formData.get("appointment");
alert(`Submitted datetime: ${typeof appointment === "string" ? appointment : ""}`);
};
return (
<form onSubmit={handleSubmit}>
<DateTimePicker value={value} onChange={setValue} name="appointment" />
<button type="submit" style={{ marginTop: 8 }}>
Submit
</button>
</form>
);
}