ข้อจำกัด
วันขั้นต่ำและสูงสุด
จำกัดความยาวของช่วงด้วย minDays และ maxDays (รวม) ผู้ใช้ไม่สามารถยืนยันช่วงที่สั้นกว่า minDays หรือยาวกว่า maxDays ได้
import { useState } from "react";import "react-date-range-picker-styled/rdrp-styles.css";import { DateRangePicker } from "react-date-range-picker-styled";
function MinMaxDays() { const [value, setValue] = useState<{ start: Date | null; end: Date | null }>({ start: null, end: null, });
return <DateRangePicker value={value} onChange={setValue} minDays={3} maxDays={14} />;}วันที่ถูกปิดใช้งาน
ใช้ isDateUnavailable เพื่อปิดใช้งานวันที่ระบุแบบไดนามิก วันที่ถูกปิดใช้งานจะไม่สามารถเลือกเป็นวันเริ่มต้นหรือสิ้นสุดของช่วงได้
import { useState } from "react";import "react-date-range-picker-styled/rdrp-styles.css";import { DateRangePicker } from "react-date-range-picker-styled";
const isWeekend = (date: Date) => { const day = date.getDay(); return day === 0 || day === 6;};
function DisabledDates() { const [value, setValue] = useState<{ start: Date | null; end: Date | null }>({ start: null, end: null, });
return <DateRangePicker value={value} onChange={setValue} isDateUnavailable={isWeekend} />;}อนุญาตให้เลือกวันเดียว
โดยค่าเริ่มต้น, ช่วงที่วันเริ่มต้นเท่ากับวันสิ้นสุดจะได้รับอนุญาต ตั้งค่า allowSingleDateInRange={false} เพื่อกำหนดให้ต้องมีวันที่แตกต่างกันอย่างน้อยสองวัน
import { useState } from "react";import { DateRangePicker } from "react-date-range-picker-styled";import "react-date-range-picker-styled/rdrp-styles.css";
function AllowSingleDate() { const [value, setValue] = useState<{ start: Date | null; end: Date | null }>({ start: null, end: null, });
return <DateRangePicker value={value} onChange={setValue} allowSingleDateInRange={false} />;}