Skip to content

Commit 21ff736

Browse files
committed
fix: image editor focus trap
Signed-off-by: Hamza <hamzamahjoubi221@gmail.com>
1 parent ad8d244 commit 21ff736

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

src/components/ImageEditor.vue

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export default {
3939
data() {
4040
return {
4141
imageEditor: null,
42+
observer: null,
4243
}
4344
},
4445
@@ -133,14 +134,31 @@ export default {
133134
)
134135
this.imageEditor.render()
135136
window.addEventListener('keydown', this.handleKeydown, true)
136-
window.addEventListener('DOMNodeInserted', this.handleSfxModal)
137+
138+
this.observer = new MutationObserver((mutations) => {
139+
mutations.forEach((mutation) => {
140+
if (mutation.type === 'childList') {
141+
mutation.addedNodes.forEach((node) => {
142+
if (node.classList.contains('FIE_root') || node.classList.contains('SfxModal-Wrapper')) {
143+
emit('viewer:trapElements:changed', node)
144+
}
145+
})
146+
}
147+
})
148+
})
149+
// using body instead of the editor ref because save modal is not mounted in editor
150+
this.observer.observe(document.body, {
151+
childList: true,
152+
subtree: true,
153+
})
137154
138155
},
139156
140157
beforeDestroy() {
141158
if (this.imageEditor) {
142159
this.imageEditor.terminate()
143160
}
161+
this.observer.disconnect()
144162
window.removeEventListener('keydown', this.handleKeydown, true)
145163
},
146164

0 commit comments

Comments
 (0)