-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Date Range with single DatePicker #584
Comments
Yep, it's possible -- you'll need to define your own way of setting |
@rafeememon sweet! thanks for the quick response. How about the hover styling, to show the range. It seems like that is controlled by |
Check out the example on the demo page |
Actually, I don't think we currently support having |
Looking forward for the best solution. |
would love to see this feature too |
I agree, would love to see if someone could diff up a PR. |
probably its better to use https://github.com/airbnb/react-dates :) |
Ok, it's possible through the setting startDate and endDate, but how can I display two dates at one input field? It seems that I can only display one date at one time |
May be it helps someone in the future: Get
|
Recently came across this use-case. This can be implemented as follows:
|
Thanks @vedadeepta for the starting point. This method works perfectly for what I need. Hopefully will help anyone else looking for this. You may want to add additional checks to stop the start date being selected after the end date and vice versa. There's also a workaround for when selecting the same day for start and end date, onChange doesn't fire so I'm leveraging onSelect instead. If anyone knows a better solution for this please add it!
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Seems like need pull request to enable this feature (selectRange props maybe) |
Thanks @DeanHand for your demo 👍 Here's my two cents: a simple range demo, I've pasted only useful stuffs. Hope it'll help someone out there: export function DemoDatePicker() {
// range demo
const [startDate, setStartDate] = useState(null);
const [endDate, setEndDate] = useState(null);
function handleDateChange(date) {
// initial change start by setting the startDate
if (!startDate && !endDate) {
setStartDate(date);
// startDate has been set, set the end date
} else if (startDate && !endDate) {
setEndDate(date);
}
// user is choosing another range => set the start date
// and set the endDate back to null
if (startDate && endDate) {
setStartDate(date);
setEndDate(null);
}
}
return (
<div>
<DatePicker
onChange={(date) => handleDateChange(date)}
selectsStart={true}
selected={startDate}
startDate={startDate}
endDate={endDate}
inline={true}
/>
</div>
);
} |
* add logic for getting date range * transfer prop for it through parents components to children * add logic for getting styles for range * add tests for selectsRange prop * add example of using selectsRange prop to docs-site * refactoring * remove extra code * add tests * add condition check for set same date when selectsRange * refactore and correct test
I wanted to show 2 month calendar on Here is what I did with 2 months shown for Date Range: has the This worked for what I wanted to accomplish. I hope it helps.
|
The issue I am having with the What's the best method for keeping the calendar open until an end date is selected? Is it even possible? Edit: Having a poke around there seems to be a
Edit: Seems like using React.useEffect(() => {
if (!endDate) {
calendar?.current.setOpen(true, true)
}
}, [endDate]) |
suggest using shouldCloseOnSelect to solve this problem @josias-r |
Thank you. That should be the right answer. But seem complex :D :D |
update to verson |
* add logic for getting date range * transfer prop for it through parents components to children * add logic for getting styles for range * add tests for selectsRange prop * add example of using selectsRange prop to docs-site * refactoring * remove extra code * add tests * add condition check for set same date when selectsRange * refactore and correct test
Is this at all possible? The example for date range is exactly the functionality I would want, but it would be best if the user is selecting the range on a single calendar, not through 2 separate inputs.
The text was updated successfully, but these errors were encountered: