diff --git a/packages/main/src/Icon.js b/packages/main/src/Icon.js index 96bed613c6ca..24c1b18c347a 100644 --- a/packages/main/src/Icon.js +++ b/packages/main/src/Icon.js @@ -198,9 +198,17 @@ class Icon extends UI5Element { } _onkeydown(event) { - if (this.interactive && isEnter(event)) { + if (!this.interactive) { + return; + } + + if (isEnter(event)) { this.fireEvent("click"); } + + if (isSpace(event)) { + event.preventDefault(); // prevent scrolling + } } _onkeyup(event) { @@ -211,8 +219,8 @@ class Icon extends UI5Element { _onclick(event) { if (this.interactive) { - event.preventDefault(); - // Prevent the native event and fire custom event because otherwise the noConfict event won't be thrown + // prevent the native event and fire custom event to ensure the noConfict "ui5-click" is fired + event.stopPropagation(); this.fireEvent("click"); } } diff --git a/packages/main/test/pages/Icon.html b/packages/main/test/pages/Icon.html index 6f9ef42b1651..117f8334f2c1 100644 --- a/packages/main/test/pages/Icon.html +++ b/packages/main/test/pages/Icon.html @@ -37,6 +37,16 @@ +

Interactive Icon

+ + +
+ +

@@ -89,7 +99,9 @@ var icon = document.getElementById("interactive-icon"), nonInteractiveIcon = document.getElementById("non-interactive-icon"), input = document.getElementById("click-event"), + input2 = document.getElementById("click-event-2"), inputValue = 0; + inputValue2 = 0; icon.addEventListener("ui5-click", function() { input.value = ++inputValue; @@ -98,6 +110,10 @@ nonInteractiveIcon.addEventListener("ui5-click", function() { input.value = ++inputValue; }); + + myInteractiveIcon.addEventListener("click", function() { + input2.value = ++inputValue2; + });