Focus on ScrollableContainers only if Scroll is present #3420
Replies: 1 comment 2 replies
-
To best address this I feel it would need a MRE of the kind of situation you were looking at, and also mention of which scrollable containers you have in mind. I'm going to guess for now that from textual.app import App, ComposeResult
from textual.containers import Horizontal, VerticalScroll
from textual.widgets import Button, Static
class ScrollAndFocusApp(App[None]):
def compose(self) -> ComposeResult:
with Horizontal():
with VerticalScroll():
for n in range(256):
yield Static(f"This is widget {n}")
with VerticalScroll():
yield Static("\n".join([f"This is line {n}" for n in range(256)]))
with VerticalScroll():
for n in range(256):
yield Button(f"This is button {n}")
if __name__ == "__main__":
ScrollAndFocusApp().run() The first two instance of The third container is, I would agree, a little different. It contains widgets which themselves can receive focus, and in this case I'd feel that it makes no sense for the In this case I'd probably change the above code to be more like this: with VerticalScroll() as buttons:
buttons.can_focus = False
for n in range(256):
yield Button(f"This is button {n}") In that instance the container still scrolls with arrow keys, with the mouse and also keeps the focused button in view too. So, the general rule I'd personally follow is: if the Hopefully that explains the thinking and approach here, and makes a wee bit more sense. Also, if your requirement is one that's not anticipated here, perhaps you could write something similar to better illustrate the surprise you experienced? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I was quite surprised to see that scrolling containers have focus all the time, not just when the scroll is present. This was very confusing for me as I moved around app and had one blind focus and for a long time I didn't know which element was stealing it. We solved the problem in our app, but shouldn't this behaviour be basic?
Beta Was this translation helpful? Give feedback.
All reactions