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 for empty ListView bindings not firing #2281

Merged
merged 3 commits into from
Apr 13, 2023
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased

### Changed
### Changed

- Changed signature of Driver. Technically a breaking change, but unlikely to affect anyone.
- Breaking change: Timer.start is now private, and returns No
Expand All @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Fixed

- Fixed order styles are applied in DataTable - allows combining of renderable styles and component classes https://github.com/Textualize/textual/pull/2272
- Fix empty ListView preventing bindings from firing https://github.com/Textualize/textual/pull/2281


## [0.19.1] - 2023-04-10
Expand Down
2 changes: 1 addition & 1 deletion src/textual/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2149,7 +2149,7 @@ async def run_action(
action_target = getattr(self, destination)
implicit_destination = True
else:
action_target = default_namespace or self
action_target = default_namespace if default_namespace is not None else self
action_name = target

handled = await self._dispatch_action(action_target, action_name, params)
Expand Down
15 changes: 15 additions & 0 deletions tests/listview/test_inherit_listview.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
from textual.app import App, ComposeResult
from textual.binding import Binding
from textual.widgets import Label, ListItem, ListView


class MyListView(ListView):
"""Test child class of a ListView."""

BINDINGS = [Binding(key="s", action="set", description="Set")]

def __init__(self, items: int = 0) -> None:
super().__init__()
self._items = items
self.action_fired = False

def compose(self) -> ComposeResult:
"""Compose the child widgets."""
for n in range(self._items):
yield ListItem(Label(f"This is item {n}"))

def action_set(self) -> None:
self.action_fired = True


class ListViewApp(App[None]):
"""ListView test app."""
Expand Down Expand Up @@ -43,3 +50,11 @@ async def test_populated_inherited_list_view() -> None:
assert pilot.app.query_one(MyListView).index == 0
await pilot.press("down")
assert pilot.app.query_one(MyListView).index == 1


async def test_actions_work_when_list_view_empty() -> None:
"""Regression test for https://github.com/Textualize/textual/issues/2265"""
async with ListViewApp().run_test() as pilot:
await pilot.press("tab", "s")
list_view = pilot.app.query_one(MyListView)
assert list_view.action_fired