-
Notifications
You must be signed in to change notification settings - Fork 815
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
Scrollbar getting focus when not visible #3909
Comments
Hey @chrisstjohn, thanks for your issue. When I run To me, it makes sense that the Now, what I'm focusing is a |
@chrisstjohn IDK if this will help you in any way, but I'll leave a link to #3717 |
The dictionary example does now show focus. If you want to implement a widget that is only focusable when it can be scrolled, you can use this pattern: from textual import on
from textual.app import App, ComposeResult
from textual.containers import VerticalScroll
from textual.widgets import Button, Label
class MaybeFocus(VerticalScroll, can_focus=False):
def watch_show_vertical_scrollbar(self) -> None:
self.can_focus = self.show_horizontal_scrollbar or self.show_vertical_scrollbar
def watch_show_horizontal_scrollbar(self) -> None:
self.can_focus = self.show_horizontal_scrollbar or self.show_vertical_scrollbar
class FocusWhenScrollApp(App[None]):
CSS = """
Label {
height: 5;
background: red;
width: 1fr;
}
"""
def compose(self) -> ComposeResult:
yield Button("MORE!")
yield MaybeFocus()
@on(Button.Pressed)
def more(self) -> None:
self.query_one(MaybeFocus).mount(Label("Stuff"))
if __name__ == "__main__":
FocusWhenScrollApp().run() |
Don't forget to star the repository! Follow @textualizeio for Textual updates. |
I have a simple app with an input box, vertical scroll containing markdown, and a button to exit the application.
When the markdown content isn't large enough to show the vertical scroll it still gets focus on TAB from input to button which is poor UX since you can't tell when it has focus because the vertical scroll is not visible. My app is based on the dictionary.py example which I think suffers from the same problem.
I'd like to see an update to the dictionary.py example that demonstrates selective enabling the ability to focus the vertical scroll.
The text was updated successfully, but these errors were encountered: