Skip to content

Commit 3a7cf08

Browse files
Make scrollable containers focusable. (#2317)
* Make scrollable containers focusable. Related issues: #2270.
1 parent 496f8b4 commit 3a7cf08

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1414
- A clicked tab will now be scrolled to the center of its tab container https://github.com/Textualize/textual/pull/2276
1515
- Style updates are now done immediately rather than on_idle https://github.com/Textualize/textual/pull/2304
1616
- `ButtonVariant` is now exported from `textual.widgets.button` https://github.com/Textualize/textual/issues/2264
17+
- `HorizontalScroll` and `VerticalScroll` are now focusable by default https://github.com/Textualize/textual/pull/2317
1718

1819
### Added
1920

src/textual/containers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Vertical(Widget):
3131
"""
3232

3333

34-
class VerticalScroll(Widget):
34+
class VerticalScroll(Widget, can_focus=True):
3535
"""A container which arranges children vertically, with an automatic vertical scrollbar."""
3636

3737
DEFAULT_CSS = """
@@ -55,7 +55,7 @@ class Horizontal(Widget):
5555
"""
5656

5757

58-
class HorizontalScroll(Widget):
58+
class HorizontalScroll(Widget, can_focus=True):
5959
"""A container which arranges children horizontally, with an automatic horizontal scrollbar."""
6060

6161
DEFAULT_CSS = """

tests/snapshot_tests/test_snapshots.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def test_input_and_focus(snap_compare):
8787

8888
def test_buttons_render(snap_compare):
8989
# Testing button rendering. We press tab to focus the first button too.
90-
assert snap_compare(WIDGET_EXAMPLES_DIR / "button.py", press=["tab"])
90+
assert snap_compare(WIDGET_EXAMPLES_DIR / "button.py", press=["tab", "tab"])
9191

9292

9393
def test_placeholder_render(snap_compare):
@@ -269,7 +269,7 @@ def test_programmatic_scrollbar_gutter_change(snap_compare):
269269

270270

271271
def test_borders_preview(snap_compare):
272-
assert snap_compare(CLI_PREVIEWS_DIR / "borders.py", press=["tab", "enter"])
272+
assert snap_compare(CLI_PREVIEWS_DIR / "borders.py", press=["tab", "tab", "enter"])
273273

274274

275275
def test_colors_preview(snap_compare):
@@ -325,7 +325,9 @@ def test_disabled_widgets(snap_compare):
325325

326326

327327
def test_focus_component_class(snap_compare):
328-
assert snap_compare(SNAPSHOT_APPS_DIR / "focus_component_class.py", press=["tab"])
328+
assert snap_compare(
329+
SNAPSHOT_APPS_DIR / "focus_component_class.py", press=["tab", "tab"]
330+
)
329331

330332

331333
def test_line_api_scrollbars(snap_compare):

0 commit comments

Comments
 (0)