aurelia / binding

A modern databinding library for JavaScript and HTML.
MIT License
111 stars 96 forks source link

Delegate event bubbling does not match native behavior in shadow dom #755

Closed michaelw85 closed 5 years ago

michaelw85 commented 5 years ago

I'm submitting a bug report

Please tell us about your environment:

Current behavior: When using a click delegate on a custom element with shadow dom the callback is not fired.

<custom-comp click.delegate="expectToTrigger()"></...>

Expected/desired behavior: According to this documentation and by testing in chrome click events should be able to cross the shadow dom boundary.

Possible root cause: event-manager:70

function handleDelegatedEvent(event) {
  event.propagationStopped = false;
  let target = findOriginalEventTarget(event);

  while (target && !event.propagationStopped) {
    if (target.delegatedCallbacks) {
      let callback = target.delegatedCallbacks[event.type];
      if (callback) {
        if (event.stopPropagation !== stopPropagation) {
          event.standardStopPropagation = event.stopPropagation;
          event.stopPropagation = stopPropagation;
        }
        if ('handleEvent' in callback) {
          callback.handleEvent(event);
        } else {
          callback(event);
        }
      }
    }

    // 🔽🔽🔽 this will receive null when the shadow root is reached and will break the loop
    target = target.parentNode;
  }
}