Skip to content

Commit

Permalink
Add a remove_pane method to TabbedContent
Browse files Browse the repository at this point in the history
  • Loading branch information
davep committed Jun 6, 2023
1 parent 290351d commit 5cf50f7
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/textual/widgets/_tabbed_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,17 @@ def add_pane(self, pane: TabPane) -> AwaitMount:
pane.display = False
return self.get_child_by_type(ContentSwitcher).mount(pane)

def remove_pane(self, pane_id: str) -> None:
"""Remove a given pane from the tabbed content.
Args:
pane_id: The ID of the pane to remove.
"""
self.get_child_by_type(Tabs).remove_tab(pane_id)
self.call_after_refresh(
self.get_child_by_type(ContentSwitcher).get_child_by_id(pane_id).remove
)

def compose_add_child(self, widget: Widget) -> None:
"""When using the context manager compose syntax, we want to attach nodes to the switcher.
Expand All @@ -237,6 +248,7 @@ 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()
self.get_child_by_type(ContentSwitcher).current = None

def _watch_active(self, active: str) -> None:
"""Switch tabs when the active attributes changes."""
Expand Down

0 comments on commit 5cf50f7

Please sign in to comment.