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
3 changes: 3 additions & 0 deletions packages/eui/changelogs/upcoming/8020.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**Bug fixes**

- Fixed `EuiDatePicker`'s `onClear` button to not appear when the input is `disabled`
19 changes: 19 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 @@ -47,6 +47,25 @@ describe('EuiDatePicker', () => {
jest.restoreAllMocks();
});

test('onClear', () => {
const onClear = () => {};
const selected = moment();

const { queryByLabelText, rerender } = render(
<EuiDatePicker onClear={onClear} selected={selected} />
);
// Should render the clear button
expect(queryByLabelText('Clear input')).toBeInTheDocument();

// Should not render the clear button if the input is disabled
rerender(<EuiDatePicker onClear={onClear} selected={selected} disabled />);
expect(queryByLabelText('Clear input')).not.toBeInTheDocument();

// Should not render the clear button if no date is selected
rerender(<EuiDatePicker onClear={onClear} />);
expect(queryByLabelText('Clear input')).not.toBeInTheDocument();
});

test('compressed', () => {
const { container } = render(<EuiDatePicker compressed />);
// TODO: Should probably be a visual snapshot test
Expand Down
4 changes: 3 additions & 1 deletion packages/eui/src/components/date_picker/date_picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,9 @@ export const EuiDatePicker: FunctionComponent<EuiDatePickerProps> = ({
<span css={cssStyles} className={classes}>
<EuiFormControlLayout
icon={optionalIcon}
clear={selected && onClear ? { onClick: onClear } : undefined}
clear={
selected && !disabled && onClear ? { onClick: onClear } : undefined
}
isLoading={isLoading}
isInvalid={isInvalid}
isDisabled={disabled}
Expand Down