[pointerevents] Moving an element to a different place in the DOM tree loses pointer lock and pointer capture (#439)

guillaumebrunerie has just created a new issue for https://github.com/w3c/pointerevents:

== Moving an element to a different place in the DOM tree loses pointer lock and pointer capture ==
If an element currently has pointer lock or pointer capture active and we move it at a different place in the DOM tree (for instance using `Node.insertBefore`), then it loses pointer lock/capture. I believe it should not lose it.

The specification says:
> When the [pointer capture target override](https://w3c.github.io/pointerevents/#dfn-pointer-capture-target-override) is no longer [connected](https://dom.spec.whatwg.org/#connected) [[DOM](https://w3c.github.io/pointerevents/#bib-dom)], the [pending pointer capture target override](https://w3c.github.io/pointerevents/#dfn-pending-pointer-capture-target-override) and [pointer capture target override](https://w3c.github.io/pointerevents/#dfn-pointer-capture-target-override) nodes SHOULD be cleared and also a PointerEvent named lostpointercapture corresponding to the captured pointer SHOULD be fired at the document.

but I guess it isn’t entirely clear on whether `Node.insertBefore` causes the node to no longer be connected (?)

Here is an example: https://codepen.io/Latcarf/pen/NWXjYNb.
Try to drag the "Drag me" box, you’ll notice that it works fine when dragging to the right but pointer lock is lost as soon as we drag one step to the left. The same happens with pointer capture. The difference between right and left is that the element itself is moved when dragging to the left, but the element to its right is moved when dragging to the right.

I’m not sure if it is a bug in the specification or in web browsers (or if I misunderstood something), but I tested it in Chrome, Safari and Firefox on Mac OS X Catalina, and all three exhibit the same behavior.

Please view or discuss this issue at https://github.com/w3c/pointerevents/issues/439 using your GitHub account

Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Monday, 28 March 2022 13:03:29 UTC