@@ -17,11 +17,11 @@ exports[`EuiFormControlLayoutClearButton is rendered 1`] = `
exports[`EuiFormControlLayoutClearButton size is rendered 1`] = `
diff --git a/packages/eui/src/components/form/form_control_layout/__snapshots__/form_control_layout_custom_icon.test.tsx.snap b/packages/eui/src/components/form/form_control_layout/__snapshots__/form_control_layout_custom_icon.test.tsx.snap
index 899c46e6829..3125319fa98 100644
--- a/packages/eui/src/components/form/form_control_layout/__snapshots__/form_control_layout_custom_icon.test.tsx.snap
+++ b/packages/eui/src/components/form/form_control_layout/__snapshots__/form_control_layout_custom_icon.test.tsx.snap
@@ -3,7 +3,7 @@
exports[`EuiFormControlLayoutCustomIcon is rendered as button 1`] = `
diff --git a/packages/eui/src/components/form/form_control_layout/form_control_layout_clear_button.styles.ts b/packages/eui/src/components/form/form_control_layout/form_control_layout_clear_button.styles.ts
new file mode 100644
index 00000000000..4da1965775f
--- /dev/null
+++ b/packages/eui/src/components/form/form_control_layout/form_control_layout_clear_button.styles.ts
@@ -0,0 +1,48 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License
+ * 2.0 and the Server Side Public License, v 1; you may not use this file except
+ * in compliance with, at your election, the Elastic License 2.0 or the Server
+ * Side Public License, v 1.
+ */
+
+import { css } from '@emotion/react';
+
+import { UseEuiTheme } from '../../../services';
+
+export const EuiFormControlLayoutClearButtonStyles = ({
+ euiTheme,
+ colorMode,
+}: UseEuiTheme) => {
+ const backgroundColor =
+ colorMode === 'DARK'
+ ? euiTheme.colors.darkShade
+ : euiTheme.colors.mediumShade;
+ return {
+ euiFormControlLayoutClearButton: css`
+ pointer-events: all;
+ background-color: ${backgroundColor};
+ border-radius: 50%;
+ line-height: 0; /* ensures the icon stays vertically centered */
+
+ &:disabled {
+ cursor: not-allowed;
+ background-color: ${euiTheme.colors.disabled};
+ }
+ `,
+
+ euiFormControlLayoutClearButton__icon: css`
+ transform: scale(0.5);
+ fill: ${euiTheme.colors.emptyShade};
+ stroke: ${euiTheme.colors.emptyShade};
+ `,
+ size: {
+ s: css`
+ stroke-width: ${euiTheme.size.xs};
+ `,
+ m: css`
+ stroke-width: ${euiTheme.size.xxs};
+ `,
+ },
+ };
+};
diff --git a/packages/eui/src/components/form/form_control_layout/form_control_layout_clear_button.test.tsx b/packages/eui/src/components/form/form_control_layout/form_control_layout_clear_button.test.tsx
index fca5cdffd1a..9b436c915a3 100644
--- a/packages/eui/src/components/form/form_control_layout/form_control_layout_clear_button.test.tsx
+++ b/packages/eui/src/components/form/form_control_layout/form_control_layout_clear_button.test.tsx
@@ -8,10 +8,14 @@
import React from 'react';
import { requiredProps } from '../../../test';
+import { shouldRenderCustomStyles } from '../../../test/internal';
import { render } from '../../../test/rtl';
+
import { EuiFormControlLayoutClearButton } from './form_control_layout_clear_button';
describe('EuiFormControlLayoutClearButton', () => {
+ shouldRenderCustomStyles();
+
test('is rendered', () => {
const { container } = render(
& {
- size?: (typeof SIZES)[number];
+ size?: 's' | 'm';
};
export const EuiFormControlLayoutClearButton: FunctionComponent<
EuiFormControlLayoutClearButtonProps
> = ({ className, onClick, size = 'm', ...rest }) => {
- const classes = classNames(
- 'euiFormControlLayoutClearButton',
- sizeToClassNameMap[size],
- className
+ const classes = classNames('euiFormControlLayoutClearButton', className);
+ const styles = useEuiMemoizedStyles(EuiFormControlLayoutClearButtonStyles);
+ const iconStyles = [
+ styles.euiFormControlLayoutClearButton__icon,
+ styles.size[size],
+ ];
+
+ const ariaLabel = useEuiI18n(
+ 'euiFormControlLayoutClearButton.label',
+ 'Clear input'
);
return (
-
- {(label: string) => (
-
- )}
-
+
+
);
};
diff --git a/packages/eui/src/components/form/form_control_layout/form_control_layout_custom_icon.test.tsx b/packages/eui/src/components/form/form_control_layout/form_control_layout_custom_icon.test.tsx
index b5abcb2c728..61a18d2afcc 100644
--- a/packages/eui/src/components/form/form_control_layout/form_control_layout_custom_icon.test.tsx
+++ b/packages/eui/src/components/form/form_control_layout/form_control_layout_custom_icon.test.tsx
@@ -9,12 +9,16 @@
import React from 'react';
import { requiredProps } from '../../../test';
import { render } from '../../../test/rtl';
+import { shouldRenderCustomStyles } from '../../../test/internal';
+
import {
EuiFormControlLayoutCustomIcon,
EuiFormControlLayoutCustomIconProps,
} from './form_control_layout_custom_icon';
describe('EuiFormControlLayoutCustomIcon', () => {
+ shouldRenderCustomStyles();
+
test('is rendered as button', () => {
const props: EuiFormControlLayoutCustomIconProps = {
onClick: () => null,
diff --git a/packages/eui/src/components/form/form_control_layout/form_control_layout_custom_icon.tsx b/packages/eui/src/components/form/form_control_layout/form_control_layout_custom_icon.tsx
index 7440ccd14d5..effdc52fb2d 100644
--- a/packages/eui/src/components/form/form_control_layout/form_control_layout_custom_icon.tsx
+++ b/packages/eui/src/components/form/form_control_layout/form_control_layout_custom_icon.tsx
@@ -11,10 +11,11 @@ import React, {
FunctionComponent,
HTMLAttributes,
} from 'react';
+import { css } from '@emotion/react';
import classNames from 'classnames';
-import { EuiIcon, EuiIconProps, IconType } from '../../icon';
import { CommonProps, ExclusiveUnion } from '../../common';
+import { EuiIcon, EuiIconProps, IconType } from '../../icon';
export type EuiFormControlLayoutCustomIconProps = CommonProps &
ExclusiveUnion<
@@ -30,16 +31,20 @@ export type EuiFormControlLayoutCustomIconProps = CommonProps &
export const EuiFormControlLayoutCustomIcon: FunctionComponent<
EuiFormControlLayoutCustomIconProps
-> = ({ className, onClick, type, iconRef, size, color, ...rest }) => {
- const classes = classNames('euiFormControlLayoutCustomIcon', className, {
- 'euiFormControlLayoutCustomIcon--clickable': onClick,
- });
+> = ({ className, onClick, type, iconRef, size, color, disabled, ...rest }) => {
+ const classes = classNames('euiFormControlLayoutCustomIcon', className);
+ const cssStyles = [
+ styles.euiFormControlLayoutCustomIcon,
+ onClick ? styles.clickable : styles.unclickable,
+ ];
if (onClick) {
return (