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

[EuiDatePicker] Fix clear button appearing when input is disabled #8020

Merged
merged 2 commits into from
Sep 13, 2024
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
Loading