Skip to content

Commit

Permalink
change collapsible title to static
Browse files Browse the repository at this point in the history
  • Loading branch information
TomJGooding committed Dec 13, 2023
1 parent 86204fa commit ed46ddb
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/textual/widgets/_collapsible.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
from __future__ import annotations

from rich.console import RenderableType
from rich.text import Text

from .. import events
from ..app import ComposeResult
from ..binding import Binding
Expand All @@ -11,11 +8,12 @@
from ..message import Message
from ..reactive import reactive
from ..widget import Widget
from ..widgets import Static

__all__ = ["Collapsible", "CollapsibleTitle"]


class CollapsibleTitle(Widget, can_focus=True):
class CollapsibleTitle(Static, can_focus=True):
"""Title and symbol for the Collapsible."""

DEFAULT_CSS = """
Expand Down Expand Up @@ -59,6 +57,8 @@ def __init__(
self.expanded_symbol = expanded_symbol
self.label = label
self.collapsed = collapsed
self._collapsed_label = f"{collapsed_symbol} {label}"
self._expanded_label = f"{expanded_symbol} {label}"

class Toggle(Message):
"""Request toggle."""
Expand All @@ -72,12 +72,19 @@ def action_toggle(self) -> None:
"""Toggle the state of the parent collapsible."""
self.post_message(self.Toggle())

def render(self) -> RenderableType:
"""Compose right/down arrow and label."""
def _watch_label(self, label: str) -> None:
self._collapsed_label = f"{self.collapsed_symbol} {label}"
self._expanded_label = f"{self.expanded_symbol} {label}"
if self.collapsed:
return Text(f"{self.collapsed_symbol} {self.label}")
self.update(self._collapsed_label)
else:
self.update(self._expanded_label)

def _watch_collapsed(self, collapsed: bool) -> None:
if collapsed:
self.update(self._collapsed_label)
else:
return Text(f"{self.expanded_symbol} {self.label}")
self.update(self._expanded_label)


class Collapsible(Widget):
Expand Down

0 comments on commit ed46ddb

Please sign in to comment.