Skip to content

Commit

Permalink
Merge pull request #5233 from TomJGooding/fix-tabs-update-highlightin…
Browse files Browse the repository at this point in the history
…g-when-tab-removed

fix(tabs): update highlighting when tab removed
  • Loading branch information
willmcgugan authored Nov 16, 2024
2 parents bbfd882 + 46a9fa0 commit 1af8e33
Show file tree
Hide file tree
Showing 4 changed files with 184 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

- Fixed duplicated key displays in the help panel https://github.com/Textualize/textual/issues/5037
- Fixed `TextArea` mouse selection with tab characters https://github.com/Textualize/textual/issues/5212
- Fixed `Tabs` not updating the highlighting after removing a tab https://github.com/Textualize/textual/issues/5218

### Added

Expand Down
6 changes: 4 additions & 2 deletions src/textual/widgets/_tabs.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,10 +556,12 @@ def remove_tab(self, tab_or_id: Tab | str | None) -> AwaitComplete:
async def do_remove() -> None:
"""Perform the remove after refresh so the underline bar gets new positions."""
await remove_tab.remove()
if next_tab is not None:
self.active = next_tab.id or ""
if not self.query("#tabs-list > Tab"):
self.active = ""
elif next_tab is not None:
self.active = next_tab.id or ""
else:
self._highlight_active(animate=False)

return AwaitComplete(do_remove())

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions tests/snapshot_tests/test_snapshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
SelectionList,
Static,
Switch,
Tab,
Tabs,
TextArea,
)
from textual.widgets.text_area import BUILTIN_LANGUAGES, Selection, TextAreaTheme
Expand Down Expand Up @@ -2547,3 +2549,25 @@ async def run_before(pilot: Pilot):

app = HelpPanelApp()
assert snap_compare(app, run_before=run_before)


def test_tabs_remove_tab_updates_highlighting(snap_compare):
"""Regression test for https://github.com/Textualize/textual/issues/5218"""

class TabsApp(App):
BINDINGS = [("r", "remove_foo", "Remove foo")]

def compose(self) -> ComposeResult:
yield Tabs(
Tab("foo", id="foo"),
Tab("bar", id="bar"),
active="bar",
)
yield Footer()

def action_remove_foo(self) -> None:
tabs = self.query_one(Tabs)
tabs.remove_tab("foo")

app = TabsApp()
assert snap_compare(app, press="r")

0 comments on commit 1af8e33

Please sign in to comment.