Tooltip & Popover
Tooltips and Popovers provide small overlays of content on hover, click, or focus. They are essential for providing extra context without cluttering the UI.
Bootstrap Reference
Quick Start (Tooltip)
Quick Start (Popover)
Popovers are similar to tooltips but can contain a title and more complex content (usually triggered by click).
Visual Examples & Use Cases
1. Positioning
Use the placement argument to control where the overlay appears.
Code & Output
2. Activation Triggers
Tooltips usually trigger on hover, but you can change this to focus or click.
# Only shows when the input field is focused (tabbed into)
Tooltip(Input("field", placeholder="Type..."), title="Help text", trigger="focus")
Practical Functionality
1. Automatic Initialization
In standard Bootstrap, you must manually run JavaScript to enable tooltips. FastStrap handles this for you automatically using a global initialization script that targets any element with data-bs-toggle="tooltip" or "popover".
Parameter Reference
Tooltip
| Param | Type | Description |
|---|---|---|
title |
str |
The text content of the tooltip. |
placement |
str |
top, bottom, left, right, auto. |
trigger |
str |
hover, focus, click, manual. |
animation |
bool |
Default True. Enables CSS fade. |
Popover
| Param | Type | Description |
|---|---|---|
title |
str |
The header of the popover. |
content |
str |
The body text of the popover. |
placement |
str |
Same as tooltip. |
trigger |
str |
Default is click. |
dismissible |
bool |
If True, closes when the user clicks anywhere else. |
faststrap.components.feedback.overlays.Tooltip(text, *children, placement='top', trigger='hover focus', html=False, tag='span', **kwargs)
Bootstrap Tooltip component (wrapper).
Wraps content to add a tooltip on hover/focus. Requires the FastStrap init script (auto-included via add_bootstrap).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Tooltip text |
required |
*children
|
Any
|
Element(s) that trigger the tooltip |
()
|
placement
|
PlacementType
|
Position (top, right, bottom, left) |
'top'
|
trigger
|
TriggerType
|
Events that trigger the tooltip |
'hover focus'
|
html
|
bool
|
Allow HTML in tooltip text |
False
|
tag
|
str
|
HTML tag for the wrapper (default: "span") |
'span'
|
**kwargs
|
Any
|
Additional HTML attributes |
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
FastHTML element (Span by default) with tooltip attributes |
Example
Tooltip("I am a tooltip", Button("Hover me"))
Tooltip("Bold tip", Icon("info"), html=True)
Source code in src/faststrap/components/feedback/overlays.py
faststrap.components.feedback.overlays.Popover(title, content, *children, placement='right', trigger='click', html=False, tag='span', container='body', **kwargs)
Bootstrap Popover component (wrapper).
Wraps content to show a popover on click/hover. Requires the FastStrap init script.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
title
|
str
|
Popover header |
required |
content
|
str
|
Popover body text |
required |
*children
|
Any
|
Element(s) that trigger the popover |
()
|
placement
|
PlacementType
|
Position (top, right, bottom, left) |
'right'
|
trigger
|
TriggerType
|
Events (click, hover, focus) |
'click'
|
html
|
bool
|
Allow HTML in content |
False
|
tag
|
str
|
HTML tag for wrapper |
'span'
|
container
|
str | None
|
Container to append to ("body" avoids containment issues) |
'body'
|
**kwargs
|
Any
|
Additional HTML attributes |
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
FastHTML element with popover attributes |
Example
Popover("Title", "Content here", Button("Click me"))