@@ -276,7 +276,11 @@ def __rich_repr__(self) -> Result:
276276 yield self .pane
277277
278278 class Cleared (Message ):
279- """Posted when there are no more tab panes."""
279+ """Posted when no tab pane is active.
280+
281+ This can happen if all tab panes are removed or if the currently active tab
282+ pane is unset.
283+ """
280284
281285 def __init__ (self , tabbed_content : TabbedContent ) -> None :
282286 """Initialize message.
@@ -329,22 +333,6 @@ def active_pane(self) -> TabPane | None:
329333 return None
330334 return self .get_pane (self .active )
331335
332- def validate_active (self , active : str ) -> str :
333- """It doesn't make sense for `active` to be an empty string.
334-
335- Args:
336- active: Attribute to be validated.
337-
338- Returns:
339- Value of `active`.
340-
341- Raises:
342- ValueError: If the active attribute is set to empty string when there are tabs available.
343- """
344- if not active and self .get_child_by_type (ContentSwitcher ).current :
345- raise ValueError ("'active' tab must not be empty string." )
346- return active
347-
348336 @staticmethod
349337 def _set_id (content : TabPane , new_id : int ) -> TabPane :
350338 """Set an id on the content, if not already present.
@@ -467,8 +455,6 @@ def remove_pane(self, pane_id: str) -> AwaitComplete:
467455
468456 async def _remove_content () -> None :
469457 await gather (* removal_awaitables )
470- if self .tab_count == 0 :
471- self .post_message (self .Cleared (self ).set_sender (self ))
472458
473459 return AwaitComplete (_remove_content ())
474460
@@ -486,7 +472,6 @@ def clear_panes(self) -> AwaitComplete:
486472
487473 async def _clear_content () -> None :
488474 await await_clear
489- self .post_message (self .Cleared (self ).set_sender (self ))
490475
491476 return AwaitComplete (_clear_content ())
492477
@@ -547,7 +532,7 @@ def _is_associated_tabs(self, tabs: Tabs) -> bool:
547532
548533 def _watch_active (self , active : str ) -> None :
549534 """Switch tabs when the active attributes changes."""
550- with self .prevent (Tabs .TabActivated ):
535+ with self .prevent (Tabs .TabActivated , Tabs . Cleared ):
551536 self .get_child_by_type (ContentTabs ).active = ContentTab .add_prefix (active )
552537 self .get_child_by_type (ContentSwitcher ).current = active
553538 if active :
@@ -557,6 +542,10 @@ def _watch_active(self, active: str) -> None:
557542 tab = self .get_child_by_type (ContentTabs ).get_content_tab (active ),
558543 )
559544 )
545+ else :
546+ self .post_message (
547+ TabbedContent .Cleared (tabbed_content = self ).set_sender (self )
548+ )
560549
561550 @property
562551 def tab_count (self ) -> int :
0 commit comments