From 7e5cd32f99573d4d3818c4241c1e8d9692109753 Mon Sep 17 00:00:00 2001 From: krutoo Date: Thu, 19 Mar 2026 20:25:39 +0500 Subject: [PATCH] fix(react): useDragAndDrop pointer release event handle fix Now pressed checked instead grabbed because grabbed can be false because of preventDefault() --- README.md | 28 ++++++++++++++++++++-------- src/react/drag-and-drop/observer.ts | 2 +- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 38f0496..29331c5 100644 --- a/README.md +++ b/README.md @@ -91,27 +91,39 @@ const mock = new ResizeObserverMock(); ## Development -### How to write unit-tests? +Repo description and how to work with + +### File structure + +- `src` folder contains files that will be compiled +- `public` folder contains files that will be added to package as is + +### Writing unit-tests Test for module `{path}/{module}.ts` should be placed in `{path}/__test__/{module}.test.ts`. By default test environment is just Node.js environment. -For write tests with simulating browser environment you need to name test file like `a.web.test.ts`. +For write tests with simulating browser environment you need to name test file like `*.web.test.ts`. -### Package structure +### Exports convention -- `src` folder contains files that will be compiled -- `public` folder contains files that will be added to package as is +Any exported file from this package should not contain default exports (`export default ...`). +Defaults exports are hard to work with and less compatible between ESM and CJS. -### Exports convention +### Environment setup + +First you need to use suitable Node.js version, for example by `nvm`: -Any exported file from this package should not contain default exports (`export default ...`). Defaults exports are hard to work with and less compatible between ESM and CJS. +```shell +nvm use && npm install +``` ### VSCode setup +This command will create/update `.vscode/settings.json` + ```shell -# Will update .vscode/settings.json npm run setup -- --vscode ``` diff --git a/src/react/drag-and-drop/observer.ts b/src/react/drag-and-drop/observer.ts index e78958d..4420ecc 100644 --- a/src/react/drag-and-drop/observer.ts +++ b/src/react/drag-and-drop/observer.ts @@ -129,7 +129,7 @@ export class DragAndDropObserver { * @param ctx Context. */ protected handlePointerRelease(event: PointerEvent, ctx: DragAndDropObserverContext): void { - if (!this.state.grabbed || this.state.pointerId !== event.pointerId) { + if (!this.state.pressed || this.state.pointerId !== event.pointerId) { return; }