| 1 |
--- |
| 2 |
id: Date picker |
| 3 |
section: components |
| 4 |
subsection: date-and-time |
| 5 |
--- |
| 6 |
|
| 7 |
import { Fragment, useRef, useState } from 'react'; |
| 8 |
import { Modal as ModalDeprecated, ModalVariant as ModalVariantDeprecated } from '@patternfly/react-core/deprecated'; |
| 9 |
|
| 10 |
## Demos |
| 11 |
|
| 12 |
### Date range picker |
| 13 |
|
| 14 |
This is intended to be used as a filter. After selecting a start date, the next date is automatically selected. |
| 15 |
|
| 16 |
```ts file="./examples/DatePickerRange.tsx" |
| 17 |
``` |
| 18 |
|
| 19 |
### Date and time pickers in modal |
| 20 |
|
| 21 |
Modals trap focus and watch a few document level events. In order to place a date picker in a modal: |
| 22 |
|
| 23 |
- To avoid the modal's escape press event handler from overruling the date picker's escape press handlers, use the `DatePickerRef` to close the calendar when it is open and the escape key is pressed. |
| 24 |
- Append the calendar to the modal to keep it as close to the date picker in the DOM while maintaining correct layouts visually |
| 25 |
In order to place a time picker in the modal, its menu must be appended to the time picker's parent. |
| 26 |
|
| 27 |
```ts file="./examples/DateTimePickerInModal.tsx" |
| 28 |
|
| 29 |
``` |