feat(touch-emulator): support Shadow DOM event handling (#13723)

This commit is contained in:
inottn
2025-12-28 17:01:45 +08:00
committed by GitHub
parent 85545bbc68
commit cacfb196a4

View File

@@ -146,7 +146,7 @@
!eventTarget || !eventTarget ||
(eventTarget && !eventTarget.dispatchEvent) (eventTarget && !eventTarget.dispatchEvent)
) { ) {
eventTarget = ev.target; eventTarget = ev.composed ? ev.composedPath()[0] : ev.target;
} }
if (eventTarget.closest('[data-no-touch-simulate]') == null) { if (eventTarget.closest('[data-no-touch-simulate]') == null) {
@@ -166,8 +166,11 @@
* @param mouseEv * @param mouseEv
*/ */
function triggerTouch(eventName, mouseEv) { function triggerTouch(eventName, mouseEv) {
var touchEvent = document.createEvent('Event'); var touchEvent = new Event(eventName, {
touchEvent.initEvent(eventName, true, true); bubbles: true,
cancelable: true,
composed: true,
});
touchEvent.altKey = mouseEv.altKey; touchEvent.altKey = mouseEv.altKey;
touchEvent.ctrlKey = mouseEv.ctrlKey; touchEvent.ctrlKey = mouseEv.ctrlKey;