Tooltip

Render a tooltip at a given element on mouse over or other events. Commonly used to provide additional context or information.

Import

import { Tooltip } from '@tidbcloud/uikit'

Basic Usage

import { Tooltip, Button } from '@tidbcloud/uikit'
 
function Demo() {
  return (
    <Tooltip label="Tooltip content">
      <Button>Button with tooltip</Button>
    </Tooltip>
  )
}

With Arrow

Set withArrow prop to add an arrow to the tooltip:

import { Tooltip, Button } from '@tidbcloud/uikit'
 
function Demo() {
  return (
    <Tooltip label="Tooltip with arrow" withArrow>
      <Button>With arrow</Button>
    </Tooltip>
  )
}

Multiline

Enable multiline mode with multiline prop and set width with w prop:

import { Tooltip, Button } from '@tidbcloud/uikit'
 
function Demo() {
  return (
    <Tooltip
      multiline
      w={220}
      withArrow
      label="Use this button to save this information in your profile, after that you will be able to access it any time."
    >
      <Button>Multiline tooltip</Button>
    </Tooltip>
  )
}

Controlled

Control tooltip state with opened prop:

import { useState } from 'react'
import { Tooltip, Button } from '@tidbcloud/uikit'
 
function Demo() {
  const [opened, setOpened] = useState(false)
 
  return (
    <Tooltip label="Ctrl + J" opened={opened}>
      <Button onClick={() => setOpened((o) => !o)}>Toggle tooltip</Button>
    </Tooltip>
  )
}

Key Props

PropTypeDescription
labelReactNodeTooltip content
positionFloatingPositionTooltip position relative to target
withArrowbooleanAdds an arrow to the tooltip
arrowSizenumberArrow size in px
offsetnumberSpace between tooltip and target in px
multilinebooleanEnable multiline mode
openedbooleanControl tooltip state (controlled mode)
openDelaynumberDelay in ms before showing tooltip
closeDelaynumberDelay in ms before hiding tooltip
colorMantineColorTooltip background color
eventsobjectEvents that trigger tooltip (hover, focus, touch)