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

Add "Boundaries" to RangePicker (do not accept ranges that include disabled dates) #22912

Closed
1 task done
rlue opened this issue Apr 3, 2020 · 5 comments
Closed
1 task done
Labels

Comments

@rlue
Copy link

rlue commented Apr 3, 2020

  • I have searched the issues of this repository and believe that this is not a duplicate.

What problem does this feature solve?

I'm looking for a way to make sure a whole set of RangePicker inputs don't contain any overlapping dates.

The application asks users to enter, e.g., to list all of their primary residences over the past ten years. The component should be able to impose a restraint like the one below on user input:

# Valid
Sydney Jan 2012–Feb 2012
Berlin Mar 2012–Aug 2016

# Invalid
Sydney Jan 2012–Jun 2019
Berlin Mar 2012–Aug 2016

AFAICT, this is currently impossible with the RangePicker. Please see the CodeSandbox here for an illustration of the problem: today's date is disabled, but it's perfectly valid to select the range spanning from yesterday until tomorrow.

What does the proposed API look like?

function disabledDate(current) {
  return current && stints.some((stint) => current.isBetween(stint.start, stint.end))
}

<DatePicker.RangePicker
  disabledDate={disabledDate}
  boundedByDisabledDates // or hardBoundaries etc.
/>

Or perhaps this should just be the default behavior for disabled dates, and you should have to explicitly allow selections that include them?

@zombieJ
Copy link
Member

zombieJ commented Apr 6, 2020

Your codesandbox is empty.

@rlue
Copy link
Author

rlue commented Apr 6, 2020

Whoops! Thought it would save automatically. Should be fixed now.

@afc163 afc163 added the 🤔 Need Reproduce We cannot reproduce your problem label Jan 21, 2022
@github-actions

This comment was marked as off-topic.

@rlue
Copy link
Author

rlue commented Jan 21, 2022

@afc163, 請注意這個 issue 本來就有重現實例:

AFAICT, this is currently impossible with the RangePicker. Please see the CodeSandbox here for an illustration of the problem: today's date is disabled, but it's perfectly valid to select the range spanning from yesterday until tomorrow.

@zombieJ
Copy link
Member

zombieJ commented Feb 20, 2024

In latest version, disabledDate provides the from date of user selection which can help on the customize boundaries logic:

// Fake Code Sample
<RangePicker
  disabledDate={(date, { from }) => {
    if (!from) return false;

    if (from < 2024-05-05) {
      return date >= 2024-05-05;
    }
    
    return date < 2024-05-05;
  }}
/>

ref demo: https://ant.design/components/date-picker#components-date-picker-demo-select-in-range

@zombieJ zombieJ closed this as completed Feb 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants