diff --git a/packages/eui/.loki/reference/chrome_desktop_Forms_EuiForm_EuiFormControlButton_High_Contrast.png b/packages/eui/.loki/reference/chrome_desktop_Forms_EuiForm_EuiFormControlButton_High_Contrast.png index d386b0621ca4..7296889f4e01 100644 Binary files a/packages/eui/.loki/reference/chrome_desktop_Forms_EuiForm_EuiFormControlButton_High_Contrast.png and b/packages/eui/.loki/reference/chrome_desktop_Forms_EuiForm_EuiFormControlButton_High_Contrast.png differ diff --git a/packages/eui/.loki/reference/chrome_desktop_Forms_EuiForm_EuiFormControlButton_High_Contrast_Dark_Mode.png b/packages/eui/.loki/reference/chrome_desktop_Forms_EuiForm_EuiFormControlButton_High_Contrast_Dark_Mode.png index d01c3ac63611..c99d5eb9da5a 100644 Binary files a/packages/eui/.loki/reference/chrome_desktop_Forms_EuiForm_EuiFormControlButton_High_Contrast_Dark_Mode.png and b/packages/eui/.loki/reference/chrome_desktop_Forms_EuiForm_EuiFormControlButton_High_Contrast_Dark_Mode.png differ diff --git a/packages/eui/.loki/reference/chrome_desktop_Forms_EuiForm_EuiFormControlButton_Kitchensink.png b/packages/eui/.loki/reference/chrome_desktop_Forms_EuiForm_EuiFormControlButton_Kitchensink.png index ff5204cb6d46..b706d9a91a6d 100644 Binary files a/packages/eui/.loki/reference/chrome_desktop_Forms_EuiForm_EuiFormControlButton_Kitchensink.png and b/packages/eui/.loki/reference/chrome_desktop_Forms_EuiForm_EuiFormControlButton_Kitchensink.png differ diff --git a/packages/eui/.loki/reference/chrome_desktop_Forms_EuiForm_EuiFormControlButton_Kitchensink_Dark_Mode.png b/packages/eui/.loki/reference/chrome_desktop_Forms_EuiForm_EuiFormControlButton_Kitchensink_Dark_Mode.png index 3811b915f22e..e4429c43487a 100644 Binary files a/packages/eui/.loki/reference/chrome_desktop_Forms_EuiForm_EuiFormControlButton_Kitchensink_Dark_Mode.png and b/packages/eui/.loki/reference/chrome_desktop_Forms_EuiForm_EuiFormControlButton_Kitchensink_Dark_Mode.png differ diff --git a/packages/eui/.loki/reference/chrome_mobile_Forms_EuiForm_EuiFormControlButton_High_Contrast.png b/packages/eui/.loki/reference/chrome_mobile_Forms_EuiForm_EuiFormControlButton_High_Contrast.png index 63c311993620..c4c4a2ae1474 100644 Binary files a/packages/eui/.loki/reference/chrome_mobile_Forms_EuiForm_EuiFormControlButton_High_Contrast.png and b/packages/eui/.loki/reference/chrome_mobile_Forms_EuiForm_EuiFormControlButton_High_Contrast.png differ diff --git a/packages/eui/.loki/reference/chrome_mobile_Forms_EuiForm_EuiFormControlButton_High_Contrast_Dark_Mode.png b/packages/eui/.loki/reference/chrome_mobile_Forms_EuiForm_EuiFormControlButton_High_Contrast_Dark_Mode.png index bc02e5e9fa97..da572065c711 100644 Binary files a/packages/eui/.loki/reference/chrome_mobile_Forms_EuiForm_EuiFormControlButton_High_Contrast_Dark_Mode.png and b/packages/eui/.loki/reference/chrome_mobile_Forms_EuiForm_EuiFormControlButton_High_Contrast_Dark_Mode.png differ diff --git a/packages/eui/.loki/reference/chrome_mobile_Forms_EuiForm_EuiFormControlButton_Kitchensink.png b/packages/eui/.loki/reference/chrome_mobile_Forms_EuiForm_EuiFormControlButton_Kitchensink.png index 2b66ff8e3f33..7213a212bb92 100644 Binary files a/packages/eui/.loki/reference/chrome_mobile_Forms_EuiForm_EuiFormControlButton_Kitchensink.png and b/packages/eui/.loki/reference/chrome_mobile_Forms_EuiForm_EuiFormControlButton_Kitchensink.png differ diff --git a/packages/eui/.loki/reference/chrome_mobile_Forms_EuiForm_EuiFormControlButton_Kitchensink_Dark_Mode.png b/packages/eui/.loki/reference/chrome_mobile_Forms_EuiForm_EuiFormControlButton_Kitchensink_Dark_Mode.png index 76fa1bd4625e..f01af140f613 100644 Binary files a/packages/eui/.loki/reference/chrome_mobile_Forms_EuiForm_EuiFormControlButton_Kitchensink_Dark_Mode.png and b/packages/eui/.loki/reference/chrome_mobile_Forms_EuiForm_EuiFormControlButton_Kitchensink_Dark_Mode.png differ diff --git a/packages/eui/changelogs/upcoming/9588.md b/packages/eui/changelogs/upcoming/9588.md new file mode 100644 index 000000000000..cc02f420e946 --- /dev/null +++ b/packages/eui/changelogs/upcoming/9588.md @@ -0,0 +1,3 @@ +**Bug fixes** + +- Fixed the visual alignment of right aligned icons in `EuiFormControlButton` when `value` is not passed \ No newline at end of file diff --git a/packages/eui/src/components/form/form_control_button/form_control_button.stories.tsx b/packages/eui/src/components/form/form_control_button/form_control_button.stories.tsx index 475a5b2e18a1..a3811ee0141e 100644 --- a/packages/eui/src/components/form/form_control_button/form_control_button.stories.tsx +++ b/packages/eui/src/components/form/form_control_button/form_control_button.stories.tsx @@ -57,60 +57,98 @@ export const Playground: Story = { export const Kitchensink: Story = { tags: ['vrt-only'], render: () => { - return ( - - - - Button content - + const renderItems = ({ + compressed, + autoFocus, + }: { + compressed?: boolean; + autoFocus?: boolean; + }) => ( + <> + + + + Button content + + + Button content + + Button content - - - + iconSide="left" + compressed={compressed} + > + Button content + Button content - - - - {/* compressed */} - - - Button content - - Button content - - - + + + + + + Button content + Button content + + ); + return ( + + {renderItems({ compressed: false, autoFocus: true })} + + + + {/* compressed */} + {renderItems({ compressed: true })} ); }, diff --git a/packages/eui/src/components/form/form_control_button/form_control_button.styles.ts b/packages/eui/src/components/form/form_control_button/form_control_button.styles.ts index fc22953abaf1..5116b4e86ff8 100644 --- a/packages/eui/src/components/form/form_control_button/form_control_button.styles.ts +++ b/packages/eui/src/components/form/form_control_button/form_control_button.styles.ts @@ -70,6 +70,9 @@ export const euiFormControlButtonStyles = (euiThemeContext: UseEuiTheme) => { justify-content: flex-start; ${logicalCSS('width', '100%')} `, + alignEnd: css` + justify-content: flex-end; + `, textContent: css` flex: 1; text-align: start; diff --git a/packages/eui/src/components/form/form_control_button/form_control_button.test.tsx b/packages/eui/src/components/form/form_control_button/form_control_button.test.tsx index d1fa910ef3c8..ca1c051bc209 100644 --- a/packages/eui/src/components/form/form_control_button/form_control_button.test.tsx +++ b/packages/eui/src/components/form/form_control_button/form_control_button.test.tsx @@ -235,4 +235,36 @@ describe('EuiButtonEmpty', () => { }); }); }); + + describe('icon alignment', () => { + it('renders icons with `iconSide="right"` right aligned when no `value` is passed', () => { + const { baseElement } = render( + + ); + + expect( + baseElement.querySelector('.euiButtonEmpty__content') + ).toHaveStyleRule('justify-content', 'flex-end'); + }); + + it('renders icons with `iconSide="left"` left aligned when no `value` is passed', () => { + const { baseElement } = render( + + ); + + expect( + baseElement.querySelector('.euiButtonEmpty__content') + ).toHaveStyleRule('justify-content', 'flex-start'); + }); + }); }); diff --git a/packages/eui/src/components/form/form_control_button/form_control_button.tsx b/packages/eui/src/components/form/form_control_button/form_control_button.tsx index 3f0bdaaeba98..56593ee5e0dd 100644 --- a/packages/eui/src/components/form/form_control_button/form_control_button.tsx +++ b/packages/eui/src/components/form/form_control_button/form_control_button.tsx @@ -69,7 +69,7 @@ export const EuiFormControlButton: FunctionComponent< isDisabled: _isDisabled, isInvalid: _isInvalid, fullWidth = true, - iconSide, + iconSide: _iconSide, isLoading: _isLoading, href, rel, // required by our local href-with-rel eslint rule @@ -89,6 +89,8 @@ export const EuiFormControlButton: FunctionComponent< const isInvalid = _isInvalid ?? formLayoutIsInvalid; const isLoading = formLayoutIsLoading === true ? false : _isLoading; const compressed = _compressed ?? formLayoutCompressed; + const hasText = value || placeholder; + const iconSide = isLoading ? 'right' : _iconSide; const styles = useEuiMemoizedStyles(euiFormControlButtonStyles); const classes = classNames('euiFormControlButton', className); @@ -104,7 +106,11 @@ export const EuiFormControlButton: FunctionComponent< const contentProps = { ..._contentProps, - css: [styles.euiFormControlButton__content, _contentProps?.css], + css: [ + styles.euiFormControlButton__content, + !hasText && iconSide === 'right' && styles.alignEnd, + _contentProps?.css, + ], }; const customTextProps = { @@ -127,7 +133,6 @@ export const EuiFormControlButton: FunctionComponent< {children} ) ) : null; - const hasText = value || placeholder; const linkProps = { href,