Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(eventing): remove unnecessary tag name check #16

Merged
merged 2 commits into from
Feb 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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