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

Fix for the issue of selectively disabling start or end date #606

Merged
merged 6 commits into from
Apr 5, 2018

Conversation

dart-wakar
Copy link
Contributor

#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.

@@ -41,6 +41,7 @@ const propTypes = forbidExtraProps({
isEndDateFocused: PropTypes.bool,
showClearDates: PropTypes.bool,
disabled: PropTypes.bool,
selectivelyDisabled: PropTypes.string,
Copy link
Member

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.

Copy link
Collaborator

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/>.

Copy link
Member

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)

Copy link
Contributor Author

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

@coveralls
Copy link

Coverage Status

Coverage increased (+0.02%) to 86.15% when pulling 43174a7 on dart-wakar:selectiveDisable into 8eca5d0 on airbnb:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.02%) to 86.15% when pulling 43174a7 on dart-wakar:selectiveDisable into 8eca5d0 on airbnb:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.02%) to 86.15% when pulling b958ad3 on dart-wakar:selectiveDisable into 8eca5d0 on airbnb:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.02%) to 86.15% when pulling 6b975bd on dart-wakar:selectiveDisable into 8eca5d0 on airbnb:master.

@coveralls
Copy link

coveralls commented Jun 29, 2017

Coverage Status

Coverage decreased (-0.03%) to 86.457% when pulling 3680f11 on dart-wakar:selectiveDisable into 8d0c96e on airbnb:master.

@ajwild
Copy link
Contributor

ajwild commented Mar 20, 2018

Is there anything I can do to help get this merged? It would be very useful for a project I'm currently working on.

@majapw
Copy link
Collaborator

majapw commented Mar 20, 2018

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 true, false, 'startDate' or 'endDate'. I'd also like to see the prop type definition use the constants instead of hardcoding the strings.

what do you think @ljharb? i know you had some comments on the original PR.

@ljharb
Copy link
Member

ljharb commented Mar 22, 2018

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).

@ajwild
Copy link
Contributor

ajwild commented Mar 26, 2018

@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 DateRangePicker to DayPickerRangeController to avoid updating or focusing on a disabled date when clicking on a calendar date.

It's also necessary to provide an isOutsideRange function to get the blocked-out-of-range CSS classes on the calendar, but the functionality still works without this. I think it would be messy trying to do this by updating the default isOutsideRange function.

Let me know if there's anything else required once you've had a chance to review/test it.

@majapw
Copy link
Collaborator

majapw commented Mar 26, 2018

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.

It's also necessary to provide an isOutsideRange function to get the blocked-out-of-range CSS classes on the calendar, but the functionality still works without this. I think it would be messy trying to do this by updating the default isOutsideRange function.

@ajwild
Copy link
Contributor

ajwild commented Mar 26, 2018

Sorry if I wasn't clear, I was referring to the "greyed-out" effect on the calendar dates.

Here's the code from the stories I added:

  .addWithInfo('disabled start date', () => (
    <DateRangePickerWrapper
      initialStartDate={moment().add(3, 'months')}
      initialEndDate={moment().add(3, 'months').add(10, 'days')}
      disabled="startDate"
      isOutsideRange={day => !isInclusivelyAfterDay(day, moment().add(3, 'months'))}
    />
  ))
  .addWithInfo('disabled end date', () => (
    <DateRangePickerWrapper
      initialStartDate={moment().add(3, 'months')}
      initialEndDate={moment().add(3, 'months').add(10, 'days')}
      disabled="endDate"
      isOutsideRange={day => !isInclusivelyAfterDay(day, moment()) ||
        !isInclusivelyBeforeDay(day, moment().add(3, 'months').add(10, 'days'))}
    />
  ))

A screenshot of the "disabled end date" example without isOutsideRange:
screenshot from 2018-03-26 13 55 53
A screenshot of the "disabled end date" example with isOutsideRange:
screenshot from 2018-03-26 13 56 22

@@ -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])]),
Copy link
Collaborator

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

Copy link
Contributor

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?

Copy link
Collaborator

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.

@majapw
Copy link
Collaborator

majapw commented Apr 5, 2018

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.

@majapw majapw merged commit 0ba2ba4 into react-dates:master Apr 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants