Skip to content

Commit

Permalink
Fix auto-scroller bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
clauderic committed Jun 7, 2024
1 parent f09f1eb commit 9fc6f96
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
1 change: 1 addition & 0 deletions .changeset/bug-fixes.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@

- `draggable`: Fixed a bug where the `element` was not properly being set on initialization
- `feedback`: Fixed a bug with optimistic re-ordering.
- `scroller`: Fixed a bug with auto-scrolling when target is position fixed
6 changes: 5 additions & 1 deletion packages/dom/src/core/plugins/scrolling/Scroller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import type {DragDropManager} from '../../manager/index.ts';
import {ScrollIntentTracker} from './ScrollIntent.ts';

export class Scroller extends CorePlugin<DragDropManager> {
public getScrollableElements: () => Element[] | null;
public getScrollableElements: () => Set<Element> | null;

private scrollIntentTracker: ScrollIntentTracker;

Expand Down Expand Up @@ -51,6 +51,8 @@ export class Scroller extends CorePlugin<DragDropManager> {
}
}

console.log(element);

return element
? getScrollableAncestors(element, {excludeElement: false})
: null;
Expand Down Expand Up @@ -98,6 +100,8 @@ export class Scroller extends CorePlugin<DragDropManager> {

const elements = this.getScrollableElements();

console.log(elements);

if (!elements) {
return false;
}
Expand Down
20 changes: 12 additions & 8 deletions packages/dom/src/utilities/scroll/getScrollableAncestors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ const defaultOptions: Options = {
export function getScrollableAncestors(
element: Node | null,
options: Options = defaultOptions
): Element[] {
): Set<Element> {
const {limit, excludeElement} = options;
const scrollParents: Element[] = [];
const scrollParents = new Set<Element>();

function findScrollableAncestors(node: Node | null): Element[] {
if (limit != null && scrollParents.length >= limit) {
function findScrollableAncestors(node: Node | null): Set<Element> {
if (limit != null && scrollParents.size >= limit) {
return scrollParents;
}

Expand All @@ -33,9 +33,9 @@ export function getScrollableAncestors(
if (
isDocument(node) &&
node.scrollingElement != null &&
!scrollParents.includes(node.scrollingElement)
!scrollParents.has(node.scrollingElement)
) {
scrollParents.push(node.scrollingElement);
scrollParents.add(node.scrollingElement);

return scrollParents;
}
Expand All @@ -48,7 +48,7 @@ export function getScrollableAncestors(
return scrollParents;
}

if (scrollParents.includes(node)) {
if (scrollParents.has(node)) {
return scrollParents;
}

Expand All @@ -58,10 +58,14 @@ export function getScrollableAncestors(
if (excludeElement && node === element) {
// no-op
} else if (isScrollable(node, computedStyle)) {
scrollParents.push(node);
scrollParents.add(node);
}

if (isFixed(node, computedStyle)) {
const {scrollingElement} = node.ownerDocument;

if (scrollingElement) scrollParents.add(scrollingElement);

return scrollParents;
}

Expand Down

0 comments on commit 9fc6f96

Please sign in to comment.