Skip to content

Commit

Permalink
Merge pull request Textualize#5515 from Textualize/visual-tooltip
Browse files Browse the repository at this point in the history
visual tooltips
  • Loading branch information
willmcgugan authored Feb 12, 2025
2 parents fecdc77 + 841fdf4 commit 40dddf9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/textual/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
from textual.selection import Selection
from textual.strip import Strip
from textual.style import Style as VisualStyle
from textual.visual import Visual, visualize
from textual.visual import Visual, VisualType, visualize

if TYPE_CHECKING:
from textual.app import App, ComposeResult
Expand Down Expand Up @@ -452,7 +452,7 @@ def __init__(
self._rich_style_cache: dict[tuple[str, ...], tuple[Style, Style]] = {}
self._visual_style_cache: dict[tuple[str, ...], VisualStyle] = {}

self._tooltip: RenderableType | None = None
self._tooltip: VisualType | None = None
"""The tooltip content."""
self.absolute_offset: Offset | None = None
"""Force an absolute offset for the widget (used by tooltips)."""
Expand Down Expand Up @@ -709,12 +709,12 @@ def _check_disabled(self) -> bool:
return self.disabled or self.loading

@property
def tooltip(self) -> RenderableType | None:
def tooltip(self) -> VisualType | None:
"""Tooltip for the widget, or `None` for no tooltip."""
return self._tooltip

@tooltip.setter
def tooltip(self, tooltip: RenderableType | None):
def tooltip(self, tooltip: VisualType | None):
self._tooltip = tooltip
try:
self.screen._update_tooltip(self)
Expand Down
28 changes: 28 additions & 0 deletions tests/snapshot_tests/test_snapshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
VerticalScroll,
HorizontalGroup,
)
from textual.content import Content
from textual.pilot import Pilot
from textual.reactive import var
from textual.renderables.gradient import LinearGradient
Expand Down Expand Up @@ -3549,3 +3550,30 @@ async def run_before(pilot: Pilot) -> None:
await pilot.pause(0.4)

snap_compare(FocusTest(), run_before=run_before)


def test_visual_tooltip(snap_compare):
"""Test Visuals such as Content work in tooltips.
You should see a tooltip under a label.
The tooltip should have the word "Tooltip" highlighted in the accent color.
"""

class TooltipApp(App[None]):
TOOLTIP_DELAY = 0.4

def compose(self) -> ComposeResult:
progress_bar = Label("Hello, World")
progress_bar.tooltip = Content.from_markup(
"Hello, [bold $accent]Tooltip[/]!"
)
yield progress_bar

async def run_before(pilot: Pilot) -> None:
await pilot.pause()
await pilot.hover(Label)
await pilot.pause(0.4)
await pilot.pause()

snap_compare(TooltipApp(), run_before=run_before)

0 comments on commit 40dddf9

Please sign in to comment.