Skip to content

Commit

Permalink
Revert "Prevent reactive-watcher loop in Tabs / TabbedContent." (#2322)
Browse files Browse the repository at this point in the history
* Revert "Prevent reactive-watcher loop in Tabs / TabbedContent. (#2305)"

This reverts commit 66a6448.

* fix stuck tab

* fix for stuck underline

* snpshot
  • Loading branch information
willmcgugan authored Apr 18, 2023
1 parent cc41a7f commit 4981eff
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/).

## [0.20.1] - 2023-04-18

### Fix

- New fix for stuck tabs underline https://github.com/Textualize/textual/issues/2229

## [0.20.0] - 2023-04-18

### Changed
Expand Down Expand Up @@ -32,7 +38,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Fix empty ListView preventing bindings from firing https://github.com/Textualize/textual/pull/2281
- Fix `get_component_styles` returning incorrect values on first call when combined with pseudoclasses https://github.com/Textualize/textual/pull/2304
- Fixed `active_message_pump.get` sometimes resulting in a `LookupError` https://github.com/Textualize/textual/issues/2301
- Fixed issue arising when active tab was changed too quickly in succession https://github.com/Textualize/textual/pull/2305

## [0.19.1] - 2023-04-10

Expand Down Expand Up @@ -769,6 +774,7 @@ https://textual.textualize.io/blog/2022/11/08/version-040/#version-040
- New handler system for messages that doesn't require inheritance
- Improved traceback handling

[0.20.1]: https://github.com/Textualize/textual/compare/v0.20.0...v0.20.1
[0.20.0]: https://github.com/Textualize/textual/compare/v0.19.1...v0.20.0
[0.19.1]: https://github.com/Textualize/textual/compare/v0.19.0...v0.19.1
[0.19.0]: https://github.com/Textualize/textual/compare/v0.18.0...v0.19.0
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "textual"
version = "0.20.0"
version = "0.20.1"
homepage = "https://github.com/Textualize/textual"
description = "Modern Text User Interface framework"
authors = ["Will McGugan <[email protected]>"]
Expand Down
28 changes: 21 additions & 7 deletions src/textual/widgets/_tabbed_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ class TabbedContent(Widget):
}
"""

active: reactive[str] = reactive("", init=False)
"""The ID of the active tab, or empty string if none are active."""

class TabActivated(Message):
"""Posted when the active tab changes."""

Expand Down Expand Up @@ -113,16 +116,21 @@ def __init__(self, *titles: TextType, initial: str = "") -> None:
self._initial = initial
super().__init__()

@property
def active(self) -> str:
"""The ID of the active tab, or empty string if none are active."""
return self.get_child_by_type(Tabs).active
def validate_active(self, active: str) -> str:
"""It doesn't make sense for `active` to be an empty string.
Args:
active: Attribute to be validated.
Returns:
Value of `active`.
@active.setter
def active(self, active: str) -> None:
Raises:
ValueError: If the active attribute is set to empty string.
"""
if not active:
raise ValueError("'active' tab must not be empty string.")
self.get_child_by_type(Tabs).active = active
return active

def compose(self) -> ComposeResult:
"""Compose the tabbed content."""
Expand Down Expand Up @@ -178,6 +186,7 @@ def _on_tabs_tab_activated(self, event: Tabs.TabActivated) -> None:
switcher = self.get_child_by_type(ContentSwitcher)
assert isinstance(event.tab, ContentTab)
switcher.current = event.tab.id
self.active = event.tab.id
self.post_message(
TabbedContent.TabActivated(
tabbed_content=self,
Expand All @@ -188,3 +197,8 @@ def _on_tabs_tab_activated(self, event: Tabs.TabActivated) -> None:
def _on_tabs_cleared(self, event: Tabs.Cleared) -> None:
"""All tabs were removed."""
event.stop()

def watch_active(self, active: str) -> None:
"""Switch tabs when the active attributes changes."""
with self.prevent(Tabs.TabActivated):
self.get_child_by_type(Tabs).active = active

0 comments on commit 4981eff

Please sign in to comment.