Repository navigation
Conversation
The Feedback plugin positions the dragged element with `position: fixed` and explicit `top`/`left` taken from its border box. Any margin on the element was then applied on top, shifting it away from the pointer by the margin width. The only margin reset lived in the low-priority `dnd-kit` layer and targeted `[popover]` only, so author margins (inline or from a stylesheet) always won. Force `margin: 0 !important` alongside the existing `top`/`left`/`right`/`bottom` overrides instead, and drop the now redundant layered reset. Visual styles stay overridable as before. Fixes clauderic#2092
🦋 Changeset detectedLatest commit: e934aea The changes in this PR will be included in the next version bump. This PR includes changesets to release 10 packages
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 |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2092
Problem
While dragging, the Feedback plugin positions the element with
position: fixedand explicittop/lefttaken from the element's border box. Margins live outside the border box, so any margin on the element was applied a second time and shifted it away from the pointer. Withstyle={{marginLeft: 20}}from the issue's sandbox, the item jumps 20px to the right on drag start.The only margin reset was in the
dnd-kitlayer:That rule is intentionally low-priority, so that framework styles such as Tailwind v4 win (#1896, 7260746). That's right for visual styles like background, border and padding, but it means author margins, whether inline or from any stylesheet, always override it.
Change
margin: 0 !importantto the main[data-dnd-dragging]rule, alongside the existingtop/left/right/bottom!importantpositioning overrides. A margin doesn't style the element. It changes where it sits, and the position is already fully controlled by the plugin.margin: unsetfrom the layered popover reset, since it's now redundant. The remaining layered resets (background,border,padding,color,overflow) are unchanged, so layered framework styles still win as [experimental] option for disabling data-dnd-dragging styles injection #1896 intended.The placeholder keeps its margins, so the surrounding layout doesn't shift. When the drag ends, the element gets its own margins back.
Tests
React/Sortable/Marginswith sortable items offset by margins: odd items inline (marginLeft: 40, marginTop: 10), even items from a stylesheet (margin-left: 60px).apps/stories/tests/sortable-margins.spec.ts. It grabs an item 25% from its top-left, drags it, and asserts the pointer is still 25% into the dragged element, within 3px, for both the inline and the stylesheet margin.main: both fail. The element is offset by exactly the margin (Received: 40andReceived: 60).packages/domunit tests: 88 pass.bun run buildpasses.@dnd-kit/dompatch.