Skip to content

Commit 1af8e33

Browse files
authored
Merge pull request #5233 from TomJGooding/fix-tabs-update-highlighting-when-tab-removed
fix(tabs): update highlighting when tab removed
2 parents bbfd882 + 46a9fa0 commit 1af8e33

File tree

4 files changed

+184
-2
lines changed

4 files changed

+184
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1111

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

1516
### Added
1617

src/textual/widgets/_tabs.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -556,10 +556,12 @@ def remove_tab(self, tab_or_id: Tab | str | None) -> AwaitComplete:
556556
async def do_remove() -> None:
557557
"""Perform the remove after refresh so the underline bar gets new positions."""
558558
await remove_tab.remove()
559-
if next_tab is not None:
560-
self.active = next_tab.id or ""
561559
if not self.query("#tabs-list > Tab"):
562560
self.active = ""
561+
elif next_tab is not None:
562+
self.active = next_tab.id or ""
563+
else:
564+
self._highlight_active(animate=False)
563565

564566
return AwaitComplete(do_remove())
565567

Lines changed: 155 additions & 0 deletions
Loading

tests/snapshot_tests/test_snapshots.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
SelectionList,
3131
Static,
3232
Switch,
33+
Tab,
34+
Tabs,
3335
TextArea,
3436
)
3537
from textual.widgets.text_area import BUILTIN_LANGUAGES, Selection, TextAreaTheme
@@ -2547,3 +2549,25 @@ async def run_before(pilot: Pilot):
25472549

25482550
app = HelpPanelApp()
25492551
assert snap_compare(app, run_before=run_before)
2552+
2553+
2554+
def test_tabs_remove_tab_updates_highlighting(snap_compare):
2555+
"""Regression test for https://github.com/Textualize/textual/issues/5218"""
2556+
2557+
class TabsApp(App):
2558+
BINDINGS = [("r", "remove_foo", "Remove foo")]
2559+
2560+
def compose(self) -> ComposeResult:
2561+
yield Tabs(
2562+
Tab("foo", id="foo"),
2563+
Tab("bar", id="bar"),
2564+
active="bar",
2565+
)
2566+
yield Footer()
2567+
2568+
def action_remove_foo(self) -> None:
2569+
tabs = self.query_one(Tabs)
2570+
tabs.remove_tab("foo")
2571+
2572+
app = TabsApp()
2573+
assert snap_compare(app, press="r")

0 commit comments

Comments
 (0)