[WC-3410]: Color Picker: re-dispatch mouseup in capture phase to prevent stuck drag in popups#2251
[WC-3410]: Color Picker: re-dispatch mouseup in capture phase to prevent stuck drag in popups#2251rahmanunver wants to merge 5 commits into
Conversation
…uck drag in popups
…nings in test output
…uck drag in popups
…nings in test output
8fbd680 to
70a4fce
Compare
AI Code Review
What was reviewed
Skipped (out of scope): Findings
|
…dix/web-widgets into fix/color-picker-stuck-drag-in-popup
AI Code Review
What was reviewed
Skipped (out of scope): Findings
|
| const releaseDrag = (): void => { | ||
| window.dispatchEvent(new MouseEvent("mouseup")); | ||
| }; | ||
| document.addEventListener("mouseup", releaseDrag, true); |
There was a problem hiding this comment.
The code here implies that we going to dispatch mouseup up until event is removed.
Pull request type
Description
Problem: When the Color Picker widget is placed inside a Mendix popup page, a single click on any drag surface (saturation gradient, hue slider, alpha slider) locks the picker into drag mode — color keeps changing on mouse move without the button held.
Root cause: `react-color@2.19.3` attaches its drag cleanup listener (`unbindEventListeners`) to `window` in the bubble phase. A Mendix dialog calls `stopPropagation()` on `mouseup` before it bubbles up to `window`, so react-color never receives the release event and the `mousemove` listener stays alive indefinitely.
Fix: Add a `useEffect` in `components/ColorPicker.tsx` that listens for `mouseup` on `document` in the capture phase (fires top-down, before any descendant can stop propagation) and re-dispatches it on `window`. This ensures react-color's cleanup always runs regardless of dialog interference. The listener is only attached while the picker is visible (`hidden === false`) and removed on hide/unmount.
Also adds a `jest.config.js` + `jest.setup.ts` to suppress pre-existing `defaultProps` deprecation warnings emitted by `react-color` itself (React 18.3 warnings, unrelated to this fix).
What should be covered while testing?