Skip to content

Commit 3d45627

Browse files
committed
added snapshot
1 parent 1668472 commit 3d45627

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1111
### Fixed
1212

1313
- Fixed `Pilot.click` not working with `times` parameter https://github.com/Textualize/textual/pull/5398
14+
- Fixed select refocusing itself too late
1415

1516
### Added
1617

tests/snapshot_tests/test_snapshots.py

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,15 @@
1111
from textual.app import App, ComposeResult
1212
from textual.binding import Binding
1313
from textual.command import SimpleCommand
14-
from textual.containers import Center, Container, Grid, Middle, Vertical, VerticalScroll
14+
from textual.containers import (
15+
Center,
16+
Container,
17+
Grid,
18+
Middle,
19+
Vertical,
20+
VerticalScroll,
21+
HorizontalGroup,
22+
)
1523
from textual.pilot import Pilot
1624
from textual.renderables.gradient import LinearGradient
1725
from textual.screen import ModalScreen, Screen
@@ -22,6 +30,8 @@
2230
Header,
2331
Input,
2432
Label,
33+
ListItem,
34+
ListView,
2535
Log,
2636
OptionList,
2737
Placeholder,
@@ -3139,3 +3149,47 @@ def compose(self) -> ComposeResult:
31393149
yield Sidebar()
31403150

31413151
snap_compare(FloatSidebarApp())
3152+
3153+
3154+
def test_select_refocus(snap_compare):
3155+
"""Regression test for https://github.com/Textualize/textual/issues/5416
3156+
3157+
The original bug was that the call to focus had no apparent effect as the Select
3158+
was re-focusing itself after the Changed message was processed.
3159+
3160+
You should see a list view with three items, where the second one is in focus.
3161+
3162+
"""
3163+
opts = ["foo", "bar", "zoo"]
3164+
3165+
class MyListItem(ListItem):
3166+
def __init__(self, opts: list[str]) -> None:
3167+
self.opts = opts
3168+
self.lab = Label("Hello!")
3169+
self.sel = Select(options=[(opt, opt) for opt in self.opts])
3170+
super().__init__()
3171+
3172+
def compose(self):
3173+
with HorizontalGroup():
3174+
yield self.lab
3175+
yield self.sel
3176+
3177+
def on_select_changed(self, event: Select.Changed):
3178+
self.app.query_one(MyListView).focus()
3179+
3180+
class MyListView(ListView):
3181+
def compose(self):
3182+
yield MyListItem(opts)
3183+
yield MyListItem(opts)
3184+
yield MyListItem(opts)
3185+
3186+
def on_list_view_selected(self, event: ListView.Selected):
3187+
event.item.sel.focus()
3188+
event.item.sel.expanded = True
3189+
3190+
class TUI(App):
3191+
def compose(self):
3192+
with Container():
3193+
yield MyListView()
3194+
3195+
snap_compare(TUI(), press=["down", "enter", "down", "down", "enter"])

0 commit comments

Comments
 (0)