@@ -108,9 +108,33 @@ def compose(self) -> ComposeResult:
108108 with pytest .raises (ValueError ):
109109 tabbed_content .active = "X"
110110
111- # Check fail with empty tab
112- with pytest .raises (ValueError ):
113- tabbed_content .active = ""
111+
112+ async def test_unsetting_tabbed_content_active ():
113+ """Check that setting `TabbedContent.active = ""` unsets active tab."""
114+
115+ messages = []
116+
117+ class TabbedApp (App [None ]):
118+ def compose (self ) -> ComposeResult :
119+ with TabbedContent (initial = "bar" ):
120+ with TabPane ("foo" , id = "foo" ):
121+ yield Label ("Foo" , id = "foo-label" )
122+ with TabPane ("bar" , id = "bar" ):
123+ yield Label ("Bar" , id = "bar-label" )
124+ with TabPane ("baz" , id = "baz" ):
125+ yield Label ("Baz" , id = "baz-label" )
126+
127+ def on_tabbed_content_cleared (self , event : TabbedContent .Cleared ) -> None :
128+ messages .append (event )
129+
130+ app = TabbedApp ()
131+ async with app .run_test () as pilot :
132+ tabbed_content = app .query_one (TabbedContent )
133+ assert bool (tabbed_content .active )
134+ tabbed_content .active = ""
135+ await pilot .pause ()
136+ assert len (messages ) == 1
137+ assert isinstance (messages [0 ], TabbedContent .Cleared )
114138
115139
116140async def test_tabbed_content_initial ():
0 commit comments