Skip to content

fix(useDropArea): preserve over state across child transitions - #2741

Open
wanxiankai wants to merge 1 commit into
streamich:masterfrom
wanxiankai:fix/2368-drop-area-child-transitions
Open

wanxiankai wants to merge 1 commit into
streamich:masterfrom
wanxiankai:fix/2368-drop-area-child-transitions

Conversation

@wanxiankai

Copy link
Copy Markdown

Description

Dragging into a child of a useDropArea element produces a bubbling dragenter followed by a dragleave for the previous element. The current leave handler immediately sets over to false, even though the drag remains inside the drop area.

Track balanced drag entries in a ref and clear over only when the last entry leaves. Keeping the count outside the memoized handlers preserves it when callbacks change during a drag. Reset the count on drop and clamp it at zero so a subsequent drag starts cleanly even if an extra dragleave follows the drop.

Fixes #2368.

Add a nested-child Storybook example and document the expected hover state.

Validation

  • Add 15 tests covering parent/child and sibling transitions, missing relatedTarget, nested drop areas, callback changes, repeated drags after a drop, and existing URI/file/text/paste handling.
  • Six of the initial eight tests fail on the original implementation and pass with the fix.
  • yarn test: 77 suites / 507 tests pass.
  • Targeted coverage: 100% statements, branches, functions, and lines for src/useDropArea.ts.
  • yarn lint:types and yarn build (CommonJS and ES modules): pass.
  • yarn lint: 0 errors, 97 existing warnings. The hook's existing useMemo dependency warning also occurs on the unmodified source.
  • Changed-file Prettier check with the repository's formatting options and git diff --check: pass.
  • Native mouse-driven drag validation in Chromium: the original hook changes over from true to false when entering a descendant; the fix keeps it true across descendants and siblings, sets it false on exit, and handles re-entry and a URI drop correctly. The recorded browser drag events are trusted.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as before)

Checklist

  • Read the Contributing Guide
  • Perform a code self-review
  • Comment the code, particularly in hard-to-understand areas — the entry count and reset are straightforward; the behavior is explained above.
  • Add documentation
  • Add hook's story at Storybook
  • Cover changes with tests
  • Ensure the test suite passes (yarn test)
  • Provide 100% tests coverage — all four metrics for the affected hook.
  • Make sure code lints (yarn lint). Fix it with yarn lint:fix in case of failure.
  • Make sure types are fine (yarn lint:types).

Prepared with AI assistance.

This branch has not been deployed

No deployments
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.

useDropArea with child elements

1 participant