Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(tabs): update highlighting when tab removed #5233

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
Loading