Skip to content

Commit d42e104

Browse files
author
Frank
committed
added test
1 parent 746ce1b commit d42e104

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
from __future__ import annotations
2+
3+
from textual.app import App, ComposeResult
4+
from textual.widgets import TextArea, Tree, OptionList, Static
5+
from textual.containers import VerticalScroll
6+
7+
8+
class _ScrollbarDemo(App[None]):
9+
"""Minimal app to exercise vertical scrollbar alignment.
10+
11+
The widgets chosen mirror the original report (TextArea, Tree, OptionList, VerticalScroll)
12+
and are intentionally given enough content to show a vertical scrollbar.
13+
"""
14+
15+
CSS = """
16+
Screen > * {
17+
width: 1fr;
18+
height: 1fr;
19+
border: none;
20+
background: $surface;
21+
}
22+
"""
23+
24+
def compose(self) -> ComposeResult:
25+
yield TextArea(id="ta")
26+
yield Tree("", id="tree")
27+
yield OptionList(id="ol")
28+
yield VerticalScroll(id="vs")
29+
30+
def on_mount(self) -> None:
31+
# TextArea content
32+
self.query_one(TextArea).load_text("\n".join(f"Line {n}" for n in range(200)))
33+
34+
# Tree content
35+
tree = self.query_one(Tree)
36+
tree.root.expand()
37+
for n in range(200):
38+
tree.root.add(f"Node {n}")
39+
40+
# OptionList content
41+
self.query_one(OptionList).add_options(f"Option {n}" for n in range(200))
42+
43+
# VerticalScroll content
44+
self.query_one("#vs").mount_all(*(Static(f"Item {n}") for n in range(200)))
45+
46+
47+
async def test_textarea_scrollbar_aligns_with_peers():
48+
"""TextArea's vertical scrollbar should align with Tree, OptionList, and VerticalScroll.
49+
50+
We check the right-most edge of each widget's region; if they match, the scrollbars
51+
are visually aligned to the same gutter.
52+
"""
53+
app = _ScrollbarDemo()
54+
async with app.run_test() as pilot:
55+
# Let layout settle
56+
await pilot.pause(0.05)
57+
58+
ta = app.query_one("#ta")
59+
tree = app.query_one("#tree")
60+
ol = app.query_one("#ol")
61+
vs = app.query_one("#vs")
62+
63+
# Sanity: all should be showing vertical scrollbars given the content size
64+
assert ta.show_vertical_scrollbar, "TextArea should show vertical scrollbar"
65+
assert tree.show_vertical_scrollbar, "Tree should show vertical scrollbar"
66+
assert ol.show_vertical_scrollbar, "OptionList should show vertical scrollbar"
67+
assert vs.show_vertical_scrollbar, "VerticalScroll should show vertical scrollbar"
68+
69+
right_edges = [w.region.right for w in (ta, tree, ol, vs)]
70+
assert len(set(right_edges)) == 1, (
71+
"Expected aligned scrollbars: right edges differ "
72+
f"{right_edges}"
73+
)

0 commit comments

Comments
 (0)