From e61f46f52266f016c117e4026390f88436434a42 Mon Sep 17 00:00:00 2001 From: Dobrin Dimchev Date: Thu, 9 Sep 2021 17:11:10 +0300 Subject: [PATCH] fix(ui5-avatar, ui5-icon): attach onclick handler based on interactive property (#3742) --- packages/main/src/Avatar.js | 14 ++++++++------ packages/main/src/Icon.js | 12 ++++++------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/packages/main/src/Avatar.js b/packages/main/src/Avatar.js index f765ff65c849..f81266d00867 100644 --- a/packages/main/src/Avatar.js +++ b/packages/main/src/Avatar.js @@ -322,12 +322,14 @@ class Avatar extends UI5Element { }; } - _onclick(event) { - if (this.interactive) { - // prevent the native event and fire custom event to ensure the noConfict "ui5-click" is fired - event.stopPropagation(); - this.fireEvent("click"); - } + onBeforeRendering() { + this._onclick = this.interactive ? this._onClickHandler.bind(this) : undefined; + } + + _onClickHandler(event) { + // prevent the native event and fire custom event to ensure the noConfict "ui5-click" is fired + event.stopPropagation(); + this.fireEvent("click"); } _onkeydown(event) { diff --git a/packages/main/src/Icon.js b/packages/main/src/Icon.js index 3a56fc403e5b..125008618195 100644 --- a/packages/main/src/Icon.js +++ b/packages/main/src/Icon.js @@ -237,12 +237,10 @@ class Icon extends UI5Element { } } - _onclick(event) { - if (this.interactive) { - // prevent the native event and fire custom event to ensure the noConfict "ui5-click" is fired - event.stopPropagation(); - this.fireEvent("click"); - } + _onClickHandler(event) { + // prevent the native event and fire custom event to ensure the noConfict "ui5-click" is fired + event.stopPropagation(); + this.fireEvent("click"); } get _dir() { @@ -329,6 +327,8 @@ class Icon extends UI5Element { this.ltr = iconData.ltr; this.packageName = iconData.packageName; + this._onclick = this.interactive ? this._onClickHandler.bind(this) : undefined; + if (this.accessibleName) { this.effectiveAccessibleName = this.accessibleName; } else if (this.accData) {