-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add initialVisibleMonth fn prop to DayPicker #70
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,6 @@ instrumentation: | |
check: | ||
global: | ||
statements: 89 | ||
branches: 70 | ||
branches: 69 | ||
lines: 91 | ||
functions: 79 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,7 @@ const defaultProps = { | |
showClearDates: false, | ||
disabled: false, | ||
reopenPickerOnClearDates: false, | ||
initialVisibleMonth: () => moment(), | ||
|
||
orientation: HORIZONTAL_ORIENTATION, | ||
withPortal: false, | ||
|
@@ -330,6 +331,8 @@ export default class DateRangePicker extends React.Component { | |
withPortal, | ||
withFullScreenPortal, | ||
enableOutsideDays, | ||
initialVisibleMonth, | ||
focusedInput, | ||
} = this.props; | ||
|
||
const modifiers = { | ||
|
@@ -370,6 +373,8 @@ export default class DateRangePicker extends React.Component { | |
onNextMonthClick={onNextMonthClick} | ||
monthFormat={monthFormat} | ||
withPortal={withPortal || withFullScreenPortal} | ||
hidden={!focusedInput} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we change this name to I think once we move to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. :( unfortunately I had it named as visible before but @ljharb asked to change it to be hidden so we didn't have a boolean prop that defaulted to true. Let me know what you would prefer now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Man, I should really have read @ljharb's comments more carefully before. :) |
||
initialVisibleMonth={initialVisibleMonth} | ||
onOutsideClick={onOutsideClick} | ||
/> | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,8 @@ const propTypes = { | |
modifiers: PropTypes.object, | ||
orientation: OrientationShape, | ||
withPortal: PropTypes.bool, | ||
hidden: PropTypes.bool, | ||
initialVisibleMonth: PropTypes.func, | ||
onDayClick: PropTypes.func, | ||
onDayMouseDown: PropTypes.func, | ||
onDayMouseUp: PropTypes.func, | ||
|
@@ -52,6 +54,8 @@ const defaultProps = { | |
modifiers: {}, | ||
orientation: HORIZONTAL_ORIENTATION, | ||
withPortal: false, | ||
hidden: false, | ||
initialVisibleMonth: () => moment(), | ||
onDayClick() {}, | ||
onDayMouseDown() {}, | ||
onDayMouseUp() {}, | ||
|
@@ -71,8 +75,10 @@ const defaultProps = { | |
export default class DayPicker extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
|
||
this.hasSetInitialVisibleMonth = !props.hidden; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similarly I don't think we need the |
||
this.state = { | ||
currentMonth: moment(), | ||
currentMonth: props.hidden ? moment() : props.initialVisibleMonth(), | ||
monthTransition: null, | ||
translationValue: 0, | ||
}; | ||
|
@@ -89,6 +95,15 @@ export default class DayPicker extends React.Component { | |
} | ||
} | ||
|
||
componentWillReceiveProps(nextProps) { | ||
if (!this.hasSetInitialVisibleMonth && !nextProps.hidden) { | ||
this.hasSetInitialVisibleMonth = true; | ||
this.setState({ | ||
currentMonth: nextProps.initialVisibleMonth(), | ||
}); | ||
} | ||
} | ||
|
||
shouldComponentUpdate(nextProps, nextState) { | ||
return shallowCompare(this, nextProps, nextState); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,8 @@ const defaultProps = { | |
orientation: HORIZONTAL_ORIENTATION, | ||
withPortal: false, | ||
withFullScreenPortal: false, | ||
initialVisibleMonth: () => moment(), | ||
|
||
|
||
onPrevMonthClick() {}, | ||
onNextMonthClick() {}, | ||
|
@@ -181,6 +183,8 @@ export default class SingleDatePicker extends React.Component { | |
onNextMonthClick, | ||
withPortal, | ||
withFullScreenPortal, | ||
focused, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. propType and defaultProp for this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a pre-existing prop on the SDP @ljharb |
||
initialVisibleMonth, | ||
} = this.props; | ||
|
||
const modifiers = { | ||
|
@@ -209,6 +213,8 @@ export default class SingleDatePicker extends React.Component { | |
onNextMonthClick={onNextMonthClick} | ||
monthFormat={monthFormat} | ||
withPortal={withPortal || withFullScreenPortal} | ||
hidden={!focused} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same, let's name this as |
||
initialVisibleMonth={initialVisibleMonth} | ||
onOutsideClick={onOutsideClick} | ||
/> | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
inline with #70 (comment), updating coverage requirements