From 70d5eea2ed971d7f6419bd7ed401c63cd8dda773 Mon Sep 17 00:00:00 2001 From: Thor Whalen <1906276+thorwhalen@users.noreply.github.com> Date: Tue, 20 Oct 2026 06:19:13 +0000 Subject: [PATCH] Render front tooltips as streamlit help= (#26) Co-Authored-By: Claude Sonnet 5.5 --- streamlitfront/elements/elements.py | 5 ++++- streamlitfront/spec_maker.py | 1 + streamlitfront/tests/test_tooltips.py | 26 ++++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 streamlitfront/tests/test_tooltips.py diff --git a/streamlitfront/elements/elements.py b/streamlitfront/elements/elements.py index db107a2..4d1e2e7 100644 --- a/streamlitfront/elements/elements.py +++ b/streamlitfront/elements/elements.py @@ -110,7 +110,7 @@ def render_views(self): class View(FrontContainerBase): def render(self): - st.markdown(f"""## **{self.name}**""") + st.markdown(f"""## **{self.name}**""", help=self.tooltip) self._render_children() @@ -150,6 +150,7 @@ def __init__( use_expander: bool = True, submit_button_label: str = "Submit", authentification: bool = False, + tooltip: str = None, ): super().__init__( obj=obj, @@ -159,6 +160,7 @@ def __init__( display=display, auto_submit=auto_submit, on_submit=on_submit, + tooltip=tooltip, ) self.use_expander = use_expander self.submit_button_label = submit_button_label @@ -272,6 +274,7 @@ def _widget_on_change(self): label="name", key="view_key", value="view_value", + help="tooltip", on_change="_widget_on_change", **input_mapping, ) diff --git a/streamlitfront/spec_maker.py b/streamlitfront/spec_maker.py index 70a0191..f21b2d9 100644 --- a/streamlitfront/spec_maker.py +++ b/streamlitfront/spec_maker.py @@ -35,6 +35,7 @@ ELEMENT_KEY: App, Callable: { ELEMENT_KEY: View, + "tooltips": True, "description": { ELEMENT_KEY: TextSection, }, diff --git a/streamlitfront/tests/test_tooltips.py b/streamlitfront/tests/test_tooltips.py new file mode 100644 index 0000000..3eb7f33 --- /dev/null +++ b/streamlitfront/tests/test_tooltips.py @@ -0,0 +1,26 @@ +"""Docs of a function flow into streamlit's ``help=`` (streamlitfront#26).""" + +from streamlit.testing.v1 import AppTest + +_SCRIPT = ''' +from streamlitfront import mk_app + +def foo(a: int = 1, b: str = "x"): + """Summary line. + + :param a: the a + :param b: the b + """ + return a + +mk_app([foo])() +''' + + +def test_docs_become_help(): + at = AppTest.from_string(_SCRIPT) + at.run() + assert not at.exception + assert at.number_input[0].help == "the a" + assert at.text_input[0].help == "the b" + assert any(m.help == "Summary line." for m in at.markdown)