Skip to content

Commit 07c3d5c

Browse files
committed
Merge branch 'add-deprecation-warnings-for-output_txt_verbatim' of https://github.com/posit-dev/py-shiny into add-deprecation-warnings-for-output_txt_verbatim
2 parents 5d6a1fd + 2f04413 commit 07c3d5c

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
* `ui.output_text_verbatim()` is deprecated. Please use `ui.output_text()` if you want to create an output container for some text, or `ui.output_code()` if you want to create an output container for code (monospaced text). (#2097)
1313

14+
### Bug fixes
15+
16+
* Fixed `ui.tooltip()`'s `options` parameter to properly pass Bootstrap tooltip options to the underlying web component. (#2101)
17+
1418
## [1.5.0] - 2025-09-11
1519

1620
### 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)