AisTooltip
An AisTooltip creates a floating element used to display additional information. AisTooltip is similar but lighter in weight to AisPopover. A tooltip is triggered when users hover, click, or focus an element. Tooltips are positioned relative to a specified target.
Tooltip Creation
Tooltips are created by one of three complementary methods -- directive, component, or composable. Each method exposes the same functionality but offers a different developer experience. At the heart of each method is a shared options object. AisTooltip's props are valid keys on the options object.
v-tooltip
The v-tooltip directive is the simplest way to create a tooltip. v-tooltip may be used with the content attribute to specify the tooltip details directly on the triggering element. v-tooltip will also accept an options object for deeper customization. If you're using Vue's Options API, please review the details for importing directives.
AisTooltip
The next method to create a tooltip is to use the AisTooltip component. The component allows developers to specify a tooltip as part of their template. The component's slot allow for more complex and customized content.
The quick brown fox
useAisTooltip
The composable useAisTooltip allows a developer to specify a tooltip completely in code. Both the directive and component call useAisTooltip.
Props
All props are valid attributes on the options object which is passed to the directive and composable. On AisTooltip the props are assembled into the options object and passed to useAisTooltip.
target
The target prop specifies the DOM element that the tooltip is positioned against. Typically, it is the same element as the trigger, but they can be different. The target element may be specified by: ref, name, id, class, or a function that returns a DOM element.
trigger
The trigger prop specifies the DOM element that displays the tooltip based on the specified triggers. Often the triggering element is the same as the target but they can be different. If no trigger is specified, the target serves as the trigger.
Separate Target
triggers
The triggers prop controls how the tooltip is triggered. It accepts any combination of the user events hover, click, and focus. The default is triggers='hover focus'. To programmatically show and hide your tooltip, set triggers='manual'.
placement
The placement prop controls where the tooltip appears in relation to the target. The base placements are top, bottom, right, left. The default placement is top. For tooltips, the base placements should generally be preferred. However, each base placement also has an alignment in the form of -start and -end. For example, right-start, or bottom-end. These options allow you to align the tooltip to an edge of the target rather than centering it.
variant
The variant prop accepts any of our standard display variants (e.g. success or danger). The default value is secondary and is the preferred option for most uses. However, there may be times when you want to match or complement the tooltip's variant with its target. You may play with different variant values in the example below.
arrow
arrow is a boolean prop that is on by default. To remove the little arrow widget on the tooltip, set arrow to false.
offset
offset sets the gap between the target and the tooltip. The default value is 6(px). Make sure you bind the value, so it is treated as a number (e.g. :offset="5").
maxWidth
The maxWidth prop will set a class to define the max width of the tooltip. The default value is max-w-md. Refer to Tailwind's max width utilities for other options.
showOnLoad
Add the showOnLoad boolean prop to show the tooltip on page load.
Slots
AisTooltip has two slots – default and target. These slots can be used to further customize a tooltip.
Content from default slot
Content from default slot
default
The default slot is used to define tooltip content. It is useful if you need rich formatting or templating in the tooltip.
target
The target slot is available as another mechanism for associating the tooltip definition with a target DOM element. This is potentially useful if you are creating tooltips in a loop and don't want to manage unique names or ids. In general however, we recommend using v-tooltip or the target prop instead.