Skip to content

Commit

Permalink
Merge pull request wix#1618 from wix/feat/allowSelectionOutOfRange
Browse files Browse the repository at this point in the history
Add allowSelectionOutOfRange prop to Calendar
  • Loading branch information
ethanshar authored Aug 30, 2021
2 parents 8fb1fc0 + be63a34 commit d5c8e85
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/calendar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ export interface CalendarProps extends CalendarHeaderProps, DayProps {
headerStyle?: ViewStyle;
/** Allow rendering of a totally custom header */
customHeader?: any;
/** Allow selection of dates before minDate or after maxDate */
allowSelectionOutOfRange?: boolean;
}

interface CalendarState {
Expand Down Expand Up @@ -126,7 +128,9 @@ class Calendar extends Component<CalendarProps, CalendarState> {
/** Style passed to the header */
headerStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.number, PropTypes.array]),
/** Allow rendering of a totally custom header */
customHeader: PropTypes.any
customHeader: PropTypes.any,
/** Allow selection of dates before minDate or after maxDate */
allowSelectionOutOfRange: PropTypes.bool
};
static defaultProps = {
enableSwipeMonths: false
Expand Down Expand Up @@ -157,12 +161,12 @@ class Calendar extends Component<CalendarProps, CalendarState> {
};

handleDayInteraction(date: Date, interaction?: (date: DateData) => void) {
const {disableMonthChange} = this.props;
const {disableMonthChange, allowSelectionOutOfRange} = this.props;
const day = parseDate(date);
const minDate = parseDate(this.props.minDate);
const maxDate = parseDate(this.props.maxDate);

if (!(minDate && !isGTE(day, minDate)) && !(maxDate && !isLTE(day, maxDate))) {
if (allowSelectionOutOfRange || !(minDate && !isGTE(day, minDate)) && !(maxDate && !isLTE(day, maxDate))) {
const shouldUpdateMonth = disableMonthChange === undefined || !disableMonthChange;

if (shouldUpdateMonth) {
Expand Down

0 comments on commit d5c8e85

Please sign in to comment.