Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ Name | Type | Required | Default value | Description
`definedRanges` | `DefinedRange[]` | _optional_ | - | custom defined ranges to show in the list
`closeOnClickOutside` | `boolean` | _optional_ | `true` | defines if DateRangePicker will be closed when clicking outside of it
`wrapperClassName` | `object` | _optional_ | `undefined` | defines additional wrapper style classes
`MenuProps` | `object` | _optional_ | `{disablePortal: true}` | defines props to be passed to the nested Select component - needed for use with Popper

## Made possible by

Expand Down
8 changes: 7 additions & 1 deletion package/src/components/DateRangePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
import { DateRange, NavigationAction, DefinedRange } from '../types';
import { getValidatedMonths, parseOptionalDate } from '../utils';

import { defaultRanges } from '../defaults';
import { defaultRanges, defaultMenuProps } from '../defaults';

import Menu from './Menu';

Expand All @@ -36,6 +36,10 @@ interface DateRangePickerProps {
minDate?: Date | string;
maxDate?: Date | string;
onChange: (dateRange: DateRange) => void;
MenuProps?: {
disablePortal: boolean,
anchorEl?: Node
}
}

const DateRangePicker: React.FunctionComponent<DateRangePickerProps> = (
Expand All @@ -50,6 +54,7 @@ const DateRangePicker: React.FunctionComponent<DateRangePickerProps> = (
minDate,
maxDate,
definedRanges = defaultRanges,
MenuProps = defaultMenuProps,
} = props;

const minDateValid = parseOptionalDate(minDate, addYears(today, -10));
Expand Down Expand Up @@ -164,6 +169,7 @@ const DateRangePicker: React.FunctionComponent<DateRangePickerProps> = (
setDateRange={setDateRangeValidated}
helpers={helpers}
handlers={handlers}
MenuProps={MenuProps}
/>
) : null;
};
Expand Down
4 changes: 4 additions & 0 deletions package/src/components/DateRangePickerWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ export interface DateRangePickerWrapperProps {
onChange: (dateRange: DateRange) => void;
closeOnClickOutside?: boolean;
wrapperClassName?: string;
MenuProps?: {
disablePortal: boolean,
anchorEl?: Node
};
}

const DateRangePickerWrapper: React.FunctionComponent<DateRangePickerWrapperProps> = (
Expand Down
6 changes: 4 additions & 2 deletions package/src/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ interface HeaderProps {
prevDisabled: boolean;
onClickNext: () => void;
onClickPrevious: () => void;
MenuProps: object
}

const MONTHS = [
Expand Down Expand Up @@ -67,6 +68,7 @@ const Header: React.FunctionComponent<HeaderProps> = ({
prevDisabled,
onClickNext,
onClickPrevious,
MenuProps,
}: HeaderProps) => {
const classes = useStyles();

Expand All @@ -93,7 +95,7 @@ const Header: React.FunctionComponent<HeaderProps> = ({
<Select
value={getMonth(date)}
onChange={handleMonthChange}
MenuProps={{ disablePortal: true }}
MenuProps={MenuProps}
>
{MONTHS.map((month, idx) => (
<MenuItem key={month} value={idx}>
Expand All @@ -107,7 +109,7 @@ const Header: React.FunctionComponent<HeaderProps> = ({
<Select
value={getYear(date)}
onChange={handleYearChange}
MenuProps={{ disablePortal: true }}
MenuProps={MenuProps}
>
{generateYears(date, 30).map((year) => (
<MenuItem key={year} value={year}>
Expand Down
7 changes: 6 additions & 1 deletion package/src/components/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ interface MenuProps {
onDayHover: (day: Date) => void;
onMonthNavigate: (marker: symbol, action: NavigationAction) => void;
};
MenuProps: {
disablePortal: boolean,
anchorEl?: Node
}
}

const Menu: React.FunctionComponent<MenuProps> = (props: MenuProps) => {
Expand All @@ -73,12 +77,13 @@ const Menu: React.FunctionComponent<MenuProps> = (props: MenuProps) => {
setDateRange,
helpers,
handlers,
MenuProps,
} = props;

const { startDate, endDate } = dateRange;
const canNavigateCloser = differenceInCalendarMonths(secondMonth, firstMonth) >= 2;
const commonProps = {
dateRange, minDate, maxDate, helpers, handlers,
dateRange, minDate, maxDate, helpers, handlers, MenuProps,
};
return (
<Paper elevation={5} square>
Expand Down
7 changes: 6 additions & 1 deletion package/src/components/Month.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {
import Header from './Header';
import Day from './Day';


// eslint-disable-next-line no-unused-vars
import { NavigationAction, DateRange } from '../types';

Expand Down Expand Up @@ -62,6 +61,10 @@ interface MonthProps {
onDayHover: (day: Date) => void;
onMonthNavigate: (marker: symbol, action: NavigationAction) => void;
};
MenuProps: {
disablePortal: boolean,
anchorEl?: Node
}
}

const Month: React.FunctionComponent<MonthProps> = (props: MonthProps) => {
Expand All @@ -76,6 +79,7 @@ const Month: React.FunctionComponent<MonthProps> = (props: MonthProps) => {
setValue: setDate,
minDate,
maxDate,
MenuProps,
} = props;

// eslint-disable-next-line react/destructuring-assignment
Expand All @@ -91,6 +95,7 @@ const Month: React.FunctionComponent<MonthProps> = (props: MonthProps) => {
prevDisabled={!back}
onClickPrevious={() => handlers.onMonthNavigate(marker, NavigationAction.Previous)}
onClickNext={() => handlers.onMonthNavigate(marker, NavigationAction.Next)}
MenuProps={MenuProps}
/>

<Grid
Expand Down
4 changes: 4 additions & 0 deletions package/src/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,8 @@ const getDefaultRanges = (date: Date): DefinedRange[] => [
},
];

export const defaultMenuProps = {
disablePortal: true,
};

export const defaultRanges = getDefaultRanges(new Date());