Skip to content

Cannot return focus to ListView from Select #5416

Closed
@ndjhartman

Description

@ndjhartman

Have you checked closed issues? https://github.com/Textualize/textual/issues?q=is%3Aissue+is%3Aclosed
Yes.

Have you checked against the most recent version of Textual? https://pypi.org/search/?q=textual
Yes.

Issue

Please give a brief but clear explanation of the issue. If you can, include a complete working example that demonstrates the bug. Check it can run without modifications.

After focusing on a Select, I cannot programmatically return focus to a ListView and/or ListItem.

from textual.app import App, ComposeResult
from textual.containers import HorizontalGroup, Container
from textual.widgets import ListView, ListItem, Label, Select

opts = [ "foo", "bar", "zoo" ]

class MyListItem(ListItem):

	def __init__(self, opts: list[str]) -> None:
		self.opts = opts
		self.lab = Label("Hello!")
		self.sel = Select(options=[ (opt, opt) for opt in self.opts ])
		super().__init__()

	def compose(self):
		with HorizontalGroup():
			yield self.lab
			yield self.sel

	def on_select_changed(self, event: Select.Changed):
	        self.app.query_one(MyListView).focus()
                # self.focus()
	
class MyListView(ListView):

	def compose(self):
		yield MyListItem(opts)
		yield MyListItem(opts)
		yield MyListItem(opts)

	def on_list_view_selected(self, event: ListView.Selected):
		event.item.sel.focus()
		event.item.sel.expanded = True

class TUI(App):

	def compose(self):
		with Container():
			yield MyListView()

TUI().run()

What happens:

  1. Hit enter
  2. Focus transfers to Select
  3. Update the Item
  4. Focus is not returned to the ListView or ListItem
  5. Hitting up/down opens the Select rather than navigating the ListView

Expected:

  1. Focus is returned to the ListView or ListItem.
  2. Hitting up/down iterates over the ListItems

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions