Skip to content

Commit 1c2a94a

Browse files
authored
fix(ui5-toast): infinite loop prevented (#1320)
1 parent 19445d1 commit 1c2a94a

File tree

2 files changed

+16
-22
lines changed

2 files changed

+16
-22
lines changed

packages/main/src/Toast.js

+15-21
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import ToastPlacement from "./types/ToastPlacement.js";
88
// Styles
99
import ToastCss from "./generated/themes/Toast.css.js";
1010

11-
// Static Constants
12-
const MAXIMUM_ALLOWED_TRANSITION_DURATION_IN_MILLISECONDS = 1000;
13-
const MINIMUM_ALLOWED_DURATION_IN_MILLISECONDS = 500;
11+
// Constants
12+
const MIN_DURATION = 500;
13+
const MAX_DURATION = 1000;
1414

1515
/**
1616
* @public
@@ -147,22 +147,6 @@ class Toast extends UI5Element {
147147
return ToastTemplate;
148148
}
149149

150-
static get maximumAllowedTransition() {
151-
return MAXIMUM_ALLOWED_TRANSITION_DURATION_IN_MILLISECONDS;
152-
}
153-
154-
static get minimumAllowedDuration() {
155-
return MINIMUM_ALLOWED_DURATION_IN_MILLISECONDS;
156-
}
157-
158-
onBeforeRendering() {
159-
// If the minimum duration is lower than 500ms, we force
160-
// it to be 500ms, as described in the documentation.
161-
if (this.duration < Toast.minimumAllowedDuration) {
162-
this.duration = Toast.minimumAllowedDuration;
163-
}
164-
}
165-
166150
onAfterRendering() {
167151
if (this._reopen) {
168152
this._reopen = false;
@@ -187,22 +171,32 @@ class Toast extends UI5Element {
187171
}
188172
}
189173

174+
/**
175+
* If the minimum duration is lower than 500ms, we force
176+
* it to be 500ms, as described in the documentation.
177+
* @private
178+
* @returns {*}
179+
*/
180+
get effectiveDuration() {
181+
return this.duration < MIN_DURATION ? MIN_DURATION : this.duration;
182+
}
183+
190184
get rtl() {
191185
return getRTL() ? "rtl" : undefined;
192186
}
193187

194188
get styles() {
195189
// Transition duration (animation) should be a third of the duration
196190
// property, but not bigger than the maximum allowed (1000ms).
197-
const transitionDuration = Math.min(this.duration / 3, Toast.maximumAllowedTransition);
191+
const transitionDuration = Math.min(this.effectiveDuration / 3, MAX_DURATION);
198192

199193
return {
200194
root: {
201195
"transition-duration": this.open ? `${transitionDuration}ms` : "",
202196

203197
// Transition delay is the duration property minus the
204198
// transition duration (animation).
205-
"transition-delay": this.open ? `${this.duration - transitionDuration}ms` : "",
199+
"transition-delay": this.open ? `${this.effectiveDuration - transitionDuration}ms` : "",
206200

207201
// We alter the opacity property, in order to trigger transition
208202
"opacity": this.open && !this.hover ? "0" : "",

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ describe("Toast general interaction", () => {
114114
it("tests minimum allowed duration", () => {
115115
const toast = browser.$("#wcToastTE");
116116

117-
assert.strictEqual(toast.getProperty("duration"), 500,
117+
assert.strictEqual(toast.getProperty("effectiveDuration"), 500,
118118
"Duration property is forced to be 500, when -1 is passed for duration attribute.");
119119
});
120120
});

0 commit comments

Comments
 (0)