Skip to content

Commit 2f5f31c

Browse files
committed
Introduce disabled dates prop.
1 parent 8ce85da commit 2f5f31c

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ export default function ReadMeExampleSingle() {
9595
// validRange={{
9696
// startDate: new Date(2021, 1, 2), // optional
9797
// endDate: new Date(), // optional
98+
// disabledDates: [new Date()] // optional
9899
// }}
99100
// onChange={} // same props as onConfirm but triggered without confirmed by user
100101
// saveLabel="Save" // optional
@@ -149,6 +150,7 @@ export default function ReadMeExampleRange() {
149150
// validRange={{
150151
// startDate: new Date(2021, 1, 2), // optional
151152
// endDate: new Date(), // optional
153+
// disabledDates: [new Date()] // optional
152154
// }}
153155
// onChange={} // same props as onConfirm but triggered without confirmed by user
154156
// locale={'nl'} // optional
@@ -203,6 +205,7 @@ export default function ReadMeExampleMultiple() {
203205
// validRange={{
204206
// startDate: new Date(2021, 1, 2), // optional
205207
// endDate: new Date(), // optional
208+
// disabledDates: [new Date()] // optional
206209
// }}
207210
// locale={'nl'} // optional
208211
// saveLabel="Save" // optional

src/Date/Calendar.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export type ScrollModeType = 'horizontal' | 'vertical'
2525
export type ValidRangeType = {
2626
startDate?: Date
2727
endDate?: Date
28+
disabledDates?: Date[]
2829
}
2930

3031
export type BaseCalendarProps = {

src/Date/Month.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,18 @@ function Month(props: MonthSingleProps | MonthRangeProps | MonthMultiProps) {
153153
let inRange = false
154154
let disabled = false
155155
let selected = false
156+
let inDisabledDates = false
156157
let leftCrop = dayOfMonth === 1
157158
let rightCrop = dayOfMonth === daysInMonth
158159

159160
const isFirstDayOfMonth = dayOfMonth === 1
160161
const isLastDayOfMonth = dayOfMonth === daysInMonth
162+
163+
inDisabledDates = validRange?.disabledDates ? validRange.disabledDates.some(disabledDate => areDatesOnSameDay(disabledDate, day)) : false
164+
if (inDisabledDates) {
165+
disabled = true
166+
}
167+
161168
if (mode === 'range') {
162169
const selectedStartDay = areDatesOnSameDay(day, startDate)
163170
const selectedEndDay = areDatesOnSameDay(day, endDate)
@@ -237,7 +244,7 @@ function Month(props: MonthSingleProps | MonthRangeProps | MonthMultiProps) {
237244
endUnix: validRangeEnd,
238245
})
239246

240-
if (inRange) {
247+
if (inRange && !inDisabledDates) {
241248
disabled = false
242249
}
243250

0 commit comments

Comments
 (0)