diff --git a/CHANGELOG.md b/CHANGELOG.md index 4228e04c3c..fb0d40657c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## Unreleased + +### Changed + +- Tooltips are now inherited, so will work with compound widgets + ## [0.28.0] - 2023-06-19 ### Added @@ -18,7 +24,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Added `origin_visible` parameter to `Widget.scroll_to_region` - Added `origin_visible` parameter to `Widget.scroll_to_center` - Added `TabbedContent.tab_count` https://github.com/Textualize/textual/pull/2751 -- Added `TabbedContnet.add_pane` https://github.com/Textualize/textual/pull/2751 +- Added `TabbedContent.add_pane` https://github.com/Textualize/textual/pull/2751 - Added `TabbedContent.remove_pane` https://github.com/Textualize/textual/pull/2751 - Added `TabbedContent.clear_panes` https://github.com/Textualize/textual/pull/2751 - Added `TabbedContent.Cleared` https://github.com/Textualize/textual/pull/2751 diff --git a/src/textual/screen.py b/src/textual/screen.py index 505ee34338..1ff2a4a4e5 100644 --- a/src/textual/screen.py +++ b/src/textual/screen.py @@ -768,7 +768,14 @@ def _handle_tooltip_timer(self, widget: Widget) -> None: except NoMatches: pass else: - tooltip_content = widget.tooltip + tooltip_content: RenderableType | None = None + for node in widget.ancestors_with_self: + if not isinstance(node, Widget): + break + if node.tooltip is not None: + tooltip_content = node.tooltip + break + if tooltip_content is None: tooltip.display = False else: diff --git a/tests/snapshot_tests/__snapshots__/test_snapshots.ambr b/tests/snapshot_tests/__snapshots__/test_snapshots.ambr index da22db70ba..0856df5f65 100644 --- a/tests/snapshot_tests/__snapshots__/test_snapshots.ambr +++ b/tests/snapshot_tests/__snapshots__/test_snapshots.ambr @@ -26255,6 +26255,164 @@ ''' # --- +# name: test_tooltips_in_compound_widgets + ''' + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + TooltipApp + + + + + + + + + + ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━10%--:--:-- + + Hello, Tooltip! + + + + + + + + + + + + + + + + + + + + + + + + + + ''' +# --- # name: test_tree_example ''' diff --git a/tests/snapshot_tests/snapshot_apps/tooltips.py b/tests/snapshot_tests/snapshot_apps/tooltips.py new file mode 100644 index 0000000000..bc55542d71 --- /dev/null +++ b/tests/snapshot_tests/snapshot_apps/tooltips.py @@ -0,0 +1,15 @@ +from textual.app import App, ComposeResult +from textual.widgets import ProgressBar + + +class TooltipApp(App[None]): + def compose(self) -> ComposeResult: + progress_bar = ProgressBar(100) + progress_bar.advance(10) + progress_bar.tooltip = "Hello, Tooltip!" + yield progress_bar + + +if __name__ == "__main__": + app = TooltipApp() + app.run() diff --git a/tests/snapshot_tests/test_snapshots.py b/tests/snapshot_tests/test_snapshots.py index 2d9229e179..c9c4c14ac6 100644 --- a/tests/snapshot_tests/test_snapshots.py +++ b/tests/snapshot_tests/test_snapshots.py @@ -213,9 +213,11 @@ def test_tabbed_content(snap_compare): def test_option_list_strings(snap_compare): assert snap_compare(WIDGET_EXAMPLES_DIR / "option_list_strings.py") + def test_option_list_options(snap_compare): assert snap_compare(WIDGET_EXAMPLES_DIR / "option_list_options.py") + def test_option_list_tables(snap_compare): assert snap_compare(WIDGET_EXAMPLES_DIR / "option_list_tables.py") @@ -562,3 +564,13 @@ def test_blur_on_disabled(snap_compare): SNAPSHOT_APPS_DIR / "blur_on_disabled.py", press=[*"foo", "f3", *"this should not appear"], ) + + +def test_tooltips_in_compound_widgets(snap_compare): + # https://github.com/Textualize/textual/issues/2641 + async def run_before(pilot) -> None: + await pilot.hover("ProgressBar") + await pilot.pause(0.3) + await pilot.pause() + + assert snap_compare(SNAPSHOT_APPS_DIR / "tooltips.py", run_before=run_before)