Skip to content

Commit 4981eff

Browse files
authored
Revert "Prevent reactive-watcher loop in Tabs / TabbedContent." (#2322)
* Revert "Prevent reactive-watcher loop in Tabs / TabbedContent. (#2305)" This reverts commit 66a6448. * fix stuck tab * fix for stuck underline * snpshot
1 parent cc41a7f commit 4981eff

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

8+
## [0.20.1] - 2023-04-18
9+
10+
### Fix
11+
12+
- New fix for stuck tabs underline https://github.com/Textualize/textual/issues/2229
13+
814
## [0.20.0] - 2023-04-18
915

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

3742
## [0.19.1] - 2023-04-10
3843

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

777+
[0.20.1]: https://github.com/Textualize/textual/compare/v0.20.0...v0.20.1
772778
[0.20.0]: https://github.com/Textualize/textual/compare/v0.19.1...v0.20.0
773779
[0.19.1]: https://github.com/Textualize/textual/compare/v0.19.0...v0.19.1
774780
[0.19.0]: https://github.com/Textualize/textual/compare/v0.18.0...v0.19.0

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "textual"
3-
version = "0.20.0"
3+
version = "0.20.1"
44
homepage = "https://github.com/Textualize/textual"
55
description = "Modern Text User Interface framework"
66
authors = ["Will McGugan <[email protected]>"]

src/textual/widgets/_tabbed_content.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ class TabbedContent(Widget):
8383
}
8484
"""
8585

86+
active: reactive[str] = reactive("", init=False)
87+
"""The ID of the active tab, or empty string if none are active."""
88+
8689
class TabActivated(Message):
8790
"""Posted when the active tab changes."""
8891

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

116-
@property
117-
def active(self) -> str:
118-
"""The ID of the active tab, or empty string if none are active."""
119-
return self.get_child_by_type(Tabs).active
119+
def validate_active(self, active: str) -> str:
120+
"""It doesn't make sense for `active` to be an empty string.
121+
122+
Args:
123+
active: Attribute to be validated.
124+
125+
Returns:
126+
Value of `active`.
120127
121-
@active.setter
122-
def active(self, active: str) -> None:
128+
Raises:
129+
ValueError: If the active attribute is set to empty string.
130+
"""
123131
if not active:
124132
raise ValueError("'active' tab must not be empty string.")
125-
self.get_child_by_type(Tabs).active = active
133+
return active
126134

127135
def compose(self) -> ComposeResult:
128136
"""Compose the tabbed content."""
@@ -178,6 +186,7 @@ def _on_tabs_tab_activated(self, event: Tabs.TabActivated) -> None:
178186
switcher = self.get_child_by_type(ContentSwitcher)
179187
assert isinstance(event.tab, ContentTab)
180188
switcher.current = event.tab.id
189+
self.active = event.tab.id
181190
self.post_message(
182191
TabbedContent.TabActivated(
183192
tabbed_content=self,
@@ -188,3 +197,8 @@ def _on_tabs_tab_activated(self, event: Tabs.TabActivated) -> None:
188197
def _on_tabs_cleared(self, event: Tabs.Cleared) -> None:
189198
"""All tabs were removed."""
190199
event.stop()
200+
201+
def watch_active(self, active: str) -> None:
202+
"""Switch tabs when the active attributes changes."""
203+
with self.prevent(Tabs.TabActivated):
204+
self.get_child_by_type(Tabs).active = active

0 commit comments

Comments
 (0)