Skip to content

[experimental] Add SnapToPointer modifier#2028

Merged
clauderic merged 5 commits intoclauderic:experimentalfrom
dooohun:feat/snap-center-to-cursor-modifier
Apr 27, 2026
Merged

[experimental] Add SnapToPointer modifier#2028
clauderic merged 5 commits intoclauderic:experimentalfrom
dooohun:feat/snap-center-to-cursor-modifier

Conversation

@dooohun
Copy link
Copy Markdown

@dooohun dooohun commented Apr 26, 2026

Context

This is a follow-up to #1599, which has been inactive since the requested changes in March.
I've implemented the same feature with the blocking issues addressed - missing changeset and incorrect import path - and rebased on top of the experimental branch.

Summary

  • Adds SnapCenterToCursor modifier to @dnd-kit/dom
  • Fixes a DTS build error in experimental branch

Changes

Fix

  • Add explicit CleanupFunction return types Plugin#registerEffect, KeyboardSensor#bind, and PointerSensor#bind to restore the DTS build

Feature

  • Implement SnapCenterToCursor modifier
  • Export from @dnd-kit/dom/modifiers
  • Add changeset (@dnd-kit/dom: minor)
  • Add Storybook story and docs

Docs

  • Add SnapCenterToCursor to apps/docs/extend/modifiers.mdx

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 26, 2026

🦋 Changeset detected

Latest commit: 247a82b

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

This PR includes changesets to release 10 packages
Name Type
@dnd-kit/dom Patch
@dnd-kit/abstract Patch
@dnd-kit/collision Patch
@dnd-kit/geometry Patch
@dnd-kit/helpers Patch
@dnd-kit/react Patch
@dnd-kit/state Patch
@dnd-kit/vue Patch
@dnd-kit/solid Patch
@dnd-kit/svelte 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

Comment thread .changeset/add-snap-center-to-cursor-modifier.md Outdated
Comment thread apps/docs/extend/modifiers.mdx Outdated
Comment thread packages/dom/src/modifiers/SnapCenterToCursor.ts Outdated
@dooohun dooohun requested a review from clauderic April 26, 2026 15:33
Comment thread packages/dom/src/modifiers/SnapToPointer.ts Outdated
@dooohun dooohun requested a review from clauderic April 27, 2026 13:08
@clauderic clauderic merged commit 3db07bb into clauderic:experimental Apr 27, 2026
@clauderic clauderic changed the title [experimental] Add SnapCenterToCursor modifier [experimental] Add SnapToPointer modifier Apr 27, 2026
@github-actions github-actions Bot mentioned this pull request Apr 27, 2026
@execto
Copy link
Copy Markdown

execto commented Apr 30, 2026

What version of dnd-kit/react i need install to have SnapToPointer modifier? Now i have 0.3.0, but SnapToPointer not exported

package.json of dnd-kit/react

{
  "name": "@dnd-kit/react",
  "version": "0.3.0",
  "main": "./index.cjs",
  "module": "./index.js",
  "type": "module",
  "types": "./index.d.ts",
  "sideEffects": false,
  "license": "MIT",
  "files": [
    "LICENSE",
    "README.md",
    "index.js",
    "index.d.ts",
    "index.cjs",
    "hooks.js",
    "hooks.d.ts",
    "hooks.cjs",
    "sortable.js",
    "sortable.d.ts",
    "sortable.cjs",
    "utilities.js",
    "utilities.d.ts",
    "utilities.cjs"
  ],
  "exports": {
    ".": {
      "types": "./index.d.ts",
      "import": "./index.js",
      "require": "./index.cjs"
    },
    "./hooks": {
      "types": "./hooks.d.ts",
      "import": "./hooks.js",
      "require": "./hooks.cjs"
    },
    "./sortable": {
      "types": "./sortable.d.ts",
      "import": "./sortable.js",
      "require": "./sortable.cjs"
    },
    "./utilities": {
      "types": "./utilities.d.ts",
      "import": "./utilities.js",
      "require": "./utilities.cjs"
    }
  },
  "scripts": {
    "build": "bun build:utilities && bun build:hooks && bun build:core && bun build:sortable",
    "build:core": "tsup src/core/index.ts",
    "build:hooks": "tsup --entry.hooks src/hooks/index.ts",
    "build:sortable": "tsup --entry.sortable src/sortable/index.ts",
    "build:utilities": "tsup --entry.utilities src/utilities/index.ts",
    "dev": "bun build:utilities --watch & bun build:hooks --watch & bun build:core --watch & bun build:sortable --watch",
    "lint": "TIMING=1 eslint src/**/*.ts* --fix",
    "clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist"
  },
  "dependencies": {
    "@dnd-kit/abstract": "^0.3.0",
    "@dnd-kit/dom": "^0.3.0",
    "@dnd-kit/state": "^0.3.0",
    "tslib": "^2.6.2"
  },
  "peerDependencies": {
    "react": "^18.0.0 || ^19.0.0",
    "react-dom": "^18.0.0 || ^19.0.0"
  },
  "devDependencies": {
    "@types/react": "^19.0.8",
    "@types/react-dom": "^19.0.3",
    "eslint": "^8.38.0",
    "@dnd-kit/eslint-config": "*",
    "react": "^19.0.0",
    "tsup": "8.3.0",
    "typescript": "^5.5.2"
  },
  "publishConfig": {
    "access": "public"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/clauderic/dnd-kit"
  }
}

modifiers.d.ts

import * as _dnd_kit_geometry from '@dnd-kit/geometry';
import { BoundingRectangle } from '@dnd-kit/geometry';
import * as _dnd_kit_abstract from '@dnd-kit/abstract';
import { Modifier, DragOperation } from '@dnd-kit/abstract';
import { DragDropManager } from '@dnd-kit/dom';

declare class RestrictToWindow extends Modifier<DragDropManager> {
    constructor(manager: DragDropManager);
    windowBoundingRectangle: BoundingRectangle | undefined;
    apply({ shape, transform }: DragOperation): _dnd_kit_geometry.Coordinates;
}

interface Options {
    element?: Element | null | ((operation: DragDropManager['dragOperation']) => Element | null);
}
declare class RestrictToElement extends Modifier<DragDropManager, Options> {
    private boundingRectangle;
    constructor(manager: DragDropManager, options?: Options);
    apply(operation: DragDropManager['dragOperation']): {
        x: number;
        y: number;
    };
    static configure: (options: Options) => _dnd_kit_abstract.PluginDescriptor<any, any, typeof RestrictToElement>;
}

export { RestrictToElement, RestrictToWindow };

@dooohun
Copy link
Copy Markdown
Author

dooohun commented Apr 30, 2026

This PR is based on the experimental branch, so SnapToPointer will be included when it's officially released. You'll need to wait for the next release.

@clauderic
Copy link
Copy Markdown
Owner

Every commit to the main branch is released to npm under the @beta tag

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.

3 participants