Skip to content

Clamp anchored scroll offset for short content#6654

Open
vamsikrishnap23 wants to merge 1 commit into
Textualize:mainfrom
vamsikrishnap23:fix-anchor-short-content-scroll
Open

Clamp anchored scroll offset for short content#6654
vamsikrishnap23 wants to merge 1 commit into
Textualize:mainfrom
vamsikrishnap23:fix-anchor-short-content-scroll

Conversation

@vamsikrishnap23

@vamsikrishnap23 vamsikrishnap23 commented Jul 19, 2026

Copy link
Copy Markdown

Fixes #6652.

When an anchored VerticalScroll contains less content than the viewport,
the compositor computes the anchored scroll position as:

new_scroll_y = content_bottom - viewport_height

If the content is shorter than the viewport, this value becomes negative.
Because it is assigned directly using set_reactive, it bypasses the normal
scroll validation, allowing scroll_y to become negative. This causes the
anchored content to render with empty space above it instead of remaining
aligned to the top of the viewport.

This change clamps the computed anchored scroll offset to 0 before it is
applied, preventing invalid negative scroll positions while preserving the
existing anchoring behavior for content that exceeds the viewport height.

Changes

Test plan

  • Verified the new regression test fails on main without the fix:
FAILED tests/test_containers.py::test_anchored_vertical_scroll_short_content_stays_clamped

E       AssertionError: assert -21 == 0
  • Verified the regression test passes after applying the fix.
  • Ran the complete tests/test_containers.py suite:
6 passed
  • Ran the full test suite:
3459 passed, 3 skipped, 4 xfailed, 1 xpassed
448 snapshot tests passed
  • Verified formatting with:
python -m black --check src/textual/_compositor.py tests/test_containers.py

Checklist

  • Updated CHANGELOG.md
  • Added a regression test
  • Verified the test fails before the fix and passes after it
  • Ran the full test suite successfully
  • Verified formatting with black --check

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Anchored scroll container paints a sticking negative scroll offset when content is shorter than the viewport

1 participant