ข้อจำกัด

จำเป็น (Required)

เมื่อตั้งค่า required ปุ่มล้างค่าจะถูกปิดใช้งานและค่าจะไม่สามารถทำให้ว่างได้

import { useState } from "react";
import { DatePicker } from "react-date-range-picker-styled";
import "react-date-range-picker-styled/rdrp-styles.css";
function Required() {
const [value, setValue] = useState<Date | null>(new Date());
return <DatePicker value={value} onChange={setValue} required />;
}

วันที่ต่ำสุดและสูงสุด (Min & Max Dates)

จำกัดวันที่สามารถเลือกได้ให้อยู่ในช่วงที่กำหนดโดยใช้ minDate และ maxDate

import { useState } from "react";
import { DatePicker } from "react-date-range-picker-styled";
import "react-date-range-picker-styled/rdrp-styles.css";
function MinMaxDate() {
const [value, setValue] = useState<Date | null>(null);
const today = new Date();
const minDate = new Date(today.getFullYear(), today.getMonth(), 1);
const maxDate = new Date(today.getFullYear(), today.getMonth() + 1, 0);
return <DatePicker value={value} onChange={setValue} minDate={minDate} maxDate={maxDate} />;
}

วันที่ปิดใช้งาน (Disabled Dates)

ใช้ isDateUnavailable เพื่อปิดใช้งานวันที่ที่ระบุแบบไดนามิก

import { useState } from "react";
import { DatePicker } from "react-date-range-picker-styled";
import "react-date-range-picker-styled/rdrp-styles.css";
function DisabledDates() {
const [value, setValue] = useState<Date | null>(null);
const isDateUnavailable = (date: Date) => {
const day = date.getDay();
return day === 0 || day === 6; // Disable weekends
};
return <DatePicker value={value} onChange={setValue} isDateUnavailable={isDateUnavailable} />;
}

ปิดใช้งานอดีต / อนาคต (Disable Past / Future)

ใช้ disablePast หรือ disableFuture เพื่อปิดใช้งานวันที่ก่อน/หลังวันนี้อย่างรวดเร็ว

import { useState } from "react";
import { DatePicker } from "react-date-range-picker-styled";
import "react-date-range-picker-styled/rdrp-styles.css";
function DisablePastFuture() {
const [pastValue, setPastValue] = useState<Date | null>(null);
const [futureValue, setFutureValue] = useState<Date | null>(null);
return (
<div style={{ display: "flex", flexDirection: "column", gap: 16 }}>
<div>
<div style={{ fontSize: 13, fontWeight: 600, opacity: 0.7, marginBottom: 8 }}>
Past dates disabled
</div>
<DatePicker value={pastValue} onChange={setPastValue} disablePast />
</div>
<div>
<div style={{ fontSize: 13, fontWeight: 600, opacity: 0.7, marginBottom: 8 }}>
Future dates disabled
</div>
<DatePicker value={futureValue} onChange={setFutureValue} disableFuture />
</div>
</div>
);
}
Past dates disabled
Future dates disabled

ไฮไลท์วันที่ (Highlight Dates)

ไฮไลท์วันที่ที่ระบุด้วยภาพ (เช่น วันหยุด, กิจกรรม) โดยใช้ prop highlightDates

import { useState } from "react";
import { DatePicker } from "react-date-range-picker-styled";
import "react-date-range-picker-styled/rdrp-styles.css";
function HighlightDates() {
const [value, setValue] = useState<Date | null>(null);
const today = new Date();
const highlightDates = [
new Date(today.getFullYear(), today.getMonth(), 5),
new Date(today.getFullYear(), today.getMonth(), 15),
new Date(today.getFullYear(), today.getMonth(), 25),
];
return <DatePicker value={value} onChange={setValue} highlightDates={highlightDates} />;
}

เดือนเริ่มต้น (Initial Month)

ตั้งค่าเดือนที่แสดงเริ่มต้นเมื่อตัวเลือกถูกเปิดครั้งแรก

import { useState } from "react";
import { DatePicker } from "react-date-range-picker-styled";
import "react-date-range-picker-styled/rdrp-styles.css";
function InitialMonth() {
const [value, setValue] = useState<Date | null>(null);
return <DatePicker value={value} onChange={setValue} initialMonth={new Date(2026, 5, 1)} />;
}