Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only consider document scrollable if not prevented #1081

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

leo
Copy link

@leo leo commented Mar 24, 2023

At the moment, the <html> element will always be added to the list of scrollable ancestors, even if the element has its scrolling ability deactivated using overflow: hidden.

As a result, sensors like KeyboardSensor will mistakenly scroll <html> when dragging elements, causing unwanted glitches in the visual experience.

@changeset-bot
Copy link

changeset-bot bot commented Mar 24, 2023

🦋 Changeset detected

Latest commit: 62b5ded

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@dnd-kit/core Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

export function isScrollable(
element: HTMLElement,
export function hasOverflowStyles(
element: Element,
Copy link
Author

@leo leo Mar 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HTMLElement is a subset of Element, so Element should be fine to use here (it won't break the public API).

Broadening the type was needed to accept node.scrollableElement in getScrollableAncestors.ts, which is of type Element and not HTMLElement. However they both are processed by hasOverflowStyles just fine, because getComputedStyle accepts both.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: it's a breaking change if somebody uses this function's type in contra-variant position like const fn: (hasOverflowStyles: typeof hasOverflowStyles) => void and then fn(myCustomHasOverflowStyles) but it's a stretch.


import {hasOverflowStyles} from './hasOverflowStyles';

export function isScrollingDisabled(
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created this dedicated function because using a single isScrollable function containing both checks doesn't work for the following reasons:

  • isScrollingEnabled needs to check if scrolling was explicitly enabled.
  • isScrollingDisabled needs to check if scrolling was explicitly disabled.

Combining both into Boolean(isScrollingEnabled && !isScrollingDisabled) (in a single isScrollable function) would imply the element won't be considered scrollable unless it explicitly had scrolling enabled, which is not something that is wanted when checking node.scrollableElement in getScrollableAncestors.ts because that element should always be considered scrollable, unless scrolling is explicitly disabled.

@leo leo marked this pull request as ready for review March 24, 2023 14:30
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.

2 participants