Tooltips
import {enableTooltips} from 'cx/widgets';Tooltips provide additional information regarding the element under the mouse pointer. In Cx, tooltips are used as a default way to display validation errors on form fields.
To enable tooltips execute the
enableTooltipsmethod at startup of your application. Tooltips are not automatically enabled to preserve small bundle sizes for applications where they are not needed.
Touch devices do not offer precise mouse pointer location,
so tooltips are shown/hidden when the user taps the element containing the tooltip. Sometimes, this is not
the desired behavior and you can make tooltips to ignore touch events, by setting touchBehavior
to ignore.
To make all tooltips ignore touch events by default, set
Tooltip.prototype.touchBehavior = 'ignore';.
import {enableTooltips} from "cx/widgets";
enableTooltips();
<div class="widgets" controller={PageController}>
<div tooltip="This is a tooltip." style="margin: 50px">
Basic
</div>
<div tooltip={{ placement: 'up', text: "This tooltip is displayed on top, unless you scroll..." }} style="margin: 50px">
Displayed on top!
</div>
<div tooltip={{ placement: 'up', title: 'Hello', text: "It seems that you're really interested in tooltips." }} style="margin: 50px">
Title
</div>
<TextField
value-bind="$page.text" required visited placeholder="Validation" style="margin: 50px"
tooltip="Tooltips are commonly used to show validation errors on form elements."
/>
<TextField
value-bind="$page.text" required visited placeholder="More Validation" style="margin: 50px"
errorTooltip={{placement: 'up', alwaysVisible: true, title: "Validation Error"}}
/>
<div style="padding: 10px" tooltip={{ mouseTrap: true, items: <cx><Md>
Tooltips can contain any content. For example, we can add [a link to the overlays page](~/widgets/overlays) or **make some text bold** because
we're using markdown here. Any other component can be used here too, however, tooltips work best with text and images.
Please note that tooltip elements are appended to the `body` element, hence only the global style rules apply.
In order to support a link click inside a tooltip, the tooltip needs to trap the click event so it doesn't disappear.
</Md></cx> }}>
Rich content
</div>
<div style="margin: 50px" tooltip={{ mouseTrap: true, items: <cx>
<Grid columns={[
{ field: 'fullName', header: 'Name', sortable: true },
{ field: 'phone', header: 'Phone' }
]} records-bind="$page.records"/>
</cx>}}>
Component inside
</div>
<div tooltip={{ alwaysVisible: { bind: '$page.showTooltip'}, placement: 'down', text: "Tooltips can be set to be always visible." }} style="margin: 50px">
<Checkbox value-bind="$page.showTooltip">Always visible</Checkbox>
</div>
<div tooltip={{ visible: { bind: '$page.tooltipVisible'}, alwaysVisible: { bind: '$page.tooltipVisible'}, placement: 'down', text: "This tooltip is visible only while the checkbox is checked." }} style="margin: 50px">
<Checkbox value-bind="$page.tooltipVisible">Controlled visibility</Checkbox>
</div>
<div tooltip={{text: "I'm right behind you.", trackMouse: true, offset: 20}}>
Mouse tracking
</div>
</div>| Property | Description | Type |
|---|---|---|
closeOnEscape | Set to | boolean |
mouseTrap | Tooltips are hidden as soon as the mouse leaves the related widget. Set this to | string |
offset | Distance in pixels from related elements. Default is | number |
placement | Placement strategy. Defaults to | string |
text | Text to be displayed inside the tooltip. | string |
title | Text to be displayed in the header. | string |
touchBehavior | This property controls how tooltips behave on touch events. Default value
is | string |
trackMouse | Set to | string |
alwaysVisible | Set to | boolean |
autoFocus | Set to | boolean |
autoFocusFirstChild | Set to | boolean |
baseClass | Base CSS class to be applied to the field. Defaults to | string |
centerX | Set to | boolean |
centerY | Set to | boolean |
class | Additional CSS classes to be applied to the element. If an object is provided, all keys with a "truthy" value will be added to the CSS class list. | string/object |
closeOnScrollDistance | The dropdown will be automatically closed if the page is scrolled a certain distance. Default value is | number |
containerStyle | Style to be applied to the overlay's container element. | string |
destroyDelay | Number of milliseconds to wait, before removing the element from the DOM. Used in combination with the | number |
dismissOnFocusOut | Set to | boolean |
dismissOnPopState | Set to | boolean |
focusable | Set to true to make the top level overlay element focusable. | boolean |
globalMouseTracking | Set to
| string |
items | List of child elements. | array |
layout | Define an inner layout. | string/object |
matchMaxWidth | Constrains the component's width to the maximum width of its parent, maintaining a responsive design within limits. | boolean |
matchWidth | Ensures the component matches the width of its parent container, creating a cohesive layout. | boolean |
mod | Appearance modifier. For example, | string/array |
onMove | A callback function which fires while the overlay is being moved around. | function |
onResize | A callback function which fires while the overlay is being resized. | function |
placementOrder | Defines available placement options. The dropdown will be pick the placement to maximize content visibility.
Supported options are | string |
plainText | Set to | boolean |
preserveWhitespace | Keep whitespace in text based children. Default is | boolean |
putInto | Used with outer layouts. Specifies the name of the content placeholder which should render the widget. | string |
resizeWidth | resizeWidth | number |
style | Style object applied to the wrapper div. Used for setting the dimensions of the element. | string/object |
trimWhitespace | Remove all whitespace in text based children. Default is | boolean |
vdomKey | Key that will be used as the key when rendering the React component. | string |
visible | Visibility of the widget. Defaults to | boolean |
zIndex | zIndex | number |