Skip to content

Commit

Permalink
feat: Allow Tooltip label to be a string or React component (#2596)
Browse files Browse the repository at this point in the history
Co-authored-by: Brandon Lenz <15805554+brandonlenz@users.noreply.github.com>
  • Loading branch information
lpsinger and brandonlenz committed Oct 20, 2023
1 parent c5f2b40 commit bc01008
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/components/Tooltip/Tooltip.tsx
Expand Up @@ -12,7 +12,8 @@ import classnames from 'classnames'
import { isElementInViewport, calculateMarginOffset } from './utils'

type TooltipProps<T> = {
label: string
label: ReactNode
title?: string
position?: 'top' | 'bottom' | 'left' | 'right' | undefined
wrapperclasses?: string
className?: string
Expand Down Expand Up @@ -202,7 +203,7 @@ export function Tooltip<FCProps = DefaultTooltipProps>(
})

if (isCustomProps(props)) {
const { label, asCustom, children, ...remainingProps } = props
const { label, title, asCustom, children, ...remainingProps } = props
const customProps: FCProps = remainingProps as unknown as FCProps

const triggerClasses = classnames('usa-tooltip__trigger', className)
Expand Down Expand Up @@ -232,7 +233,7 @@ export function Tooltip<FCProps = DefaultTooltipProps>(
{triggerElement}
<span
data-testid="tooltipBody"
title={label}
title={title ?? (typeof label === 'string' ? label : undefined)}
id={tooltipID.current}
ref={tooltipBodyRef}
className={tooltipBodyClasses}
Expand All @@ -244,7 +245,7 @@ export function Tooltip<FCProps = DefaultTooltipProps>(
</span>
)
} else {
const { label, children, ...remainingProps } = props
const { label, title, children, ...remainingProps } = props

const triggerClasses = classnames(
'usa-button',
Expand Down Expand Up @@ -273,7 +274,7 @@ export function Tooltip<FCProps = DefaultTooltipProps>(
</button>
<span
data-testid="tooltipBody"
title={label}
title={title ?? (typeof label === 'string' ? label : undefined)}
id={tooltipID.current}
ref={tooltipBodyRef}
className={tooltipBodyClasses}
Expand Down

0 comments on commit bc01008

Please sign in to comment.