Repository navigation
Conversation
…tainers The auto-scroll boundary introduced in #5228 used getFirstScrollableParent, which only matches ancestors whose content currently overflows. A short sortable list inside an overflow-y: auto container therefore fell through to the page scroller, and dragging scrolled the page behind the container. Use the nearest ancestor with a scrolling overflow-y (auto, scroll, overlay) as the boundary, whether or not it overflows. getFirstScrollableParent and its other callers are unchanged.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5301 +/- ##
==========================================
- Coverage 97.87% 97.87% -0.01%
==========================================
Files 1016 1016
Lines 32887 32912 +25
Branches 12199 12208 +9
==========================================
+ Hits 32187 32211 +24
- Misses 660 695 +35
+ Partials 40 6 -34 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
🟡 Changes recommended
The new boundary lookup can mistake viewport-propagated body overflow for an independent scroller, disabling pointer-drag page auto-scroll in standards mode.
1 open issue
What changed in this PR
This follow-up to #5228 keeps sortable-list pointer auto-scroll within the nearest vertical scroll container, even when its content does not overflow.
Changes:
- Adds an overflow-independent container lookup and uses it in
SortableArea, leavinggetFirstScrollableParentunchanged. - Adds regression tests for non-overflowing containers, horizontal-only ancestors, and unrestricted page scrolling.
- Expands the demo with additional layouts and URL-configurable item counts.
| File | Description |
|---|---|
src/list/__tests__/list-sortable.test.tsx |
Tests auto-scroll boundary selection and reset behavior. |
src/internal/utils/scrollable-containers.ts |
Adds getNearestScrollContainer. |
src/internal/utils/__tests__/scrollable-containers.test.tsx |
Tests container lookup across overflow configurations. |
src/internal/components/sortable-area/index.tsx |
Uses the new lookup for auto-scroll boundaries. |
pages/list/sortable-sticky-drawer-autoscroll.page.tsx |
Adds nested and fixed-height layouts plus item-count controls. |
Review effort: Balanced
…iewport
With html overflow visible and body { overflow-y: auto }, the body's overflow
applies to the viewport, so the body does not scroll itself. The sortable
auto-scroll boundary picked the body and rejected the document scroller,
disabling pointer-drag page auto-scroll. Map such a body to
document.scrollingElement; keep a body that is an independent scroller.
There was a problem hiding this comment.
🟡 Changes recommended
The scroll-container logic ignores CSS containment on html or body, potentially selecting the document scroller and auto-scrolling the outer page during pointer drags instead of the independently scrolling body.
1 open issue
1 resolved since last review
Review effort: Balanced
| const rootStyle = getComputedStyle(root); | ||
| return rootStyle.overflowX === 'visible' && rootStyle.overflowY === 'visible'; |
| * When that ancestor is a `body` whose overflow is propagated to the viewport, the document's scrolling element | ||
| * is returned instead. Returns `undefined` when no such ancestor exists. | ||
| */ | ||
| export function getNearestScrollContainer(element: HTMLElement): HTMLElement | undefined { |
There was a problem hiding this comment.
getNearestScrollableContainer does conceptually the same as getFirstScrollableParent, only with a small behavior change that their names tell nothing about.
If instead we apply the change to getFirstScrollableParent (which is used by popovers and prompt input), would it break them? Or by the contrary, would it potentially improve those consumers as well?
If you determine that it really would break them, could we reuse the same function with a flag instead of having two?

Description
Follow-up to #5228.
Problem: #5228 limited dnd-kit auto-scroll to the sortable list's nearest scroll container. That fix still breaks when the container has
overflow-y: autobut its content does not overflow yet, for example a short list of 4 items in a fixed-height panel or a sticky drawer. A pointer drag near the container's top or bottom edge then scrolls the page behind it.Root cause: the boundary came from
getFirstScrollableParent, which only matches an ancestor whose content currently overflows (scrollHeight > clientHeight). A non-overflowingoverflow-y: autocontainer is skipped. The boundary then becomes an outer scroller (the page or drawer scroller), and dnd-kit auto-scrolls that instead.Fix:
getNearestScrollContainer(element)ininternal/utils/scrollable-containers. It returns the nearest ancestor (excluding the element itself) whose computedoverflow-yisauto,scrolloroverlay, whether or not it currently overflows.SortableArea'suseScopedAutoScrollnow uses it as the boundary. A non-overflowing container has nothing to scroll, so a drag scrolls nothing.getFirstScrollableParentand its other callers (popover positioning, prompt-input token mode) are unchanged.overflow-y: hiddenorvisible) are not treated as a boundary.bodyand the root element's overflow isvisiblein both axes, the body's overflow propagates to the viewport (CSS Overflow 3, standards and quirks mode alike). The body then doesn't scroll itself, so the boundary becomesdocument.scrollingElement(falling back tohtmlin standards mode,bodyin quirks mode). Without this,canScrollrejected the document scroller and pointer-drag page auto-scroll stopped.visible) stays the boundary.dnd-kit context: clauderic/dnd-kit#1893
How has this been tested?
Real-browser pointer drags on the dev page
list/sortable-sticky-drawer-autoscroll, extended withlayoutanditemCountURL params. I used Playwright 1.65 (Chromium and WebKit,mcr.microsoft.com/playwright:v1.65.0-noble) against the dev server. Each run:Values are the
scrollTopchange (px) of every scrollable ancestor during the hold;{}means nothing scrolled.overflow-y: autocontainer in a scrolling page, 4 itemsoverflow-x-only container (no vertical scroll container)htmloverflow visible,body { overflow-y: auto }, 30 items, no other scroller (viewport edges)html) +1466 / −1466html { overflow: hidden },bodyan independent 100%-height scroller, 30 itemsbody+1466 / −1466All rows were re-measured on the final head in both engines and match the first revision. The page-flow rows shift a little because of the merge from
main(page-30 window +346 / −346,overflow-x-only top −847, WebKit no-scroller top −1338), and they are identical before and after the second commit. The twobodyrows were also measured before #5228 and with #5228 only: both scroll the same as after this PR.Unit tests:
getNearestScrollContainertests inscrollable-containers.test.tsx:auto,scrollandoverlay;getFirstScrollableParentreturns the outer one;overflow-x-only orclipancestors;undefinedwhen nothing matches.getNearestScrollContainerbody tests:document.scrollingElement, with fallbacks tohtml(standards) andbody(quirks);hidden,auto,clip, or non-visible in one axis;list-sortable.test.tsxauto-scroll tests:overflow-x-only ancestors are ignored;scrollable-containers,list,sortable-areaandcollection-preferences(the otherSortableAreaconsumer): 18 suites, 221 tests, all passing.tsc -p tsconfig.jsonpasses.Review checklist
getFirstScrollableParent.