-
-
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
Fix for the issue of selectively disabling start or end date #606
Conversation
@@ -41,6 +41,7 @@ const propTypes = forbidExtraProps({ | |||
isEndDateFocused: PropTypes.bool, | |||
showClearDates: PropTypes.bool, | |||
disabled: PropTypes.bool, | |||
selectivelyDisabled: PropTypes.string, |
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.
instead of a string, let's use PropTypes.oneOf(['none', 'startDate', 'endDate'])
, and let's have that be imported from the same shared module.
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.
@ljharb what do you think about instead providing two boolean props, disableStart
and disableEnd
?
It might make the logic a little easier for users. Rather than
let selectivelyDisabled;
if (condition1) {
selectivelyDisabled = 'startDate';
}
if (condition2) {
selectivelyDisabled = 'endDate';
}
<DatePicker selectivelyDisabled={selectivelyDisabled}/>
it could be
<DatePicker disableStart={condition1} disableEnd={condition2}/>
Would also simplify the other code a bit as well.
I guess a potential gotcha would be that behavior of <DatePicker disableStart disableEnd/>
would probably need to be identical to <DatePicker disabled/>
.
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.
Generally we've been moving in the direction, for > 2-state props, of having a single enum prop instead of multiple boolean props. (With your suggestion, we'd want to specify a mutuallyExclusiveTrueProp
propType to prevent both from being true anyways)
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 have made the changes as suggested.Have a look
Is there anything I can do to help get this merged? It would be very useful for a project I'm currently working on. |
If you'd like to take over this PR @dart-wakar, that would be great. I think that I'd personally prefer to roll this functionality up into the disabled prop and have it be able to be equal to what do you think @ljharb? i know you had some comments on the original PR. |
I agree on constants; but I’m hesitant to roll up more meaning into an existing prop - but maybe it makes sense here for “disabled”. If @ajwild or anyone else wants to update this PR, please comment here with a link to your branch and we can pull in the commits and rebase for you (rather than making a new PR). |
@majapw @ljharb I've added a commit to the master branch of my fork: https://github.com/ajwild/react-dates I had to pass through the disabled property from It's also necessary to provide an Let me know if there's anything else required once you've had a chance to review/test it. |
Awesome @ajwild I'll pull it into this branch and take a look. Thank you for the work! Can you clarify a bit about what you mean here? I'm not sure I understand.
|
@@ -117,7 +117,7 @@ The following is a list of other *OPTIONAL* props you may provide to the `DateRa | |||
// input related props | |||
startDatePlaceholderText: PropTypes.string, | |||
endDatePlaceholderText: PropTypes.string, | |||
disabled: PropTypes.bool, | |||
disabled: PropTypes.oneOfType([PropTypes.bool, PropTypes.oneOf([START_DATE, END_DATE])]), |
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.
We could probably pull this out into its own variable
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.
Should I reference it from "DateRangePickerShape.js" in the three other locations it is used, and leave it as it is (or simplify it) here in the readme?
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 cleaned it up! :P But left it in the README for clarity.
Ah @ajwild you are right. I think we want to leave it up to the developer to block out days when disabling if that's the UI they want. I don't think we should make any attempt to mess with it automagically. |
#593
The above mentioned issue is fixed by introducing a new prop into the DateRangePicker component: selectivelyDisable. selectivelyDisable is a string proptype,which is none by default,but if defined as 'startDate' in DateRangePickerWrapper it disables the start-date and so is the case with end-date.