Make scrollable containers focusable. (#2317)

* Make scrollable containers focusable.

Related issues: #2270.
This commit is contained in:
Rodrigo Girão Serrão
2023-04-18 11:44:32 +01:00
committed by GitHub
parent 496f8b4524
commit 3a7cf08ef2
3 changed files with 8 additions and 5 deletions

View File

@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- A clicked tab will now be scrolled to the center of its tab container https://github.com/Textualize/textual/pull/2276 - A clicked tab will now be scrolled to the center of its tab container https://github.com/Textualize/textual/pull/2276
- Style updates are now done immediately rather than on_idle https://github.com/Textualize/textual/pull/2304 - Style updates are now done immediately rather than on_idle https://github.com/Textualize/textual/pull/2304
- `ButtonVariant` is now exported from `textual.widgets.button` https://github.com/Textualize/textual/issues/2264 - `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 ### Added

View File

@@ -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.""" """A container which arranges children vertically, with an automatic vertical scrollbar."""
DEFAULT_CSS = """ 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.""" """A container which arranges children horizontally, with an automatic horizontal scrollbar."""
DEFAULT_CSS = """ DEFAULT_CSS = """

View File

@@ -87,7 +87,7 @@ def test_input_and_focus(snap_compare):
def test_buttons_render(snap_compare): def test_buttons_render(snap_compare):
# Testing button rendering. We press tab to focus the first button too. # 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): def test_placeholder_render(snap_compare):
@@ -269,7 +269,7 @@ def test_programmatic_scrollbar_gutter_change(snap_compare):
def test_borders_preview(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): def test_colors_preview(snap_compare):
@@ -325,7 +325,9 @@ def test_disabled_widgets(snap_compare):
def test_focus_component_class(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): def test_line_api_scrollbars(snap_compare):