Skip to content

Commit cc8acc7

Browse files
feat(ui5-busy-indicator): add new "delay" property (#3419)
1 parent 3b1c0b5 commit cc8acc7

11 files changed

+118
-7
lines changed

packages/fiori/src/NotificationListGroupItem.hbs

+6-1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@
8282
</ui5-list>
8383

8484
{{#if busy}}
85-
<ui5-busy-indicator active size="Medium" class="ui5-nli-busy"></ui5-busy-indicator>
85+
<ui5-busy-indicator
86+
delay="{{busyDelay}}"
87+
active
88+
size="Medium"
89+
class="ui5-nli-busy"
90+
></ui5-busy-indicator>
8691
{{/if}}
8792
</li>

packages/fiori/src/NotificationListItem.hbs

+6-1
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@
9696
</div>
9797

9898
{{#if busy}}
99-
<ui5-busy-indicator active size="Medium" class="ui5-nli-busy"></ui5-busy-indicator>
99+
<ui5-busy-indicator
100+
delay="{{busyDelay}}"
101+
active
102+
size="Medium"
103+
class="ui5-nli-busy"
104+
></ui5-busy-indicator>
100105
{{/if}}
101106
</li>

packages/fiori/src/NotificationListItemBase.js

+13
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { isSpace } from "@ui5/webcomponents-base/dist/Keys.js";
22
import { getI18nBundle } from "@ui5/webcomponents-base/dist/i18nBundle.js";
33

44
import ListItemBase from "@ui5/webcomponents/dist/ListItemBase.js";
5+
import Integer from "@ui5/webcomponents-base/dist/types/Integer.js";
56
import Priority from "@ui5/webcomponents/dist/types/Priority.js";
67

78
// Icons
@@ -85,6 +86,18 @@ const metadata = {
8586
busy: {
8687
type: Boolean,
8788
},
89+
90+
/**
91+
* Defines the delay in milliseconds, after which the busy indicator will show up for this component.
92+
*
93+
* @type {Integer}
94+
* @defaultValue 1000
95+
* @public
96+
*/
97+
busyDelay: {
98+
type: Integer,
99+
defaultValue: 1000,
100+
},
88101
},
89102
slots: /** @lends sap.ui.webcomponents.fiori.NotificationListItemBase.prototype */ {
90103

packages/main/src/BusyIndicator.hbs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div class="{{classes.root}}">
2-
{{#if active}}
2+
{{#if _isBusy}}
33
<div
44
class="ui5-busy-indicator-busy-area"
55
title="{{ariaTitle}}"

packages/main/src/BusyIndicator.js

+44
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import litRender from "@ui5/webcomponents-base/dist/renderer/LitRenderer.js";
33
import { isIE } from "@ui5/webcomponents-base/dist/Device.js";
44
import { fetchI18nBundle, getI18nBundle } from "@ui5/webcomponents-base/dist/i18nBundle.js";
55
import { isTabNext } from "@ui5/webcomponents-base/dist/Keys.js";
6+
import Integer from "@ui5/webcomponents-base/dist/types/Integer.js";
67
import BusyIndicatorSize from "./types/BusyIndicatorSize.js";
78
import Label from "./Label.js";
89

@@ -78,6 +79,27 @@ const metadata = {
7879
active: {
7980
type: Boolean,
8081
},
82+
83+
/**
84+
* Defines the delay in milliseconds, after which the busy indicator will be visible on the screen.
85+
*
86+
* @type {Integer}
87+
* @defaultValue 1000
88+
* @public
89+
*/
90+
delay: {
91+
type: Integer,
92+
defaultValue: 1000,
93+
},
94+
95+
/**
96+
* Defines if the component is currently in busy state.
97+
* @private
98+
*/
99+
_isBusy: {
100+
type: Boolean,
101+
noAttribute: true,
102+
},
81103
},
82104
};
83105

@@ -143,6 +165,11 @@ class BusyIndicator extends UI5Element {
143165
}
144166

145167
onExitDOM() {
168+
if (this._busyTimeoutId) {
169+
clearTimeout(this._busyTimeoutId);
170+
delete this._busyTimeoutId;
171+
}
172+
146173
this.removeEventListener("keydown", this._keydownHandler, true);
147174
this.removeEventListener("keyup", this._preventEventHandler, true);
148175
}
@@ -188,6 +215,23 @@ class BusyIndicator extends UI5Element {
188215
};
189216
}
190217

218+
onBeforeRendering() {
219+
if (this.active) {
220+
if (!this._isBusy && !this._busyTimeoutId) {
221+
this._busyTimeoutId = setTimeout(() => {
222+
delete this._busyTimeoutId;
223+
this._isBusy = true;
224+
}, Math.max(0, this.delay));
225+
}
226+
} else {
227+
if (this._busyTimeoutId) {
228+
clearTimeout(this._busyTimeoutId);
229+
delete this._busyTimeoutId;
230+
}
231+
this._isBusy = false;
232+
}
233+
}
234+
191235
_handleKeydown(event) {
192236
if (!this.active) {
193237
return;

packages/main/src/List.hbs

+3-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@
5656
{{#if busy}}
5757
<div class="ui5-list-busy-row">
5858
<ui5-busy-indicator
59-
active size="Medium"
59+
delay="{{busyDelay}}"
60+
active
61+
size="Medium"
6062
class="ui5-list-busy-ind"
6163
style="{{styles.busyInd}}"
6264
></ui5-busy-indicator>

packages/main/src/List.js

+13
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { isIE } from "@ui5/webcomponents-base/dist/Device.js";
66
import { renderFinished } from "@ui5/webcomponents-base/dist/Render.js";
77
import { getLastTabbableElement } from "@ui5/webcomponents-base/dist/util/TabbableElements.js";
88
import { isTabNext, isSpace, isEnter } from "@ui5/webcomponents-base/dist/Keys.js";
9+
import Integer from "@ui5/webcomponents-base/dist/types/Integer.js";
910
import NavigationMode from "@ui5/webcomponents-base/dist/types/NavigationMode.js";
1011
import { getEffectiveAriaLabelText } from "@ui5/webcomponents-base/dist/util/AriaLabelHelper.js";
1112
import { fetchI18nBundle, getI18nBundle } from "@ui5/webcomponents-base/dist/i18nBundle.js";
@@ -185,6 +186,18 @@ const metadata = {
185186
type: Boolean,
186187
},
187188

189+
/**
190+
* Defines the delay in milliseconds, after which the busy indicator will show up for this component.
191+
*
192+
* @type {Integer}
193+
* @defaultValue 1000
194+
* @public
195+
*/
196+
busyDelay: {
197+
type: Integer,
198+
defaultValue: 1000,
199+
},
200+
188201
/**
189202
* @type {String}
190203
* @defaultvalue ""

packages/main/src/Table.hbs

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
{{#*inline "busyRow"}}
8989
<div tabindex="-1" class="ui5-table-busy-row">
9090
<ui5-busy-indicator
91+
delay="{{busyDelay}}"
9192
class="ui5-table-busy-ind"
9293
style="{{styles.busy}}"
9394
active

packages/main/src/Table.js

+13
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import UI5Element from "@ui5/webcomponents-base/dist/UI5Element.js";
22
import litRender from "@ui5/webcomponents-base/dist/renderer/LitRenderer.js";
33
import ResizeHandler from "@ui5/webcomponents-base/dist/delegate/ResizeHandler.js";
44
import ItemNavigation from "@ui5/webcomponents-base/dist/delegate/ItemNavigation.js";
5+
import Integer from "@ui5/webcomponents-base/dist/types/Integer.js";
56
import NavigationMode from "@ui5/webcomponents-base/dist/types/NavigationMode.js";
67
import { isIE } from "@ui5/webcomponents-base/dist/Device.js";
78
import { isSpace, isEnter } from "@ui5/webcomponents-base/dist/Keys.js";
@@ -167,6 +168,18 @@ const metadata = {
167168
type: Boolean,
168169
},
169170

171+
/**
172+
* Defines the delay in milliseconds, after which the busy indicator will show up for this component.
173+
*
174+
* @type {Integer}
175+
* @defaultValue 1000
176+
* @public
177+
*/
178+
busyDelay: {
179+
type: Integer,
180+
defaultValue: 1000,
181+
},
182+
170183
/**
171184
* Determines whether the column headers remain fixed at the top of the page during
172185
* vertical scrolling as long as the Web Component is in the viewport.

packages/main/test/pages/BusyIndicator.html

+2-3
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,9 @@
172172
</div>
173173
</ui5-dialog>
174174
<script>
175-
var busyIndicator = document.getElementById("busy-container");
176-
var list = document.getElementById("fetch-list");
177-
178175
document.getElementById("fetch-btn").addEventListener("click", function(event) {
176+
var busyIndicator = document.getElementById("busy-container");
177+
var list = document.getElementById("fetch-list");
179178
busyIndicator.setAttribute("active", "");
180179

181180
setTimeout(function() {

packages/main/test/specs/BusyIndicator.spec.js

+16
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,22 @@ describe("BusyIndicator general interaction", () => {
1818
assert.strictEqual(input.getProperty("value"), "0", "itemClick is not thrown");
1919
});
2020

21+
it("test activation", () => {
22+
const busyIndicator = browser.$("#busy-container");
23+
busyIndicator.setAttribute("active", "");
24+
25+
const busyArea = busyIndicator.shadow$(".ui5-busy-indicator-busy-area");
26+
assert.notOk(busyArea.isExisting(), "busy area is not yet created");
27+
28+
browser.pause(3000);
29+
30+
assert.ok(busyArea.isExisting(), "busy area is created");
31+
32+
// reset
33+
busyIndicator.removeAttribute("active");
34+
assert.notOk(busyArea.isExisting(), "busy area is removed");
35+
});
36+
2137
it("tests focus handling", () => {
2238
const busyIndicator = browser.$("#indicator1");
2339
busyIndicator.click();

0 commit comments

Comments
 (0)