You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: website/docs/guides/custom-components.mdx
+76-3Lines changed: 76 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,6 +18,12 @@ You may need to use custom components in advanced applications to:
18
18
- Implement buttons or dropdowns using your own design system components.
19
19
- Wrap an element with another element, like adding a tooltip to a day cell.
20
20
21
+
## Keep accessibility and behavior intact
22
+
23
+
- Always forward the props you receive (including `aria-*`, `tabIndex`, `ref`, and event handlers) to preserve keyboard navigation and screen reader support.
24
+
- Reuse `classNames` and `labels` from `useDayPicker` when rendering built-in elements so modifiers and ARIA text remain correct.
25
+
- Prefer composing around the default components instead of rebuilding behavior like focus management in `DayButton`.
26
+
21
27
When customizing components, familiarize yourself with the [API Reference](../api#components) and the [DayPicker Anatomy](../docs/anatomy.mdx). Ensure you maintain [accessibility](../guides/accessibility.mdx).
22
28
23
29
:::note Custom Components vs Formatters
@@ -42,6 +48,18 @@ Custom components allow you to extend DayPicker beyond just using [formatters](.
|`Nav`|[`NavProps`](../api/functions/Nav.md)| Use provided `onPreviousClick`/`onNextClick`. |
58
+
|`Dropdown`|[`DropdownProps`](../api/functions/Dropdown.md)| Forward `aria-label` and call `onChange` with target. |
59
+
|`Root`|[`RootProps`](../api/functions/Root.md)| Forward `rootRef` when `animate` is enabled. |
60
+
61
+
The `components` prop accepts a **partial** map—pass only the entries you want to override. The legacy `Button` entry is deprecated; prefer `NextMonthButton` and `PreviousMonthButton`.
62
+
45
63
## List of Custom Components
46
64
47
65
| Name | Description |
@@ -71,6 +89,7 @@ Custom components allow you to extend DayPicker beyond just using [formatters](.
71
89
|[`Weekdays`](../api/functions/Weekdays.md)| The row containing the week days. |
72
90
|[`Weeks`](../api/functions/Weeks.md)| The weeks section in the month grid. |
73
91
|[`YearsDropdown`](../api/functions/YearsDropdown.md)| The dropdown with the years. |
92
+
|`Button`| Deprecated: use `NextMonthButton`/`PreviousMonthButton`. |
74
93
75
94
## DayPicker Hook
76
95
@@ -160,14 +179,39 @@ export function MyDatePicker() {
160
179
<Examples.CustomDayButton />
161
180
</BrowserWindow>
162
181
182
+
### Compose with the defaults
183
+
184
+
When you want to add UI but keep the built-in behavior (focus, labels, modifier classes), wrap the default component from context.
You can use a custom [Dropdown](../api/functions/Dropdown.md) to select years and months. The example below uses a simplified version of `shadcn/ui`'s [Select](https://ui.shadcn.com/docs/components/select).
@@ -237,4 +281,33 @@ export function CustomDropdown() {
237
281
<Examples.CustomDropdown />
238
282
</BrowserWindow>
239
283
284
+
If your design system portals dropdown content, provide the container (as shown in `examples/CustomDropdown/CustomDropdown.tsx`) so the list renders inside the calendar's shadow root in the docs.
285
+
286
+
### Structural customization
287
+
288
+
Swap layout components to add design-system wrappers or decoration while keeping behavior.
0 commit comments