Skip to content

Commit 3e39a70

Browse files
authored
fix(eventing): remove unnecessary tag name check (#16)
1 parent 8f2ec94 commit 3e39a70

File tree

2 files changed

+7
-21
lines changed

2 files changed

+7
-21
lines changed

packages/base/src/sap/ui/webcomponents/base/DOMEventHandler.js

+7-16
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import PseudoEvents from '@ui5/webcomponents-core/dist/sap/ui/events/PseudoEvents';
22
import ControlEvents from './events/ControlEvents';
3+
import WebComponent from './WebComponent';
34

45
const handleEvent = function (event) {
56

@@ -32,32 +33,24 @@ const getDomTarget = function(event) {
3233
};
3334

3435
const processDOMNode = function(node, event) {
35-
const id = node.getAttribute("data-sap-ui");
36-
const tag = node.tagName;
37-
let control;
38-
39-
if (tag.match(/^ui5-/i)) {
40-
control = node;
41-
}
42-
43-
if (control && control._handleEvent) {
44-
return dispatchEvent(control, event);
36+
if (node && node instanceof WebComponent) {
37+
return dispatchEvent(node, event);
4538
}
4639
return true;
4740
};
4841

49-
const dispatchEvent = function(control, event) {
42+
const dispatchEvent = function(ui5WebComponent, event) {
5043

5144
// Handle the original event (such as "keydown")
52-
control._handleEvent(event);
45+
ui5WebComponent._handleEvent(event);
5346
if (event.isImmediatePropagationStopped()) {
5447
return false;
5548
}
5649

5750
// Handle pseudo events that derive from the original event (such as "sapselect")
5851
const pseudoTypes = getPseudoTypesFor(event);
5952
for (let i = 0, len = pseudoTypes.length; i < len; i++) {
60-
control._handleEvent(event, pseudoTypes[i]);
53+
ui5WebComponent._handleEvent(event, pseudoTypes[i]);
6154
if (event.isImmediatePropagationStopped()) {
6255
return false;
6356
}
@@ -104,8 +97,6 @@ const getPseudoTypesFor = function(event) {
10497
const getParentDOMNode = function(node) {
10598
const parentNode = node.parentNode;
10699

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

131122

132-
export default DOMEventHandler;
123+
export default DOMEventHandler;

packages/base/src/sap/ui/webcomponents/base/WebComponent.js

-5
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,6 @@ class WebComponent extends HTMLElement {
6565
ShadowDOM.updateStyle(tag, this.shadowRoot, styleURLs);
6666
}
6767

68-
// For duck typing when instanceof WebComponent cannot be used
69-
isUI5WebComponent() {
70-
return true;
71-
}
72-
7368
_whenShadowRootReady() {
7469
return this._shadowRootReadyPromise;
7570
}

0 commit comments

Comments
 (0)