From 318b5f772e5b3dd8fb8e20da42306dc235040234 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: Tue, 18 Apr 2023 11:10:55 +0100 Subject: [PATCH 1/2] Make scrollable containers focusable. Related issues: #2270. --- src/textual/containers.py | 4 ++-- tests/snapshot_tests/test_snapshots.py | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/textual/containers.py b/src/textual/containers.py index 99605ace70..9d6c35b7f6 100644 --- a/src/textual/containers.py +++ b/src/textual/containers.py @@ -31,7 +31,7 @@ class Vertical(Widget): """ -class VerticalScroll(Widget): +class VerticalScroll(Widget, can_focus=True): """A container which arranges children vertically, with an automatic vertical scrollbar.""" DEFAULT_CSS = """ @@ -55,7 +55,7 @@ class Horizontal(Widget): """ -class HorizontalScroll(Widget): +class HorizontalScroll(Widget, can_focus=True): """A container which arranges children horizontally, with an automatic horizontal scrollbar.""" DEFAULT_CSS = """ diff --git a/tests/snapshot_tests/test_snapshots.py b/tests/snapshot_tests/test_snapshots.py index e8bde50c72..2ab2ba63c3 100644 --- a/tests/snapshot_tests/test_snapshots.py +++ b/tests/snapshot_tests/test_snapshots.py @@ -87,7 +87,7 @@ def test_input_and_focus(snap_compare): def test_buttons_render(snap_compare): # Testing button rendering. We press tab to focus the first button too. - assert snap_compare(WIDGET_EXAMPLES_DIR / "button.py", press=["tab"]) + assert snap_compare(WIDGET_EXAMPLES_DIR / "button.py", press=["tab", "tab"]) def test_placeholder_render(snap_compare): @@ -269,7 +269,7 @@ def test_programmatic_scrollbar_gutter_change(snap_compare): def test_borders_preview(snap_compare): - assert snap_compare(CLI_PREVIEWS_DIR / "borders.py", press=["tab", "enter"]) + assert snap_compare(CLI_PREVIEWS_DIR / "borders.py", press=["tab", "tab", "enter"]) def test_colors_preview(snap_compare): @@ -325,7 +325,9 @@ def test_disabled_widgets(snap_compare): def test_focus_component_class(snap_compare): - assert snap_compare(SNAPSHOT_APPS_DIR / "focus_component_class.py", press=["tab"]) + assert snap_compare( + SNAPSHOT_APPS_DIR / "focus_component_class.py", press=["tab", "tab"] + ) def test_line_api_scrollbars(snap_compare): From b3286402f15376f7fa3e209184cd1708f3136a37 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: Tue, 18 Apr 2023 11:11:58 +0100 Subject: [PATCH 2/2] Changelog. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 26b46f0b9e..ec2de8a072 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Breaking change: Timer.start is now private, and returns No - A clicked tab will now be scrolled to the center of its tab container https://github.com/Textualize/textual/pull/2276 - `ButtonVariant` is now exported from `textual.widgets.button` https://github.com/Textualize/textual/issues/2264 +- `HorizontalScroll` and `VerticalScroll` are now focusable by default https://github.com/Textualize/textual/pull/2317 ### Added