Skip to content

Commit 031b6ca

Browse files
authored
fix(ui5-busyindicator): prevent keyboard events propagation to controls (#1607)
1 parent c80130d commit 031b6ca

File tree

4 files changed

+98
-1
lines changed

4 files changed

+98
-1
lines changed

packages/main/src/BusyIndicator.hbs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<div class="ui5-busyindicator-root">
22
<div class="ui5-busyindicator-wrapper">
33
{{#if active}}
4-
<div class="ui5-busyindicator-dynamic-content" tabindex="0" role="progressbar" aria-valuemin="0" aria-valuemax="100" title="{{ariaTitle}}">
4+
<div class="ui5-busyindicator-dynamic-content" role="progressbar" aria-valuemin="0" aria-valuemax="100" title="{{ariaTitle}}">
55
<div class="ui5-busyindicator-circle circle-animation-0"></div>
66
<div class="ui5-busyindicator-circle circle-animation-1"></div>
77
<div class="ui5-busyindicator-circle circle-animation-2"></div>

packages/main/src/BusyIndicator.js

+30
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,30 @@ class BusyIndicator extends UI5Element {
9595
super();
9696

9797
this.i18nBundle = getI18nBundle("@ui5/webcomponents");
98+
this._preventHandler = this._preventEvent.bind(this);
99+
}
100+
101+
onBeforeRendering() {
102+
if (this.active) {
103+
this.tabIndex = -1;
104+
} else {
105+
this.tabIndex = 0;
106+
}
107+
}
108+
109+
onEnterDOM() {
110+
this.addEventListener("keyup", this._preventHandler, {
111+
capture: true,
112+
});
113+
114+
this.addEventListener("keydown", this._preventHandler, {
115+
capture: true,
116+
});
117+
}
118+
119+
onExitDOM() {
120+
this.removeEventListener("keyup", this._preventHandler, true);
121+
this.removeEventListener("keydown", this._preventHandler, true);
98122
}
99123

100124
static get metadata() {
@@ -123,6 +147,12 @@ class BusyIndicator extends UI5Element {
123147
get ariaTitle() {
124148
return this.i18nBundle.getText(BUSY_INDICATOR_TITLE);
125149
}
150+
151+
_preventEvent(event) {
152+
if (this.active) {
153+
event.stopImmediatePropagation();
154+
}
155+
}
126156
}
127157

128158
BusyIndicator.define();

packages/main/test/pages/BusyIndicator.html

+49
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,24 @@
112112
<br>
113113
<br>
114114

115+
<ui5-busyindicator id="busy-tree" style="width: 100%;">
116+
<ui5-tree id="treeDynamic">
117+
<div slot="header">
118+
<ui5-title>Dynamic tree</ui5-title>
119+
</div>
120+
121+
<ui5-tree-item text="Has preloaded children">
122+
<ui5-tree-item text="Child 1"></ui5-tree-item>
123+
<ui5-tree-item text="Child 2"></ui5-tree-item>
124+
</ui5-tree-item>
125+
126+
<ui5-tree-item text="Has no children at all"></ui5-tree-item>
127+
128+
<ui5-tree-item id="dynamicNode" text="Has children, but not yet loaded" has-children></ui5-tree-item>
129+
</ui5-tree>
130+
</ui5-busyindicator>
131+
132+
<ui5-input value="0" id="tree-input"></ui5-input>
115133

116134
<script>
117135
var busyIndocator = document.getElementById("busy-container");
@@ -132,6 +150,37 @@
132150
busyIndocator.removeAttribute("active");
133151
}, 2000);
134152
});
153+
154+
var dynamicTree = document.getElementById("treeDynamic");
155+
var busyIndicator = document.getElementById("busy-tree");
156+
var input = document.getElementById("tree-input");
157+
var inputValue = 0;
158+
159+
dynamicTree.addEventListener("ui5-itemToggle", function(event) {
160+
var item = event.detail.item; // get the node that is toggled
161+
console.log(item);
162+
// Only for the dynamic node, only when it's empty
163+
if (item.id === "dynamicNode" && item.children.length === 0) {
164+
busyIndicator.active = true;
165+
event.preventDefault(); // do not let the toggle button switch yet
166+
setTimeout(function() {
167+
var newItem = document.createElement("ui5-tree-item"); // Fetching from db....
168+
newItem.text = "Node fetched from DB after 2 sec";
169+
item.appendChild(newItem);
170+
item.toggle(); // now manually switch
171+
busyIndicator.active = false;
172+
}, 2000);
173+
}
174+
});
175+
176+
dynamicTree.addEventListener("ui5-itemClick", function(event) {
177+
var item = event.detail.item; // get the node that is toggled
178+
179+
// Only for the dynamic node, only when it's empty
180+
if (item.id === "dynamicNode") {
181+
input.value = ++inputValue;
182+
}
183+
});
135184
</script>
136185
</body>
137186

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const assert = require("chai").assert;
2+
3+
4+
describe("BusyIndicator general interaction", () => {
5+
browser.url("http://localhost:8080/test-resources/pages/BusyIndicator.html");
6+
7+
it("tests event propagation", () => {
8+
const busyIndicator = browser.$("#busy-tree");
9+
const dynamicItem = busyIndicator.$("ui5-tree").shadow$("ui5-list").$$("ui5-li-tree")[2].shadow$(".ui5-li-tree-toggle-box");
10+
const input = browser.$("#tree-input");
11+
12+
dynamicItem.click();
13+
dynamicItem.keys("Space");
14+
15+
assert.strictEqual(input.getProperty("value"), "0", "itemClick is not thrown");
16+
});
17+
18+
});

0 commit comments

Comments
 (0)