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 popoverPlacement prop in EuiDatePicker #3359

1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

- Added `showCloseButton` and `dockedBreakpoint` flexibility to `EuiCollapsibleNav` ([#3330](https://github.com/elastic/eui/pull/3330))
- Added `panelStyle` prop to `EuiPopover` to distinguish style object configuration ([#3329](https://github.com/elastic/eui/pull/3329))
- Expose `popperPlacement` prop in `EuiDatePicker` ([#3359](https://github.com/elastic/eui/pull/3359))
elizabetdev marked this conversation as resolved.
Show resolved Hide resolved

**Bug Fixes**

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ exports[`EuiDatePicker is rendered 2`] = `
onMonthChange={[Function]}
onSelect={[Function]}
onYearChange={[Function]}
popperPlacement="bottom-start"
preventOpenOnFocus={false}
previousMonthButtonLabel="Previous Month"
readOnly={false}
Expand Down
10 changes: 10 additions & 0 deletions src/components/date_picker/date_picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ export const euiDatePickerDefaultTimeFormat = 'hh:mm A';

const DatePicker = _ReactDatePicker as typeof ReactDatePicker;

export type EuiDatePickerPopoverPlacement = ReactDatePickerProps['popperPlacement'];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't create a whole new type and export it here. Instead just add this directly to the prop below


interface EuiExtendedDatePickerProps extends ReactDatePickerProps {
/**
* Applies classes to the numbered days provided. Check docs for example.
Expand Down Expand Up @@ -89,6 +91,11 @@ interface EuiExtendedDatePickerProps extends ReactDatePickerProps {
* Show the icon in input
*/
showIcon?: boolean;

/**
* Sets the placement of the popover. It accepts: `"bottom"`, `"bottom-end"`, `"bottom-start"`, `"left"`, `"left-end"`, `"right"`, `"right-end"`, `"right-start"`, `"top"`, `"top-end"`, `"top-start"`
*/
popoverPlacement?: EuiDatePickerPopoverPlacement;
elizabetdev marked this conversation as resolved.
Show resolved Hide resolved
}

type _EuiDatePickerProps = CommonProps & EuiExtendedDatePickerProps;
Expand All @@ -109,6 +116,7 @@ export class EuiDatePicker extends Component<_EuiDatePickerProps> {
showIcon: true,
showTimeSelect: false,
timeFormat: euiDatePickerDefaultTimeFormat,
popoverPlacement: 'bottom-start',
};

render() {
Expand Down Expand Up @@ -138,6 +146,7 @@ export class EuiDatePicker extends Component<_EuiDatePickerProps> {
openToDate,
placeholder,
popperClassName,
popoverPlacement,
selected,
shadow,
shouldCloseOnSelect,
Expand Down Expand Up @@ -262,6 +271,7 @@ export class EuiDatePicker extends Component<_EuiDatePickerProps> {
utcOffset={utcOffset}
yearDropdownItemNumber={7}
accessibleMode
popperPlacement={popoverPlacement}
{...rest}
/>
);
Expand Down
1 change: 1 addition & 0 deletions src/components/date_picker/date_picker_range.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ export const EuiDatePickerRange: FunctionComponent<EuiDatePickerRangeProps> = ({
showIcon: false,
fullWidth: fullWidth,
readOnly: readOnly,
popoverPlacement: 'bottom-end',
}
);
}
Expand Down
15 changes: 14 additions & 1 deletion src/components/date_picker/react-datepicker.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@
import * as React from 'react';
import * as moment from 'moment';

type popperPlacement =
| 'bottom'
| 'bottom-end'
| 'bottom-start'
Comment on lines +36 to +39
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

| 'left'
| 'left-end'
| 'right'
| 'right-end'
| 'right-start'
| 'top'
| 'top-end'
| 'top-start';

export interface ReactDatePickerProps {
/**
* Whether changes to Year and Month (via dropdowns) should trigger `onChange`
Expand Down Expand Up @@ -144,7 +157,7 @@ export interface ReactDatePickerProps {
*/
popperClassName?: string;
popperContainer?(props: { children: React.ReactNode[] }): React.ReactNode;
popperPlacement?: string;
popperPlacement?: popperPlacement;
preventOpenOnFocus?: boolean;
readOnly?: boolean;
required?: boolean;
Expand Down