From 33a470f56965bed37104fb2e609bf32ca3948610 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodrigo=20Gir=C3=A3o=20Serr=C3=A3o?= <5621605+rodrigogiraoserrao@users.noreply.github.com> Date: Mon, 22 May 2023 11:45:40 +0100 Subject: [PATCH 1/2] Fix footer highlight when pushing modal. --- CHANGELOG.md | 1 + src/textual/widgets/_footer.py | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ba7ec1535..d838c46f50 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Changed - `Placeholder` now sets its color cycle per app https://github.com/Textualize/textual/issues/2590 +- Footer now clears key highlight regardless of whether it's in the active screen or not https://github.com/Textualize/textual/issues/2606 ### Removed diff --git a/src/textual/widgets/_footer.py b/src/textual/widgets/_footer.py index a52e05785d..b5e772ab60 100644 --- a/src/textual/widgets/_footer.py +++ b/src/textual/widgets/_footer.py @@ -79,8 +79,7 @@ def _on_mouse_move(self, event: events.MouseMove) -> None: def _on_leave(self, _: events.Leave) -> None: """Clear any highlight when the mouse leaves the widget""" - if self.screen.is_current: - self.highlight_key = None + self.highlight_key = None def __rich_repr__(self) -> rich.repr.Result: yield from super().__rich_repr__() From c32d5d3c25321bb3d1b7930ec1ac96c2046a14e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodrigo=20Gir=C3=A3o=20Serr=C3=A3o?= <5621605+rodrigogiraoserrao@users.noreply.github.com> Date: Mon, 22 May 2023 13:53:58 +0100 Subject: [PATCH 2/2] Add regression test for #2606. --- tests/test_footer.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 tests/test_footer.py diff --git a/tests/test_footer.py b/tests/test_footer.py new file mode 100644 index 0000000000..26e46cf29f --- /dev/null +++ b/tests/test_footer.py @@ -0,0 +1,28 @@ +from textual.app import App, ComposeResult +from textual.geometry import Offset +from textual.screen import ModalScreen +from textual.widgets import Footer, Label + + +async def test_footer_highlight_when_pushing_modal(): + """Regression test for https://github.com/Textualize/textual/issues/2606""" + + class MyModalScreen(ModalScreen): + def compose(self) -> ComposeResult: + yield Label("apple") + + class MyApp(App[None]): + BINDINGS = [("a", "p", "push")] + + def compose(self) -> ComposeResult: + yield Footer() + + def action_p(self): + self.push_screen(MyModalScreen()) + + app = MyApp() + async with app.run_test(size=(80, 2)) as pilot: + await pilot.hover(None, Offset(0, 1)) + await pilot.click(None, Offset(0, 1)) + assert isinstance(app.screen, MyModalScreen) + assert app.screen_stack[0].query_one(Footer).highlight_key is None