React Tooltip

    The Ignite UI for React Tooltip component provides a way to display a tooltip for a specific element. A tooltip is a popup that displays information related to an element, usually when the element receives keyboard focus or when the mouse hovers over it.

    Ignite UI for React Tooltip Example

    Getting Started

    To start using the IgrTooltipComponent, first, you need to install the Ignite UI for React by running the following command:

    npm install igniteui-react
    

    After that, you need to import the IgrTooltipComponent component and its necessary CSS as follows:

    import { IgrTooltip } from 'igniteui-react';
    import 'igniteui-webcomponents/themes/light/bootstrap.css';
    

    Now you can start with a basic configuration of the React IgrTooltipComponent.

    <IgrTooltip anchor="hover-button">
      Congrats you have hovered the button!
    </IgrTooltip>
    
    <IgrButton id="hover-button">Hover me</IgrButton>
    

    For a complete introduction to the Ignite UI for React, read the Getting Started topic.

    Usage

    Tooltip target

    To attach a tooltip to the desired element, use the anchor property on the <IgrTooltip> element. This property accepts either an element ID or a direct reference to an element. When using an ID reference, simply set the anchor property to the ID of the target element.

    <IgrButton id="target-button">Hover me</IgrButton>
    <IgrTooltip anchor="target-button">
      Congrats you have hovered the button!
    </IgrTooltip>
    

    You can also specify the target by passing the element instance directly:

    const anchor = document.querySelector('#hover-button') as IgrButton;
    const tooltip = document.querySelector('#tooltip') as IgrTooltip;
    tooltip.anchor = anchor;
    
    <IgrTooltip id="tooltip">
      Congrats you have hovered the button!
    </IgrTooltip>
    <IgrButton id="hover-button">Hover me</IgrButton>
    

    Tooltip content

    The Tooltip content is defined by placing custom content between the opening and closing tags of the <IgrTooltip> element.

    <IgrTooltip>
      Congrats you have hovered the button!
    </IgrTooltip>
    

    Alternatively, to set simple text, you can use the message property.

    <IgrTooltip message="This is my custom content here."></IgrTooltip>
    

    If you use both approaches (slotted content and the message property), the slotted content will take priority and the message value will be ignored.

    <IgrButton id="target-button">Hover me</IgrButton>
    <IgrTooltip anchor="target-button" message="I will be hidden.">
      I will be shown!
    </IgrTooltip>
    

    In this example, the slotted content (“I will be shown!”) will be displayed instead of the message property value.

    The IgrTooltipComponent content can be more than just simple text. Since the IgrTooltipComponent is a regular element in the markup, you can enhance its content by adding any elements you need and styling them accordingly.

    Show/Hide delay settings

    If you want to control the delay before showing and hiding the IgrTooltipComponent, you can use the showDelay and hideDelay properties. Both properties accept a number value representing time in milliseconds.

    <IgrTooltip show-delay="600" hide-delay="800">
      Her name is Madelyn James.
    </IgrTooltip>
    

    [!NOTE] It's important to note that the Tooltip API methods — show, hide, and toggle — DO NOT take the showDelay and hideDelay properties into account. They act immediately when invoked.

    Placement

    The IgrTooltipComponent can also be positioned relative to its target element with ease. All you need to do is use the placement property along with one of the following position options: top, top-start, top-end, bottom, bottom-start, bottom-end , right, right-start, right-end, left, left-start, left-end.

    If the placement property is not set, the default value is "top", which places the IgrTooltipComponent above the target element.

    Additionally, you can make the IgrTooltipComponent "sticky" using the sticky property, which adds a close button and keeps the IgrTooltipComponent visible until the user closes it manually - either by clicking the close button or pressing the Esc key. This behavior overrides the default hover behavior, preventing the IgrTooltipComponent from disappearing when the user stops hovering over the target element.

    <IgrButton id="target-button">Hover me</IgrButton>
    <IgrTooltip anchor="target-button" placement="top-start" sticky>
      Congrats you have hovered the button!
    </IgrTooltip>
    

    In the following example, you can see a demonstration of all position options and the sticky property in action:

    Triggers

    By default, the IgrTooltipComponent is triggered only while hovering over the target element. However, you can change this behavior using the showTriggers and hideTriggers properties, which allow you to control when the IgrTooltipComponent appears and disappears. These properties accept event names as values—such as click, focus, or keypress—letting you trigger the IgrTooltipComponent in different scenarios.

    Additional Properties

    Apart from the properties we've already covered, the IgrTooltipComponent component offers a variety of additional properties that allow you to further configure its behavior, position, and appearance.

    Name Type Description
    open boolean Determines whether the tooltip is visible.
    disableArrow boolean If set to true, disables the arrow indicator on the tooltip.
    offset number Sets the pixel distance between the tooltip and its anchor.

    Methods

    In addition to its configurable properties, the IgrTooltipComponent also exposes three methods that you can use:

    Name Description
    show Displays the tooltip if it’s not already shown. If a target is provided, it sets the target as a transient anchor.
    hide Hides the tooltip if it’s not already hidden.
    toggle Toggles the tooltip between the shown and hidden states.

    Accessibility & ARIA Support

    The IgrTooltipComponent is built with accessibility in mind and includes the following ARIA attributes:

    • role - When the tooltip is in its default behavior, role="tooltip" is applied. If the sticky property is enabled, the role changes to status.
    • inert - Dynamically toggled based on visibility. When the tooltip is hidden, it becomes inert.
    • aria-atomic - Set to true, ensuring that the entire tooltip content is announced when it changes.
    • aria-live - Set to polite, indicating to screen readers that updates should be announced only when the user is idle.

    Styling

    The IgrTooltipComponent component exposes two CSS parts that you can use for styling:

    Name Description
    base The base wrapper of the tooltip component.
    bottom The area containing the tooltip arrow.
    igc-tooltip::part(base) {
      background-color: var(--ig-primary-500);
      color: var(--ig-primary-500-contrast);
    }
    
    igc-tooltip::part(bottom) {
      border-bottom-color: var(--ig-primary-500);
    }
    

    API References

    Additional Resources