Skip to content
Discussion options

You must be logged in to vote

Widget.show_horizontal_scrollbar and Widget.show_vertical_scrollbar are reactives that can be watched. I'd probably do something with that:

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 {

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@mzebrak
Comment options

@davep
Comment options

@mzebrak
Comment options

Answer selected by mzebrak
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants