Skip to content

Commit 81e55f3

Browse files
committed
tooltip on switch.
1 parent 8f7eb27 commit 81e55f3

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/textual/widgets/_switch.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
from typing import TYPE_CHECKING, ClassVar
44

5+
from rich.console import RenderableType
6+
57
if TYPE_CHECKING:
68
from ..app import RenderResult
79
from ..binding import Binding, BindingType
@@ -110,6 +112,7 @@ def __init__(
110112
id: str | None = None,
111113
classes: str | None = None,
112114
disabled: bool = False,
115+
tooltip: RenderableType | None = None,
113116
):
114117
"""Initialise the switch.
115118
@@ -120,12 +123,15 @@ def __init__(
120123
id: The ID of the switch in the DOM.
121124
classes: The CSS classes of the switch.
122125
disabled: Whether the switch is disabled or not.
126+
tooltip: Optional tooltip.
123127
"""
124128
super().__init__(name=name, id=id, classes=classes, disabled=disabled)
125129
if value:
126130
self.slider_pos = 1.0
127131
self.set_reactive(Switch.value, value)
128132
self._should_animate = animate
133+
if tooltip is not None:
134+
self.tooltip = tooltip
129135

130136
def watch_value(self, value: bool) -> None:
131137
target_slider_pos = 1.0 if value else 0.0

0 commit comments

Comments
 (0)