-
Notifications
You must be signed in to change notification settings - Fork 685
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
Enable disabling of certain dates #221
Conversation
i couldn't get the build to work however |
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.
Can you add this to README.md
and CHANGELOG.md
?
demo/src/components/Main.js
Outdated
@@ -72,6 +72,13 @@ export default class Main extends Component { | |||
key: 'selection', | |||
}, | |||
}, | |||
dateRangeWithDisabled: { | |||
selection: { | |||
startDate: new Date(new Date().getTime() + 24 * 60 * 60 * 1000), |
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.
You can use date utils
addDays(new Date(), 3)
src/components/Calendar.js
Outdated
@@ -116,7 +116,7 @@ class Calendar extends PureComponent { | |||
setTimeout(() => this.focusToDate(this.state.focusedDate), 1); | |||
} | |||
} | |||
componentWillReceiveProps(nextProps) { | |||
UNSAFE_componentWillReceiveProps(nextProps) { |
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.
This will break compatibility of older react versions. It's better to remove for a while.
src/components/DateRange.js
Outdated
// reverse dates if startDate before endDate | ||
let hasBeenReversed = false; |
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 keeping a bool for hasBeenReversed
, can you expose a variable like below:
let isStartDateSelected = focusedRange[1] === 0;
// then
if (isBefore(endDate, startDate)) {
isStartDateSelected = !isStartDateSelected;
[startDate, endDate] = [endDate, startDate]; [startDate, endDate] = [endDate, startDate];
}
}
src/components/DateRange.js
Outdated
} else { | ||
const maxDate = new Date(Math.max.apply(null, inValidDatesWithinRange)); | ||
endDate = new Date(maxDate.getTime() - 24 * 60 * 60 * 1000); | ||
} |
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.
It's can be cleaner:
if (isStartDateSelected) {
startDate = addDays(max(disabledDates), 1);
} else {
endDate = addDays(min(disabledDates), -1);
}
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've noticed that this method has some problems. It fails when the first selected date is inbetween two invalid dates.
src/components/DateRange.js
Outdated
@@ -81,14 +102,14 @@ class DateRange extends Component { | |||
this.props.onRangeFocusChange && this.props.onRangeFocusChange(focusedRange); | |||
} | |||
updatePreview(val) { | |||
if (!val) { | |||
if (!val || !val.wasValid) { |
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.
It should still show the preview because when a user clicks the date, It will select the date. Can you remove the preventing of preview disabling?
should be ok now |
Types of changes
Description
disabledDates
props which holds an array of dates to be disabled. These days will be rendered with the disabled props.