Skip to content
This repository was archived by the owner on May 19, 2025. It is now read-only.

Commit 4705532

Browse files
committed
Rename preventUnnecessaryRefocus -> preventSnapRefocus & remove redundant arg to differenceInCalendarMonths
1 parent 24a416c commit 4705532

File tree

3 files changed

+7
-11
lines changed

3 files changed

+7
-11
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ showPreview(DateRange) | bool | true | visibility
128128
editableDateInputs(Calendar) | bool | false | whether dates can be edited in the Calendar's input fields
129129
dragSelectionEnabled(Calendar) | bool | true | whether dates can be selected via drag n drop
130130
calendarFocus(Calendar) | String | 'forwards' | Whether calendar focus month should be forward-driven or backwards-driven. can be 'forwards' or 'backwards'
131-
preventUnnecessaryRefocus(Calendar) | bool | false | prevents unneceessary refocus of shown range on selection
131+
preventSnapRefocus(Calendar) | bool | false | prevents unneceessary refocus of shown range on selection
132132
onPreviewChange(DateRange) | Object | | Callback function for preview changes
133133
dateDisplayFormat | String | `MMM d, yyyy` | selected range preview formatter. Check out [date-fns's format option](https://date-fns.org/docs/format)
134134
dayDisplayFormat | String | `d` | selected range preview formatter. Check out [date-fns's format option](https://date-fns.org/docs/format)

src/components/Calendar/index.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,8 @@ class Calendar extends PureComponent {
7878
}
7979
focusToDate = (date, props = this.props, preventUnnecessary = true) => {
8080
if (!props.scroll.enabled) {
81-
if (preventUnnecessary && props.preventUnnecessaryRefocus) {
82-
const focusedDateDiff = differenceInCalendarMonths(
83-
date,
84-
this.state.focusedDate,
85-
this.dateOptions
86-
);
81+
if (preventUnnecessary && props.preventSnapRefocus) {
82+
const focusedDateDiff = differenceInCalendarMonths(date, this.state.focusedDate);
8783
const isAllowedForward = props.calendarFocus === 'forwards' && focusedDateDiff >= 0;
8884
const isAllowedBackward = props.calendarFocus === 'backwards' && focusedDateDiff <= 0;
8985
if ((isAllowedForward || isAllowedBackward) && Math.abs(focusedDateDiff) < props.months) {
@@ -561,7 +557,7 @@ Calendar.defaultProps = {
561557
dragSelectionEnabled: true,
562558
fixedHeight: false,
563559
calendarFocus: 'forwards',
564-
preventUnnecessaryRefocus: false,
560+
preventSnapRefocus: false,
565561
ariaLabels: {},
566562
};
567563

@@ -617,7 +613,7 @@ Calendar.propTypes = {
617613
dragSelectionEnabled: PropTypes.bool,
618614
fixedHeight: PropTypes.bool,
619615
calendarFocus: PropTypes.string,
620-
preventUnnecessaryRefocus: PropTypes.bool,
616+
preventSnapRefocus: PropTypes.bool,
621617
ariaLabels: ariaLabelsShape,
622618
};
623619

src/components/DateRangePicker/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const [state, setState] = useState([
2424
/>;
2525
```
2626

27-
#### Example: Backwards 2 Month View with preventUnnecessaryRefocus
27+
#### Example: Backwards 2 Month View with preventSnapRefocus
2828

2929
```jsx inside Markdown
3030
import { addDays } from 'date-fns';
@@ -45,7 +45,7 @@ const [state, setState] = useState([
4545
months={2}
4646
ranges={state}
4747
direction="horizontal"
48-
preventUnnecessaryRefocus={true}
48+
preventSnapRefocus={true}
4949
calendarFocus="backwards"
5050
/>;
5151
```

0 commit comments

Comments
 (0)