This commit is contained in:
Will McGugan
2025-10-05 11:57:18 +01:00
parent 1e4ab382ea
commit 88220b8f02
5 changed files with 99 additions and 1 deletions

View File

@@ -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()

View File

@@ -0,0 +1,11 @@
VerticalScroll {
width: 1fr;
}
.left {
scrollbar-visibility: visible; # The default
}
.right {
scrollbar-visibility: hidden;
}

View File

@@ -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";
```

View File

@@ -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"

View File

@@ -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