Skip to content

Commit

Permalink
fix(eventing): remove unnecessary tag name check (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
vladitasev authored Feb 12, 2019
1 parent 8f2ec94 commit 3e39a70
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 21 deletions.
23 changes: 7 additions & 16 deletions packages/base/src/sap/ui/webcomponents/base/DOMEventHandler.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import PseudoEvents from '@ui5/webcomponents-core/dist/sap/ui/events/PseudoEvents';
import ControlEvents from './events/ControlEvents';
import WebComponent from './WebComponent';

const handleEvent = function (event) {

Expand Down Expand Up @@ -32,32 +33,24 @@ const getDomTarget = function(event) {
};

const processDOMNode = function(node, event) {
const id = node.getAttribute("data-sap-ui");
const tag = node.tagName;
let control;

if (tag.match(/^ui5-/i)) {
control = node;
}

if (control && control._handleEvent) {
return dispatchEvent(control, event);
if (node && node instanceof WebComponent) {
return dispatchEvent(node, event);
}
return true;
};

const dispatchEvent = function(control, event) {
const dispatchEvent = function(ui5WebComponent, event) {

// Handle the original event (such as "keydown")
control._handleEvent(event);
ui5WebComponent._handleEvent(event);
if (event.isImmediatePropagationStopped()) {
return false;
}

// Handle pseudo events that derive from the original event (such as "sapselect")
const pseudoTypes = getPseudoTypesFor(event);
for (let i = 0, len = pseudoTypes.length; i < len; i++) {
control._handleEvent(event, pseudoTypes[i]);
ui5WebComponent._handleEvent(event, pseudoTypes[i]);
if (event.isImmediatePropagationStopped()) {
return false;
}
Expand Down Expand Up @@ -104,8 +97,6 @@ const getPseudoTypesFor = function(event) {
const getParentDOMNode = function(node) {
const parentNode = node.parentNode;

// Skip the custom element tag (host) only if crossing a shadow DOM boundary
// The reason is that the event was already dispatched to the light control while traversing the shadow DOM
if (parentNode && parentNode.host) {
return parentNode.host;
}
Expand All @@ -129,4 +120,4 @@ class DOMEventHandler {
}


export default DOMEventHandler;
export default DOMEventHandler;
5 changes: 0 additions & 5 deletions packages/base/src/sap/ui/webcomponents/base/WebComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,6 @@ class WebComponent extends HTMLElement {
ShadowDOM.updateStyle(tag, this.shadowRoot, styleURLs);
}

// For duck typing when instanceof WebComponent cannot be used
isUI5WebComponent() {
return true;
}

_whenShadowRootReady() {
return this._shadowRootReadyPromise;
}
Expand Down

0 comments on commit 3e39a70

Please sign in to comment.