Skip to content

Commit ae81b1b

Browse files
committed
fix(ui/portal): (backport from Qv2) avoid registering portal multiple times; improve algorithm and protect against future failures quasarframework#11767
1 parent 8228dfa commit ae81b1b

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

ui/src/mixins/portal.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ const Portal = {
8282
return
8383
}
8484

85+
if (this.__portalIsActive === true) { return }
86+
this.__portalIsActive = true
87+
8588
if (this.focusObj === void 0) {
8689
this.focusObj = {}
8790
}
@@ -116,6 +119,7 @@ const Portal = {
116119
},
117120

118121
__hidePortal () {
122+
this.__portalIsActive = false
119123
removeFocusWaitFlag(this.focusObj)
120124

121125
if (this.__portal !== void 0) {

ui/src/utils/focus-manager.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
let queue = []
2-
const waitFlags = []
2+
let waitFlags = []
3+
4+
function clearFlag (flag) {
5+
waitFlags = waitFlags.filter(entry => entry !== flag)
6+
}
37

48
export function addFocusWaitFlag (flag) {
9+
clearFlag(flag)
510
waitFlags.push(flag)
611
}
712

813
export function removeFocusWaitFlag (flag) {
9-
const index = waitFlags.indexOf(flag)
10-
if (index !== -1) {
11-
waitFlags.splice(index, 1)
12-
}
14+
clearFlag(flag)
1315

1416
if (waitFlags.length === 0 && queue.length > 0) {
1517
// only call last focus handler (can't focus multiple things at once)
@@ -29,8 +31,5 @@ export function addFocusFn (fn) {
2931
}
3032

3133
export function removeFocusFn (fn) {
32-
const index = queue.indexOf(fn)
33-
if (index !== -1) {
34-
queue.splice(index, 1)
35-
}
34+
queue = queue.filter(entry => entry !== fn)
3635
}

0 commit comments

Comments
 (0)