|
1 | | -import React, { useState } from 'react'; |
| 1 | +import React, { useRef, useState } from 'react'; |
2 | 2 | import DatePicker from 'react-date-picker/src/entry.nostyle'; |
3 | 3 | import 'react-date-picker/src/DatePicker.less'; |
4 | 4 | import 'react-calendar/dist/Calendar.css'; |
@@ -35,12 +35,14 @@ const nineteenNinetyFive = new Date(1995, now.getUTCMonth() + 1, 15, 12); |
35 | 35 | const fifteenthOfNextMonth = new Date(now.getUTCFullYear(), now.getUTCMonth() + 1, 15, 12); |
36 | 36 |
|
37 | 37 | export default function Test() { |
| 38 | + const portalContainer = useRef(); |
38 | 39 | const [disabled, setDisabled] = useState(false); |
39 | 40 | const [locale, setLocale] = useState(null); |
40 | 41 | const [maxDate, setMaxDate] = useState(fifteenthOfNextMonth); |
41 | 42 | const [maxDetail, setMaxDetail] = useState('month'); |
42 | 43 | const [minDate, setMinDate] = useState(nineteenNinetyFive); |
43 | 44 | const [minDetail, setMinDetail] = useState('century'); |
| 45 | + const [renderInPortal, setRenderInPortal] = useState(false); |
44 | 46 | const [returnValue /* , setReturnValue */] = useState('start'); |
45 | 47 | const [required, setRequired] = useState(true); |
46 | 48 | const [showLeadingZeros, setShowLeadingZeros] = useState(true); |
@@ -77,7 +79,9 @@ export default function Test() { |
77 | 79 | <ValueOptions setValue={setValue} value={value} /> |
78 | 80 | <ViewOptions |
79 | 81 | disabled={disabled} |
| 82 | + renderInPortal={renderInPortal} |
80 | 83 | setDisabled={setDisabled} |
| 84 | + setRenderInPortal={setRenderInPortal} |
81 | 85 | setShowLeadingZeros={setShowLeadingZeros} |
82 | 86 | setShowNeighboringMonth={setShowNeighboringMonth} |
83 | 87 | setShowWeekNumbers={setShowWeekNumbers} |
@@ -110,13 +114,15 @@ export default function Test() { |
110 | 114 | onCalendarClose={() => console.log('Calendar closed')} |
111 | 115 | onCalendarOpen={() => console.log('Calendar opened')} |
112 | 116 | onChange={setValue} |
| 117 | + portalContainer={renderInPortal ? portalContainer.current : undefined} |
113 | 118 | required={required} |
114 | 119 | returnValue={returnValue} |
115 | 120 | showLeadingZeros={showLeadingZeros} |
116 | 121 | showNeighboringMonth={showNeighboringMonth} |
117 | 122 | showWeekNumbers={showWeekNumbers} |
118 | 123 | value={value} |
119 | 124 | /> |
| 125 | + <div ref={portalContainer} /> |
120 | 126 | <br /> |
121 | 127 | <br /> |
122 | 128 | <button id="submit" type="submit"> |
|
0 commit comments