diff --git a/packages/eui/changelogs/upcoming/8020.md b/packages/eui/changelogs/upcoming/8020.md new file mode 100644 index 00000000000..9547fb5ab0d --- /dev/null +++ b/packages/eui/changelogs/upcoming/8020.md @@ -0,0 +1,3 @@ +**Bug fixes** + +- Fixed `EuiDatePicker`'s `onClear` button to not appear when the input is `disabled` diff --git a/packages/eui/src/components/date_picker/date_picker.test.tsx b/packages/eui/src/components/date_picker/date_picker.test.tsx index 4897860527e..63af2d48d98 100644 --- a/packages/eui/src/components/date_picker/date_picker.test.tsx +++ b/packages/eui/src/components/date_picker/date_picker.test.tsx @@ -47,6 +47,25 @@ describe('EuiDatePicker', () => { jest.restoreAllMocks(); }); + test('onClear', () => { + const onClear = () => {}; + const selected = moment(); + + const { queryByLabelText, rerender } = render( + + ); + // Should render the clear button + expect(queryByLabelText('Clear input')).toBeInTheDocument(); + + // Should not render the clear button if the input is disabled + rerender(); + expect(queryByLabelText('Clear input')).not.toBeInTheDocument(); + + // Should not render the clear button if no date is selected + rerender(); + expect(queryByLabelText('Clear input')).not.toBeInTheDocument(); + }); + test('compressed', () => { const { container } = render(); // TODO: Should probably be a visual snapshot test diff --git a/packages/eui/src/components/date_picker/date_picker.tsx b/packages/eui/src/components/date_picker/date_picker.tsx index a88ea36a0f8..01b58569c86 100644 --- a/packages/eui/src/components/date_picker/date_picker.tsx +++ b/packages/eui/src/components/date_picker/date_picker.tsx @@ -320,7 +320,9 @@ export const EuiDatePicker: FunctionComponent = ({