From e3e275544c2c1543598123f4950b943fdccfed0b Mon Sep 17 00:00:00 2001 From: Eric Olkowski Date: Fri, 16 Aug 2024 11:35:06 -0400 Subject: [PATCH] fix(Button): rendered position modifier only when children are passed --- .../src/components/Button/Button.tsx | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/packages/react-core/src/components/Button/Button.tsx b/packages/react-core/src/components/Button/Button.tsx index 608af5bb005..a440deb871e 100644 --- a/packages/react-core/src/components/Button/Button.tsx +++ b/packages/react-core/src/components/Button/Button.tsx @@ -136,6 +136,7 @@ const ButtonBase: React.FunctionComponent = ({ const Component = component as any; const isButtonElement = Component === 'button'; const isInlineSpan = isInline && Component === 'span'; + const isIconAlignedAtEnd = iconPosition === 'end' || iconPosition === 'right'; const preventedEvents = inoperableEvents.reduce( (handlers, eventToPrevent) => ({ @@ -157,6 +158,13 @@ const ButtonBase: React.FunctionComponent = ({ } }; + const _icon = icon && ( + + {icon} + + ); + const _children = children && {children}; + return ( = ({ /> )} - {icon && (iconPosition === 'start' || iconPosition === 'left') && ( - {icon} - )} - {children && {children}} - {icon && (iconPosition === 'end' || iconPosition === 'right') && ( - {icon} + {isIconAlignedAtEnd ? ( + <> + {_children} + {_icon} + + ) : ( + <> + {_icon} + {_children} + )} {countOptions && (