Components

Tooltip

Tooltips display supporting information to disambiguate user controls and text.

Examples #

Import Syntax #

import Tooltip from 'mineral-ui/Tooltip';

Basic Usage #

Tooltips wrap the triggering component. Placement is relative to the location of the trigger. Tooltips will change position relative to the trigger automatically depending on viewport constraints.

<Tooltip content="Edit your account settings">
  <Button iconStart={<IconPerson title="account settings"/>} />
</Tooltip>

In Prose #

Tooltips can add information to prose.

Here's some prose with a Tooltip in the middle of it.

<DemoLayout>
  <p>
    Here's some prose with a <Tooltip content="Light years star stuff" isOpen usePortal>Tooltip</Tooltip> in the middle of it.
  </p>
</DemoLayout>

Placement #

The placement prop determines the initial placement of the Tooltip content relative to the trigger. The Tooltip will still react to viewport edges and scrolling.

<DemoLayout>
  <Tooltip
    content="Light years star stuff harvesting star light citizens of distant epochs."
    isOpen
    placement="bottom">
    <Button variant="danger" iconStart={<IconDelete title="delete" />}/>
  </Tooltip>
</DemoLayout>

Overflow #

A Tooltip can extend beyond its bounding container (the blue area in this example) even if the container has an overflow: hidden style. See the portal example for even greater control.

<OverflowContainer>
  <Tooltip
    content="Light years star stuff"
    placement="top"
    isOpen>
    <Button>Button</Button>
  </Tooltip>
</OverflowContainer>

Scrolling Container #

Tooltip will attempt to stay visible in an overflow: scroll container.

<ScrollParent>
  <Tooltip
    content="Light years star stuff"
    placement="left"
    isOpen>
    <Button>Button</Button>
  </Tooltip>
</ScrollParent>

Portal #

Use a portal to render the Tooltip to the body of the page rather than as a sibling of the trigger. This can be useful to visually "break out" of a container with overflow or z-index styles. Note that you may have to adjust the modifiers to get the exact behavior that you want.

<ScrollParent>
  <Tooltip
    content="Light years star stuff"
    placement="bottom"
    usePortal
    isOpen
    modifiers={{
      preventOverflow: {
        escapeWithReference: true
      }
    }}>
    <Button>Button</Button>
  </Tooltip>
</ScrollParent>

Cursor #

Tooltips can apply any of the valid CSS cursor values.

HelpNot AllowedMove
<DemoLayout>
  <Tooltip cursor="help" content="Help">Help</Tooltip>
  <Tooltip cursor="not-allowed" content="Not Allowed">Not Allowed</Tooltip>
  <Tooltip cursor="move" content="Move">Move</Tooltip>
</DemoLayout>

Disabled #

Disabled Tooltips simply don't display the tooltip content upon interaction. The child is unaffected.

<Tooltip content="Edit your account settings" disabled>
  <Button iconStart={<IconPerson title="account settings"/>} />
</Tooltip>

Controlled #

Tooltip controls its own state by default, and can optionally be managed by the application as a controlled component through the isOpen prop. Callbacks for onOpen and onClose are also provided.

class App extends Component {
  constructor(props) {
    super(props);
    this.state = {isOpen: true};
    this.toggleTooltip = this.toggleTooltip.bind(this);
  }

  toggleTooltip() {
    this.setState(prevState => ({ isOpen: !prevState.isOpen }));
  }

  render() {
    const label = this.state.isOpen ? 'Close Tooltip' : 'Open Tooltip';
    return (
      <DemoLayout>
        <Tooltip
          content="This tooltip is controlled"
          isOpen={this.state.isOpen}
          placement="top">
          <Button>Button</Button>
        </Tooltip>
        <Button onClick={this.toggleTooltip}>{label}</Button>
      </DemoLayout>
    );
  }
}

API & Theme #

Tooltip Props #

The Tooltip component takes the following React props.

NameTypeDefaultDescription
childrenReact$Noderequired

Trigger for the Tooltip

contentstringrequired

Content of the Tooltip

cursorstring

Cursor applied when hovering the tooltip trigger; accepts any valid CSS value

defaultIsOpenboolean

Open the Tooltip upon initialization. Primarily for use with uncontrolled components.

disabledboolean

Disables the Tooltip

hasArrowbooleantrue

Include an arrow on the Tooltip content pointing to the trigger

idstring

Id of the Tooltip

isOpenboolean

Determines whether the Tooltip is open. For use with controlled components.

modifiersObject

Plugins that are used to alter behavior. See PopperJS docs for options.

onClose

Called when Tooltip is closed

onOpen

Called when Tooltip is opened

placement'bottom'

Placement of the Tooltip

positionFixedboolean

Apply fixed positioning to the content

usePortalboolean

Use a Portal to render the Tooltip to the body rather than as a sibling to the trigger.

Undocumented properties, including as and css, will be applied to the root element.

Tooltip Theme Variables #

These variables can be used as hooks to override this component's style at either a local or global level. The theme referenced below is whatever theme is available from props to the instance of this component.

VariableValue
TooltipArrow_backgroundColortheme.panel_backgroundColor_inverted
TooltipArrow_borderColortheme.panel_borderColor_inverted
TooltipContent_backgroundColortheme.panel_backgroundColor_inverted
TooltipContent_borderColortheme.panel_borderColor_inverted
TooltipContent_borderRadiustheme.borderRadius_1
TooltipContent_boxShadowtheme.boxShadow_2
TooltipContent_colortheme.color_inverted
TooltipContent_paddingVerticaltheme.space_inset_sm
TooltipContent_maxWidth18em
TooltipContent_zIndextheme.zIndex_100
TooltipContentBlock_marginVertical0
TooltipContentBlock_paddingHorizontaltheme.space_inset_md
TooltipTriggerText_borderStyledashed
TooltipTriggerText_borderColorcurrentcolor
TooltipTriggerText_borderWidth1px

Usage #

When/How to Use #

Use Tooltips to provide contextual annotations to user controls. Tooltip content should be concise and helpful. Content should also be static. Users don't expect the contents to change and are unlikely to notice changes since they are hidden.

Tooltips are not predictable interactions for mobile device users and should be avoided.

Use a Popover instead of a Tooltip when users need to interact with the content. For example, walkthroughs and dismissable new feature announcements should be built with Popovers.

Best Practices #

Use Tooltips to provide supplemental information for a user control, such as titles and keyboard shortcuts, when the interface design doesn't allow space for a text label.

Use Tooltips to annotate the controls for rarely used features or features that can be interpreted in several ways. For instance, these buttons are for voting, not scrolling or prioritizing.

115

Don't use Tooltips to hide important information. Information hidden inside a Tooltip is much less likely to be discovered by the user.

Friedrich Mohs

more info
Born: January 29, 1773
Died: September 29, 1839

Don't place Tooltips such that they prevent the user from reviewing their input.

Don't place useless or redundant content in a Tooltip. Tooltip content should be helpful.

Don't put large strings of text inside a Tooltip's content. Tooltips are intended for short, simple content.

more info

Don't litter your prose with Tooltips. They clutter the text and make it hard to read.

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.