FlexTip Documentation
A FlexTip can be created declaratively by adding the flextip class to a <div>. Use data-attributes to configure that particular FlexTip.
The content inside the <div> becomes the tooltip content. When data-target-id is omitted, FlexTip creates an information icon at the position where the FlexTip markup was declared.
An existing button can be used as the target. Set its type explicitly when it is not intended to submit a form.
This example only specifies a target. All other values use the defaults shown on the Default configuration tab.
<button id="productHelp" type="button">Product help</button>
<div class="flextip"
data-target-id="productHelp">
Product information
</div>
An existing target can be annotated after its text. superscript adds a raised information “i”, while superscript-question adds a raised question mark. Both annotations work in ordinary inline layouts and when the annotation is a flex item.
<span id="commissionRateHelp">Commission rate</span> <div class="flextip" data-target-id="commissionRateHelp" data-target-annotation-style="superscript-question"> The commission rate as a percentage </div> <span id="productInfo">Product</span> <div class="flextip" data-target-id="productInfo" data-target-annotation-style="superscript"> Product information </div>
A FlexTip can also be created programmatically. A content callback is evaluated immediately before every opening and receives the current target and FlexTip instance. It can therefore return fresh target-specific content without recreating or manually updating the FlexTip.
const targets = document.querySelectorAll(".product-help");
function createContent(target) {
const fragment = document.createDocumentFragment();
const text = document.createElement("span");
text.textContent = target.dataset.tipContent;
fragment.appendChild(text);
return fragment;
}
const productTip = FlexTip.create({
target: {
element: targets[0]
}
}, createContent);
targets.forEach(target => {
target.addEventListener("mouseenter", () => {
productTip.update({
target: {
element: target
}
}).showTip();
});
});
Use FlexTip.configure(<options object>) to change the defaults for all FlexTips created afterwards on the page.
FlexTip.configure({
trigger: "hover",
autoClose: true,
closeOnEscape: true,
position: "top",
align: "center",
gap: "5px",
zIndex: 1000,
target: {
annotationStyle: "none",
iconColor: "#ccc"
},
arrow: {
use: true,
size: "5px"
},
styles: {
cssClass: "",
padding: "5px 10px",
backgroundColor: "#f6f6f6",
borderRadius: "4px",
transition: "opacity 0.5s",
boxShadow: "0 2px 8px rgba(0, 0, 0, 0.15)"
},
scrim: {
opacity: 0,
backgroundColor: "transparent"
}
});
Data-attributes configure an individual declarative FlexTip and override the corresponding default configuration.
| Attribute | Values | Description |
|---|---|---|
| class | flextip |
|
| id | Unique HTML id |
|
| data-trigger | hover | click |
|
| data-auto-close | true | false |
|
| data-close-on-escape | true | false |
|
| data-position | top | right | bottom | left |
|
| data-align | start | center | end |
|
| data-gap | Pixel length |
|
| data-z-index | Number |
|
| target | Options for the element that triggers and anchors the tooltip. | |
| data-target-id | HTML id |
|
| data-target-annotation-style | none | underline | superscript | superscript-question | bracketed |
|
| data-target-icon-color | CSS color |
|
| arrow | Options for the arrow between the tooltip and target. Short tooltips keep visible overflow so the arrow does not create a scrollbar. Vertical scrolling is enabled only when tooltip content exceeds the available viewport height. | |
| data-arrow-use | true | false |
|
| data-arrow-size | Pixel length |
|
| styles | Visual options applied directly to the tooltip element. | |
| data-styles-css-class | CSS class name |
|
| data-styles-padding | CSS padding |
|
| data-styles-background-color | CSS color | none |
|
| data-styles-border-radius | CSS border-radius |
|
| data-styles-transition | CSS transition |
|
| data-styles-box-shadow | CSS box-shadow |
|
| scrim | Options for the shared page scrim used by click-triggered FlexTips. | |
| data-scrim-opacity | Number from 0 to 1 |
|
| data-scrim-background-color | CSS color |
|
| Method | Parameters and return value | Description |
|---|---|---|
| FlexTip.configure(options) |
|
Deep-merges options into the defaults used by FlexTips created afterwards. |
| FlexTip.create(options, content) |
|
Creates a programmatic FlexTip. String content is inserted as HTML. An Element or DocumentFragment is moved into the tooltip. A content callback is evaluated immediately before every opening. |
| FlexTip.closeAll() | Returns nothing. | Hides every FlexTip instance registered on the page. |
| myFlexTip.update(options, content) |
|
Hides the tip, detaches it from its previous target, applies the supplied configuration, attaches it to the new target, and optionally replaces its content. Use target.element to reuse one instance across multiple page elements. Changing trigger immediately rebinds the interaction listeners on both the target and tooltip. |
| myFlexTip.updateContent(content) |
|
Replaces only the user-provided tooltip content while preserving the arrow and hover bridge. A callback remains registered and is evaluated immediately before every opening. |
| myFlexTip.showTip() | Returns nothing. | Positions and shows the tooltip for its current target. |
| myFlexTip.hideTip() | Returns nothing. | Hides the tooltip and removes its open state from the current target. |