diff --git a/docs/examples/styles/scrollbar_visibility.py b/docs/examples/styles/scrollbar_visibility.py new file mode 100644 index 000000000..3f08a8bf4 --- /dev/null +++ b/docs/examples/styles/scrollbar_visibility.py @@ -0,0 +1,27 @@ +from textual.app import App +from textual.containers import Horizontal, VerticalScroll +from textual.widgets import Label + +TEXT = """I must not fear. +Fear is the mind-killer. +Fear is the little-death that brings total obliteration. +I will face my fear. +I will permit it to pass over me and through me. +And when it has gone past, I will turn the inner eye to see its path. +Where the fear has gone there will be nothing. Only I will remain. +""" + + +class ScrollbarApp(App): + CSS_PATH = "scrollbar_visibility.tcss" + + def compose(self): + yield Horizontal( + VerticalScroll(Label(TEXT * 10), classes="left"), + VerticalScroll(Label(TEXT * 10), classes="right"), + ) + + +if __name__ == "__main__": + app = ScrollbarApp() + app.run() diff --git a/docs/examples/styles/scrollbar_visibility.tcss b/docs/examples/styles/scrollbar_visibility.tcss new file mode 100644 index 000000000..cab96d982 --- /dev/null +++ b/docs/examples/styles/scrollbar_visibility.tcss @@ -0,0 +1,11 @@ +VerticalScroll { + width: 1fr; +} + +.left { + scrollbar-visibility: visible; # The default +} + +.right { + scrollbar-visibility: hidden; +} diff --git a/docs/styles/scrollbar_visibility.md b/docs/styles/scrollbar_visibility.md new file mode 100644 index 000000000..c493597a7 --- /dev/null +++ b/docs/styles/scrollbar_visibility.md @@ -0,0 +1,60 @@ +# Scrollbar-visibility + +The `scrollbar-visibility` is used to show or hide scrollbars. + +If scrollbars are hidden, the user may still scroll the container using the mouse wheel / keys / and gestures, but +there will be no scrollbars shown. + +## Syntax + +--8<-- "docs/snippets/syntax_block_start.md" +scrollbar-visibility: hidden | visible; +--8<-- "docs/snippets/syntax_block_end.md" + + +### Values + +| Value | Description | +| ------------------- | ---------------------------------------------------- | +| `hidden` | The widget's scrollbars will be hidden. | +| `visible` (default) | The widget's scrollbars will be displayed as normal. | + + +## Examples + +The following example contains two containers with the same text. +The container on the right has its scrollbar hidden. + +=== "Output" + + ```{.textual path="docs/examples/styles/scrollbar_visibility.py"} + ``` + +=== "scrollbar_visibility.py" + + ```py + --8<-- "docs/examples/styles/scrollbar_visibility.py" + ``` + +=== "scrollbar_visibility.tcss" + + ```css + --8<-- "docs/examples/styles/scrollbar_visibility.tcss" + ``` + + +## CSS + +```css +scrollbar-visibility: visible; +scrollbar-visibility: hidden; +``` + + + +## Python + +```py +widget.styles.scrollbar_visibility = "visible"; +widget.styles.scrollbar_visibility = "hidden"; +``` diff --git a/mkdocs-nav.yml b/mkdocs-nav.yml index a587d54c8..e6b7b6672 100644 --- a/mkdocs-nav.yml +++ b/mkdocs-nav.yml @@ -136,6 +136,7 @@ nav: - "styles/scrollbar_colors/scrollbar_corner_color.md" - "styles/scrollbar_gutter.md" - "styles/scrollbar_size.md" + - "styles/scrollbar_visibility.md" - "styles/text_align.md" - "styles/text_opacity.md" - "styles/text_overflow.md" diff --git a/src/textual/widget.py b/src/textual/widget.py index cdcd7103e..cf56e9536 100644 --- a/src/textual/widget.py +++ b/src/textual/widget.py @@ -3421,7 +3421,6 @@ class Widget(DOMNode): `True` if any scrolling has occurred in any descendant, otherwise `False`. """ # Grow the region by the margin so to keep the margin in view. - region = widget.virtual_region_with_margin scrolled = False