diff --git a/.changeset/tasty-needles-clean.md b/.changeset/tasty-needles-clean.md new file mode 100644 index 00000000..5c43ac4e --- /dev/null +++ b/.changeset/tasty-needles-clean.md @@ -0,0 +1,5 @@ +--- +'@jpmorganchase/mosaic-components': patch +--- + +Fix Link sometimes removing text children. diff --git a/packages/components/src/LinkText/index.tsx b/packages/components/src/LinkText/index.tsx index db8667b9..46641df7 100644 --- a/packages/components/src/LinkText/index.tsx +++ b/packages/components/src/LinkText/index.tsx @@ -1,4 +1,4 @@ -import React, { forwardRef, isValidElement, ReactNode, Ref } from 'react'; +import React, { ComponentPropsWithRef, forwardRef, isValidElement, ReactNode, Ref } from 'react'; import classnames from 'clsx'; import { Icon, IconProps } from '../Icon'; @@ -90,26 +90,21 @@ export const LinkText = forwardRef( className: styles.icon }); - let enhancedChildren: ReactNode = null; + let enhancedChildren: ReactNode = children; const childrenClassName = classnames(className, styles.root, { [styles.document]: variant === 'document', [styles.regular]: variant === 'regular', [styles.disabled]: disabled }); - if (typeof children === 'string') { - enhancedChildren = children; - } else if (isValidElement(children)) { - const child = React.Children.only(children) as React.ReactElement<{ - className: string; - ref: Ref; - }>; + if (isValidElement>(children)) { + const child = React.Children.only(children); enhancedChildren = React.cloneElement(child, { className: classnames(child.props.className, childrenClassName), ref }); } return ( - + {startIconAdornment} {enhancedChildren}