Skip to content
Merged
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
5 changes: 5 additions & 0 deletions packages/eui/changelogs/upcoming/7987.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- Updated `EuiDatePicker` to support `append` and `prepend` nodes in its form control layout

**Bug fixes**

- Fixed border rendering bug with inline `EuiDatePicker`s with `shadow={false}`
6 changes: 3 additions & 3 deletions packages/eui/src-docs/src/views/date_picker/states.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ export default () => {

return (
/* DisplayToggles wrapper for Docs only */
<div>
<DisplayToggles>
<>
<DisplayToggles canPrepend={true} canAppend={true}>
<EuiDatePicker
showTimeSelect
selected={startDate}
Expand Down Expand Up @@ -52,6 +52,6 @@ export default () => {
placeholder="Example of an error"
/>
</EuiFormRow>
</div>
</>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ const meta: Meta<EuiDatePickerProps> = {
isInvalid: false,
isLoading: false,
placeholder: '',
append: '',
prepend: '',
// manually adding non-resolved prop types (extended from react-date-picker)
calendarClassName: '',
customInput: undefined,
Expand Down
11 changes: 10 additions & 1 deletion packages/eui/src/components/date_picker/date_picker.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const euiDatePickerStyles = (euiThemeContext: UseEuiTheme) => {
.euiFormControlLayout {
${logicalCSS('height', 'auto')}
${logicalCSS('width', 'fit-content')}
box-shadow: none;
border: none;
padding: 0;
}

Expand Down Expand Up @@ -75,5 +75,14 @@ export const euiDatePickerStyles = (euiThemeContext: UseEuiTheme) => {
}
`,
},

inGroup: css`
.euiFormControlLayout__childrenWrapper {
.euiPopover,
.react-datepicker__input-container {
${logicalCSS('height', '100%')}
}
}
`,
};
};
23 changes: 23 additions & 0 deletions packages/eui/src/components/date_picker/date_picker.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,29 @@ describe('EuiDatePicker', () => {
expect(container.innerHTML).toContain('-compressed');
});

test('append/prepend', () => {
const { container, rerender } = render(
<EuiDatePicker append="hello" prepend="world" />
);
const getAppend = () =>
container.querySelector('.euiFormControlLayout__append');
const getPrepend = () =>
container.querySelector('.euiFormControlLayout__prepend');

expect(getAppend()).toHaveTextContent('hello');
expect(getPrepend()).toHaveTextContent('world');

// Does not render if controlOnly
rerender(<EuiDatePicker append="hello" prepend="world" controlOnly />);
expect(getAppend()).not.toBeInTheDocument();
expect(getPrepend()).not.toBeInTheDocument();

// Does not render if inline
rerender(<EuiDatePicker append="hello" prepend="world" inline />);
expect(getAppend()).not.toBeInTheDocument();
expect(getPrepend()).not.toBeInTheDocument();
});

// TODO: These tests/snapshots don't really do anything in Jest without
// the corresponding popover opening. Should be switched to an E2E test instead
describe.skip('popoverPlacement', () => {
Expand Down
43 changes: 37 additions & 6 deletions packages/eui/src/components/date_picker/date_picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ import { useCombinedRefs, useEuiMemoizedStyles } from '../../services';
import { EuiI18nConsumer } from '../context';
import { CommonProps } from '../common';
import { PopoverAnchorPosition } from '../popover';
import { EuiFormControlLayout, useEuiValidatableControl } from '../form';
import {
EuiFormControlLayout,
EuiFormControlLayoutProps,
useEuiValidatableControl,
} from '../form';
import { EuiFormControlLayoutIconsProps } from '../form/form_control_layout/form_control_layout_icons';

import { ReactDatePicker, ReactDatePickerProps } from './react-datepicker';
Expand Down Expand Up @@ -138,9 +142,26 @@ interface EuiExtendedDatePickerProps
*/
popoverPlacement?: PopoverAnchorPosition;

/**
* Creates an input group with element(s) coming before the input.
* `string` | `ReactElement` or an array of these
*
* Ignored if `inline` or `controlOnly` are true.
*/
append?: EuiFormControlLayoutProps['append'];
/**
* Creates an input group with element(s) coming before the input.
* `string` | `ReactElement` or an array of these
*
* Ignored if `inline` or `controlOnly` are true.
*/
prepend?: EuiFormControlLayoutProps['prepend'];

/**
* Completely removes form control layout wrapper and ignores
* iconType. Best used inside EuiFormControlLayoutDelimited.
* `iconType`, `prepend`, and `append`.
*
* Best used inside EuiFormControlLayoutDelimited.
*/
controlOnly?: boolean;
}
Expand All @@ -149,6 +170,7 @@ export type EuiDatePickerProps = CommonProps & EuiExtendedDatePickerProps;

export const EuiDatePicker: FunctionComponent<EuiDatePickerProps> = ({
adjustDateOnChange = true,
append,
calendarClassName,
className,
compressed,
Expand Down Expand Up @@ -177,6 +199,7 @@ export const EuiDatePicker: FunctionComponent<EuiDatePickerProps> = ({
placeholder,
popperClassName,
popoverPlacement = 'downLeft',
prepend,
readOnly,
selected,
shadow = true,
Expand Down Expand Up @@ -297,15 +320,23 @@ export const EuiDatePicker: FunctionComponent<EuiDatePickerProps> = ({
<span css={cssStyles} className={classes}>
<EuiFormControlLayout
icon={optionalIcon}
fullWidth={!inline && fullWidth}
compressed={!inline && compressed}
clear={selected && onClear ? { onClick: onClear } : undefined}
isLoading={isLoading}
isInvalid={isInvalid}
isDisabled={disabled}
readOnly={readOnly}
isDelimited={inline} // Styling shortcut for inline calendars
iconsPosition={inline ? 'static' : undefined}
{...(inline
? {
isDelimited: true,
iconsPosition: 'static',
}
: {
fullWidth,
compressed,
append,
prepend,
css: (append || prepend) && styles.inGroup,
})}
>
{control}
</EuiFormControlLayout>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const euiDatePickerRangeInlineStyles = (
${logicalCSS('height', 'auto')}
${logicalCSS('width', 'fit-content')}
${logicalCSS('max-width', '100%')}
box-shadow: none;
border: none;
padding: 0;

.euiFormControlLayout__childrenWrapper {
Expand Down