Skip to content

Commit 146a281

Browse files
committed
docs: add more docs about for disabled prop
Signed-off-by: Giampaolo Bellavite <[email protected]>
1 parent 2eeb513 commit 146a281

File tree

2 files changed

+65
-7
lines changed

2 files changed

+65
-7
lines changed

src/types/props.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,9 +316,10 @@ export interface PropsBase {
316316
*/
317317
initialFocus?: boolean;
318318
/**
319-
* Apply the `disabled` modifier to the matching days.
319+
* Apply the `disabled` modifier to the matching days. Disabled days cannot be
320+
* selected when in a selection mode is set.
320321
*
321-
* @see https://daypicker.dev/docs/selection-modes#disabling-dates
322+
* @see https://daypicker.dev/docs/selection-modes#disabled
322323
*/
323324
disabled?: Matcher | Matcher[] | undefined;
324325
/**
@@ -632,6 +633,12 @@ export interface PropsMulti {
632633
export interface PropsRangeRequired {
633634
mode: "range";
634635
required: true;
636+
/**
637+
* Apply the `disabled` modifier to the matching days. Disabled days cannot be
638+
* selected when in a selection mode is set.
639+
*
640+
* @see https://daypicker.dev/docs/selection-modes#disabled
641+
*/
635642
disabled?: Matcher | Matcher[] | undefined;
636643
/**
637644
* When `true`, the range will reset when including a disabled day.
@@ -657,11 +664,18 @@ export interface PropsRangeRequired {
657664
export interface PropsRange {
658665
mode: "range";
659666
required?: false | undefined;
667+
/**
668+
* Apply the `disabled` modifier to the matching days. Disabled days cannot be
669+
* selected when in a selection mode is set.
670+
*
671+
* @see https://daypicker.dev/docs/selection-modes#disabled
672+
*/
660673
disabled?: Matcher | Matcher[] | undefined;
661674
/**
662675
* When `true`, the range will reset when including a disabled day.
663676
*
664677
* @since V9.0.2
678+
* @see https://daypicker.dev/docs/selection-modes#exclude-disabled
665679
*/
666680
excludeDisabled?: boolean | undefined;
667681
/** The selected range. */

website/docs/docs/selection-modes.mdx

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,17 +174,59 @@ By setting the `required` prop, DayPicker ensures that the selected range cannot
174174
<Examples.RangeRequired />
175175
</BrowserWindow>
176176

177-
## Disabling Dates
177+
## Disabling Dates {#disabled}
178178

179-
To disable specific days, use the `disabled` prop. Disabled dates cannot be selected.
179+
To disable specific days, use the `disabled` prop. Disabled days cannot be selected.
180+
181+
### Matchers Types
180182

181183
The prop accepts a [`Matcher`](../api/type-aliases/Matcher.md) or an array of matchers to specify which days should be disabled.
182184

183-
### Disabling Specific Dates
185+
| Matcher Type | Description |
186+
| ----------------------------------------------------- | ------------------------------------------------------------------------- |
187+
| `boolean` | Disable all the dates |
188+
| `Date` | Matches a specific date. |
189+
| `Date[]` | Matches any date in the array of dates. |
190+
| [`DateRange`](../api/type-aliases/DateRange.md) | Matches a range of dates, including the start and end dates. |
191+
| [`DateBefore`](../api/type-aliases/DateBefore.md) | Matches all dates before a specific date (exclusive). |
192+
| [`DateAfter`](../api/type-aliases/DateAfter.md) | Matches all dates after a specific date (exclusive). |
193+
| [`DateInterval`](../api/type-aliases/DateInterval.md) | Matches dates between two dates (exclusive of the start and end dates). |
194+
| [`DayOfWeek`](../api/type-aliases/DayOfWeek.md) | Matches specific days of the week (e.g., Sunday is `0`, Saturday is `6`). |
195+
| `(date: Date) => boolean` | A function that returns `true` if the given date matches the condition. |
196+
| [`Matcher[]`](../api/type-aliases/Matcher.md) | An array of the matchers listed above. |
197+
198+
```tsx
199+
// Disable all days
200+
<DayPicker disabled />
201+
202+
// Disable a day
203+
<DayPicker disabled={new Date(2023, 9, 1)} />
204+
205+
// Disable an array of days
206+
<DayPicker disabled={[new Date(2023, 9, 1), new Date(2023, 9, 2)]} />
207+
208+
// Disable a range of days
209+
<DayPicker disabled={{ from: new Date(2023, 9, 1), to: new Date(2023, 9, 5) }} />
210+
211+
// Disable a specific day of the week
212+
<DayPicker disabled={{ dayOfWeek: [0, 6] }} /> // disable weekends
213+
214+
// Disable days before a specific date
215+
<DayPicker disabled={{ before: new Date(2023, 9, 1) }} />
216+
217+
// Disable days after a specific date
218+
<DayPicker disabled={{ after: new Date(2023, 9, 5) }} />
219+
220+
// Disable days between two dates
221+
<DayPicker disabled={{ before: [new Date(2023, 9, 1), after: new Date(2023, 9, 5)] }} />
222+
```
223+
224+
### Disabling Weekends
225+
226+
To disable weekends, use the `dayOfWeek` matcher, where `0` is Sunday and `6` is Saturday.
184227

185228
```tsx
186-
// disable weekends
187-
<DayPicker mode="range" disabled={{ dayOfWeek: [0, 6] }} />
229+
<DayPicker disabled={{ dayOfWeek: [0, 6] }} />
188230
```
189231

190232
<BrowserWindow>
@@ -193,6 +235,8 @@ The prop accepts a [`Matcher`](../api/type-aliases/Matcher.md) or an array of ma
193235

194236
### Disabling Dates in the Past
195237

238+
Use the `before` matcher to disable all dates before today.
239+
196240
```tsx
197241
<DayPicker mode="single" disabled={{ before: new Date() }} />
198242
```

0 commit comments

Comments
 (0)