This repository was archived by the owner on May 19, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +32
-1
lines changed
Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -102,7 +102,7 @@ class DateRange extends Component {
102102 }
103103 const { rangeColors, ranges } = this . props ;
104104 const focusedRange = this . props . focusedRange || this . state . focusedRange ;
105- const color = ranges [ focusedRange [ 0 ] ] . color || rangeColors [ focusedRange [ 0 ] ] || color ;
105+ const color = ranges [ focusedRange [ 0 ] ] ? .color || rangeColors [ focusedRange [ 0 ] ] || color ;
106106 this . setState ( { preview : { ...val . range , color } } ) ;
107107 } ;
108108 render ( ) {
Original file line number Diff line number Diff line change @@ -189,3 +189,34 @@ function customDayContent(day) {
189189 }}
190190/ > ;
191191```
192+
193+
194+ #### Example: Restrict Date Selection
195+ Restricts access for range selection to (-30, +30) days of current date.
196+ ``` jsx inside Markdown
197+ import { addDays } from ' date-fns' ;
198+ import { useState } from ' react' ;
199+
200+ const [state , setState ] = useState ({
201+ selection: {
202+ startDate: new Date (),
203+ endDate: null ,
204+ key: ' selection'
205+ },
206+ compare: {
207+ startDate: new Date (),
208+ endDate: addDays (new Date (), 3 ),
209+ key: ' compare'
210+ }
211+ });
212+
213+ < DateRangePicker
214+ onChange= {item => setState ({ ... state, ... item })}
215+ months= {1 }
216+ minDate= {addDays (new Date (), - 30 )}
217+ maxDate= {addDays (new Date (), 30 )}
218+ direction= " vertical"
219+ scroll= {{ enabled: true }}
220+ ranges= {[state .selection , state .compare ]}
221+ / > ;
222+ ```
You can’t perform that action at this time.
0 commit comments