Replies: 1 comment 4 replies
|
I think the confusing bit is the meaning of
self.has_focus # the ListView itself is focused
self.has_focus_within # focus is within the ListView subtree, including itselfThat is the same idea as CSS For your goal, I would key the subtitle/title off from textual import on
from textual.events import Focus, Blur
from textual.widgets import ListView
class MyListView(ListView):
@on(Focus)
@on(Blur)
def focus_toggled(self) -> None:
focused = self.has_focus
self.border_title = "focused" if focused else None
self.border_subtitle = NoneOr, if all you need is the visual border, CSS is the cleanest source of truth: MyListView {
border: solid white;
}
MyListView:focus {
border: solid green;
}If you want the initial focused widget to show a title immediately at startup, also call the same update method from |
Uh oh!
There was an error while loading. Please reload this page.
Hi,
with the following code:
The app looks like this right after start:
And when I
TABto switch focus, it looks like this:I'm confused because
ListViewis defined like this:But the behavior above looks like the focus is actually still on whatever is inside the ListView 🤔
Am I missing something? 🙏
PS: My goal is pretty much what the sample does, to update the border subtitle whenever the ListView has or loses focus.
All reactions