-
-
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
Fixes issues with displayFormat prop's default values by using a thunk #98
Fixes issues with displayFormat prop's default values by using a thunk #98
Conversation
15201e2
to
bd9f6d8
Compare
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.
LGTM but the comments might be some nice improvements
@@ -138,7 +138,9 @@ export default class DateRangePicker extends React.Component { | |||
|
|||
onEndDateChange(endDateString) { | |||
const { startDate, isOutsideRange, onDatesChange, onFocusChange, displayFormat } = this.props; | |||
const endDate = toMomentObject(endDateString, displayFormat); | |||
|
|||
const formatString = typeof displayFormat === 'function' ? displayFormat() : displayFormat; |
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.
the propTypes help ensure it's only a string or function, but perhaps it would be more robust (ie, fail faster when it's not a func or string) if this did typeof displayFormat === 'string' ? displayFormat : displayFormat();
?
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.
Okay. I wasn't sure if it made more sense to have it fail abruptly in this way or fail silently, but still function, in the other. I can change it to the former.
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.
i'm a big fan of failing fast and loud
@@ -175,7 +177,8 @@ export default class DateRangePicker extends React.Component { | |||
|
|||
onStartDateChange(startDateString) { | |||
const { displayFormat } = this.props; | |||
const startDate = toMomentObject(startDateString, displayFormat); | |||
const formatString = typeof displayFormat === 'function' ? displayFormat() : displayFormat; |
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.
also here. should this logic be consolidated into a helper function?
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.
Yes
@@ -203,8 +206,9 @@ export default class DateRangePicker extends React.Component { | |||
|
|||
getDateString(date) { | |||
const { displayFormat } = this.props; | |||
if (date && displayFormat) { | |||
return date && date.format(displayFormat); | |||
const formatString = typeof displayFormat === 'function' ? displayFormat() : displayFormat; |
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.
^_^
@@ -68,7 +68,8 @@ export default class SingleDatePicker extends React.Component { | |||
|
|||
onChange(dateString) { | |||
const { displayFormat, isOutsideRange, onDateChange, onFocusChange } = this.props; | |||
const date = toMomentObject(dateString, displayFormat); | |||
const formatString = typeof displayFormat === 'function' ? displayFormat() : displayFormat; |
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.
ᕕ( ᐛ )ᕗ
@@ -114,8 +115,9 @@ export default class SingleDatePicker extends React.Component { | |||
|
|||
getDateString(date) { | |||
const { displayFormat } = this.props; | |||
if (date && displayFormat) { | |||
return date && date.format(displayFormat); | |||
const formatString = typeof displayFormat === 'function' ? displayFormat() : displayFormat; |
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.
there's a lot of these :-p
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.
Lol
bd9f6d8
to
cea7d28
Compare
to: @ljharb
When attempting to bump the version of
react-dates
used on Airbnb, we noticed that the display format for theDateRangePicker
andSingleDatePicker
components was often returning nonsense because moment's locale was not yet set. Similarly, live right now on the storybook, you can see that the format doesn't work at all for the non-english locale example. This fixes this issue.