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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions packages/eui/changelogs/upcoming/9588.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**Bug fixes**

- Fixed the visual alignment of right aligned icons in `EuiFormControlButton` when `value` is not passed
Original file line number Diff line number Diff line change
Expand Up @@ -57,60 +57,98 @@ export const Playground: Story = {
export const Kitchensink: Story = {
tags: ['vrt-only'],
render: () => {
return (
<EuiFlexGroup gutterSize="s" direction="column">
<EuiFormControlButton placeholder="Placeholder" />
<EuiFormControlButton value="Button value" />
<EuiFormControlButton autoFocus>Button content</EuiFormControlButton>
<EuiFormControlButton value="Button value">
const renderItems = ({
compressed,
autoFocus,
}: {
compressed?: boolean;
autoFocus?: boolean;
}) => (
<>
<EuiFormControlButton
placeholder="Placeholder"
compressed={compressed}
/>
<EuiFormControlButton value="Button value" compressed={compressed} />
<EuiFormControlButton autoFocus={autoFocus} compressed={compressed}>
Button content
</EuiFormControlButton>
<EuiFormControlButton value="Button value" compressed={compressed}>
Button content
</EuiFormControlButton>
<EuiFormControlButton compressed={compressed}>
Button content
</EuiFormControlButton>
<EuiFormControlButton value="Button value" isDisabled />
<EuiFormControlButton value="Button value" isInvalid />
<EuiFormControlButton value="Button value" iconType="faceHappy" />
<EuiFormControlButton
value="Button value"
iconType="faceHappy"
iconSide="right"
/>
iconSide="left"
compressed={compressed}
>
Button content
</EuiFormControlButton>
<EuiFormControlButton
value="Button value"
iconType="faceHappy"
iconSide="right"
compressed={compressed}
>
Button content
</EuiFormControlButton>

<EuiSpacer size="s" />

{/* compressed */}
<EuiFormControlButton placeholder="Placeholder" compressed />
<EuiFormControlButton value="Button value" compressed />
<EuiFormControlButton compressed>Button content</EuiFormControlButton>
<EuiFormControlButton value="Button value" compressed>
Button content
</EuiFormControlButton>
<EuiFormControlButton value="Button value" isDisabled compressed />
<EuiFormControlButton value="Button value" isInvalid compressed />
<EuiFormControlButton
value="Button value"
isDisabled
compressed={compressed}
/>
<EuiFormControlButton
value="Button value"
isInvalid
compressed={compressed}
/>
<EuiFormControlButton
iconType="faceHappy"
iconSide="left"
compressed={compressed}
/>
<EuiFormControlButton
iconType="faceHappy"
iconSide="right"
Comment thread
mgadewoll marked this conversation as resolved.
compressed={compressed}
Comment thread
mgadewoll marked this conversation as resolved.
/>
<EuiFormControlButton
value="Button value"
iconType="faceHappy"
compressed
compressed={compressed}
/>
<EuiFormControlButton
value="Button value"
iconType="faceHappy"
compressed={compressed}
>
Button content
</EuiFormControlButton>
<EuiFormControlButton
value="Button value"
iconType="faceHappy"
iconSide="right"
compressed
compressed={compressed}
/>
<EuiFormControlButton
value="Button value"
iconType="faceHappy"
iconSide="right"
compressed
compressed={compressed}
>
Button content
</EuiFormControlButton>
</>
);
return (
<EuiFlexGroup gutterSize="s" direction="column">
{renderItems({ compressed: false, autoFocus: true })}

<EuiSpacer size="s" />

{/* compressed */}
{renderItems({ compressed: true })}
</EuiFlexGroup>
);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<EuiFormControlButton
{...defaultProps}
value={undefined}
iconType="user"
iconSide="right"
/>
);

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(
<EuiFormControlButton
{...defaultProps}
value={undefined}
iconType="user"
iconSide="left"
/>
);

expect(
baseElement.querySelector('.euiButtonEmpty__content')
).toHaveStyleRule('justify-content', 'flex-start');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -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,
],
Comment thread
mgadewoll marked this conversation as resolved.
Comment thread
mgadewoll marked this conversation as resolved.
};

const customTextProps = {
Expand All @@ -127,7 +133,6 @@ export const EuiFormControlButton: FunctionComponent<
<span>{children}</span>
)
) : null;
const hasText = value || placeholder;

const linkProps = {
href,
Expand Down