Skip to content

[fix] Tooltip title not being pass to button #3276

@cagosto

Description

@cagosto

ReactUSWDS Version & USWDS Version:

Describe the bug

The title prop is not being pass down to the tool tip button. In your types you define title as a prop that can be passed as seen here

type TooltipProps<T> = {
  label: ReactNode
  title?: string
  position?: 'top' | 'bottom' | 'left' | 'right' | undefined
  wrapperclasses?: string
  className?: string
  children: ReactNode
} &

however in reviewing the code i see that title is alway set with an empty string. As seen here

return (
      // the span that wraps the element will have the tooltip class
      <span data-testid="tooltipWrapper" className={wrapperClasses}>
        <button
          {...remainingProps}
          data-testid="triggerElement"
          ref={triggerElementRef}
          aria-describedby={tooltipID}
          tabIndex={0}
          type="button"
          className={triggerClasses}
          title=""
          onMouseEnter={showTooltip}
          onMouseOver={showTooltip}
          onFocus={showTooltip}
          onMouseLeave={hideTooltip}
          onBlur={hideTooltip}
          onKeyDown={hideTooltip}>
          {children}
        </button>
        <span
          data-testid="tooltipBody"
          title={title ?? (typeof label === 'string' ? label : undefined)}
          id={tooltipID}
          ref={tooltipBodyRef}
          className={tooltipBodyClasses}
          role="tooltip"
          aria-hidden={!isVisible}
          style={positionStyles}>
          {label}
        </span>
      </span>
    )

To Reproduce
Steps to reproduce the behavior:

  1. Create a tool tip
  2. pass title prop on tool tip something like this
<div className="margin-4">
    <Tooltip label="Default" title="test">Default</Tooltip>
  </div>
  1. inspect element to see the title on the button
  2. it will show a blank title value title=""

Expected behavior

The title prop should be pass to the button element and readable by screen readers.

Device and Browser Information (please complete the following information if describing a UI bug):

All browser all versions

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bugSomething isn't working like it's supposed to

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions