Skip to content

Commit

Permalink
fix(Button): ensure leftIcon className is not added when children are…
Browse files Browse the repository at this point in the history
… non-renderable
  • Loading branch information
YossiSaadi authored Dec 29, 2024
1 parent 5744dbd commit ead380b
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/core/src/components/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,8 @@ const Button: VibeComponent<ButtonProps, unknown> & {
return BUTTON_ICON_SIZE;
}, [successIcon]);

const hasRenderableChildren = useMemo(() => React.Children.toArray(children).some(Boolean), [children]);

const buttonContent = useMemo(
() => (
<>
Expand All @@ -326,7 +328,7 @@ const Button: VibeComponent<ButtonProps, unknown> & {
icon={leftIcon}
iconSize={leftIconSize}
className={cx({
[styles.leftIcon]: !!children
[styles.leftIcon]: hasRenderableChildren
})}
ignoreFocusStyle
/>
Expand All @@ -338,14 +340,14 @@ const Button: VibeComponent<ButtonProps, unknown> & {
icon={rightIcon}
iconSize={rightIconSize}
className={cx({
[styles.rightIcon]: !!children
[styles.rightIcon]: hasRenderableChildren
})}
ignoreFocusStyle
/>
) : null}
</>
),
[children, leftIcon, leftIconSize, rightIcon, rightIconSize]
[children, hasRenderableChildren, leftIcon, leftIconSize, rightIcon, rightIconSize]
);

if (loading) {
Expand Down

0 comments on commit ead380b

Please sign in to comment.