Skip to content
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

feat(DatePicker): make onChange and value required #437

Merged
merged 4 commits into from
Apr 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/components/Datepicker/Datepicker.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -385,10 +385,23 @@ DatePicker.propTypes = {
PropTypes.object,
PropTypes.number,
]),
value: PropTypes.oneOfType([PropTypes.array, PropTypes.object]),
value: PropTypes.oneOfType([PropTypes.array, PropTypes.object]).isRequired,
isRange: PropTypes.bool,
lang: PropTypes.oneOfType([PropTypes.array, PropTypes.object]),
onChange: PropTypes.func,
onChange: function (props, propName) {
var fn = props[propName];
if (
!fn ||
!fn.prototype ||
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when onChange is null or undefined, the error message is:

Warning: Failed prop type: Cannot read properties of undefined (reading 'prototype')

I think we should also display the ... must be a function with 2 (if isMonthsMode is on) or 3 args. Args are: year, month and day. error.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, will add that. thanks!

typeof fn.prototype.constructor !== "function" ||
fn.prototype.constructor.length < 2 ||
fn.prototype.constructor.length > 3
) {
return new Error(
`${propName} must be a function with 2 (if isMonthsMode is on) or 3 args. Args are: year, month and day.`
);
}
},
onYearChange: PropTypes.func,
onShow: PropTypes.func,
onDismiss: PropTypes.func,
Expand All @@ -401,7 +414,6 @@ DatePicker.propTypes = {

DatePicker.defaultProps = {
years: getYearsByNum(5),
onChange(year, month, idx) {},
show: false,
isMonthsMode: false,
isRange: false,
Expand Down