TooltipTooltip provides advisory information for a component.

Tooltip - 图1

Documentation

Import

  1. import {TooltipModule} from 'primeng/tooltip';
  2.  

Getting Started

Tooltip is applied to an element with pTooltip directive where the value of the directive defines the text to display.

  1. <input type="text" pTooltip="Enter your username">
  2.  

Position

There are four choices to position the tooltip, default value is "right" and alternatives are "top", "bottom", "left". Position is specified using tooltipPosition attribute.

  1. <input type="text" pTooltip="Enter your username" tooltipPosition="top">
  2.  

Events

Tooltip gets displayed on hover event of its target by default, other option is the focus event to display and blur to hide.

  1. <input type="text" pTooltip="Enter your username" tooltipPosition="top" tooltipEvent="focus">
  2.  

Delay

Tooltip is displayed or hidden instantly by default however you may add delays using showDelay and hideDelay properties which accept a number value in terms of milliseconds.

  1. <input type="text" pTooltip="Enter your username" tooltipPosition="top" tooltipEvent="focus" showDelay="1000" hideDelay="500">
  2.  

Scrolling Containers

When placed inside a scrolling container like an overflown div, tooltip must be appended to another element that has relative positioning instead of document body which is the default.

  1. <div #container style="display:inline-block;position:relative">
  2. <input type="text" pInputText pTooltip="Enter your username" placeholder="Right" [appendTo]="container">
  3. </div>
  4.  

Properties

NameTypeDefaultDescription
pTooltipstringnullText of the tooltip.
tooltipPositionstringrightPosition of the tooltip, valid values are right, left, top and bottom.
tooltipEventstringhoverEvent to show the tooltip, valid values are hover and focus.
positionStylestringabsoluteType of CSS position.
tooltipDisabledbooleanfalseWhen present, it specifies that the component should be disabled.
appendTostringanyTarget element to attach the overlay, valid values are "body", "target" or a local ng-template variable of another element.
hideDelaynullnumberDelay to hide the tooltip in milliseconds.
showDelaynullnumberDelay to show the tooltip in milliseconds.
lifenullnumberTime to wait in milliseconds to hide the tooltip even it is active.
tooltipStyleClassstringnullStyle class of the tooltip.
escapebooleantrueBy default the tooltip contents are rendered as text. Set to false to support html tags in the content
tooltipZIndexstringautoWhether the z-index should be managed automatically to always go on top or have a fixed value.

Styling

Following is the list of structural style classes, for theming classes visit theming page.

NameElement
ui-tooltipContainer element
ui-tooltip-arrowArrow of the tooltip
ui-tooltip-textText of the tooltip

Dependencies

None.

Source

View on GitHub

  1. <h3 class="first">Positions</h3>
  2. <div class="ui-g ui-fluid">
  3. <div class="ui-g-12 ui-md-3">
  4. <input type="text" pInputText pTooltip="Enter your username" placeholder="Right">
  5. </div>
  6. <div class="ui-g-12 ui-md-3">
  7. <input type="text" pInputText pTooltip="Enter your username" tooltipPosition="top" placeholder="Top">
  8. </div>
  9. <div class="ui-g-12 ui-md-3">
  10. <input type="text" pInputText pTooltip="Enter your username" tooltipPosition="bottom" placeholder="Bottom">
  11. </div>
  12. <div class="ui-g-12 ui-md-3">
  13. <input type="text" pInputText pTooltip="Enter your username" tooltipPosition="left" placeholder="Left">
  14. </div>
  15. </div>
  16. <h3>Focus and Blur</h3>
  17. <input type="text" pInputText pTooltip="Enter your username" placeholder="Right" tooltipEvent="focus" style="margin-left:.5em">
  18.