Skip to content

Commit c1d5941

Browse files
Copilotschloerkekarangattu
authored
fix(ui): tooltip(options=) to use bsOptions DOM attribute (#2101)
Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: schloerke <[email protected]> Co-authored-by: Barret Schloerke <[email protected]> Co-authored-by: karangattu <[email protected]> Co-authored-by: Karan Gathani <[email protected]>
1 parent 631be6f commit c1d5941

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to Shiny for Python will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [UNRELEASED]
9+
10+
### Bug fixes
11+
12+
* Fixed `ui.tooltip()`'s `options` parameter to properly pass Bootstrap tooltip options to the underlying web component. (#2101)
13+
814
## [1.5.0] - 2025-09-11
915

1016
### New features

shiny/ui/_tooltip.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def fa_info_circle(title: str):
144144
{
145145
"id": resolve_id_or_none(id),
146146
"placement": placement,
147-
"options": json.dumps(options) if options else None,
147+
"bsOptions": json.dumps(options) if options else None,
148148
},
149149
attrs,
150150
# Use display:none instead of <template> since shiny.js

tests/pytest/test_ui.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,3 +189,36 @@ def test__update_options():
189189
assert _update_options(d4, remove_button=True, multiple=True) == d4
190190
assert _update_options(d4, remove_button=True, multiple=False) == d4
191191
assert _update_options(d4, remove_button=False, multiple=False) == d4
192+
193+
194+
def test_tooltip_options():
195+
"""Test that tooltip renders options as bsOptions attribute."""
196+
# Test with options parameter
197+
options_dict: dict[str, object] = {"offset": [0, 100]}
198+
t = ui.tooltip(
199+
ui.input_action_button("btn", "Test"),
200+
"A message",
201+
id="test_tooltip",
202+
placement="right",
203+
options=options_dict,
204+
)
205+
206+
t_str = str(t)
207+
208+
# Should contain bsOptions attribute with JSON-encoded options
209+
assert "bsoptions" in t_str.lower(), "bsOptions attribute should be present"
210+
# Check that the JSON content is present (HTML entities are encoded, so " becomes &quot;)
211+
assert "&quot;offset&quot;" in t_str and (
212+
"[0, 100]" in t_str or "[0,100]" in t_str
213+
), "Options should be JSON-encoded with offset value"
214+
215+
# Test without options parameter
216+
t2 = ui.tooltip(
217+
ui.input_action_button("btn2", "Test2"),
218+
"Another message",
219+
id="test_tooltip2",
220+
)
221+
222+
t2_str = str(t2)
223+
# Should still render properly
224+
assert "bslib-tooltip" in t2_str, "Tooltip should render without options"

0 commit comments

Comments
 (0)