Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions src/components/NcModal/NcModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,6 @@ export default {
playing: false,
slideshowTimeout: null,
focusTrap: null,
externalFocusTrapStack: [],
randId: GenRandomId(),
internalShow: true,
}
Expand Down Expand Up @@ -864,11 +863,6 @@ export default {
setReturnFocus: this.setReturnFocus,
}

// Deactivate other focus traps to unlock modal elements
this.externalFocusTrapStack = [...options.trapStack]
for (const trap of this.externalFocusTrapStack) {
trap.deactivate()
}
// Init focus trap
this.focusTrap = createFocusTrap([contentContainer, ...this.additionalTrapElements], options)
this.focusTrap.activate()
Expand All @@ -879,10 +873,6 @@ export default {
}
this.focusTrap?.deactivate()
this.focusTrap = null
for (const trap of this.externalFocusTrapStack) {
trap.activate()
}
this.externalFocusTrapStack = []
},

},
Expand Down
12 changes: 10 additions & 2 deletions src/utils/focusTrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ export function getTrapStack() {
*
* When some component manually implements its own focus-trap without using global focus-trap stack,
* it also needs to pause the global stack to avoid conflict.
*
* Note: if global focus-trap stack was modified outside TrapStackController (likely due to user actions),
* trap queue should be correctly handled by focus-trap itself.
* It is no longer safe to unpause cached `pausedStack`, as it can disrupt the current focus trap state.
* We assume that the focus-trap stack is self-regulated and ignore unpause.
*/
export function createTrapStackController() {
/**
Expand All @@ -45,10 +50,13 @@ export function createTrapStackController() {
},
/**
* Unpause the paused focus trap stack
* If the actual stack is different from the paused one, ignore unpause.
*/
unpause() {
for (const trap of pausedStack) {
trap.unpause()
if (pausedStack.length === getTrapStack().length) {
for (const trap of pausedStack) {
trap.unpause()
}
}
pausedStack = []
},
Expand Down
Loading