Skip to content

Commit 4f335c9

Browse files
Merge pull request #387 from nextcloud/fix/modal-focus-trap-loop
Fix dialog not appearing when another modal is open
2 parents f76f4da + 0ae3fc0 commit 4f335c9

7 files changed

Lines changed: 24 additions & 9 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44

55
## Unreleased
66

7+
### Fixed
8+
9+
- Fix dialog not appearing when another modal is open
10+
711
## 3.0.0 - 2022-09-07
812

913
### Breaking

l10n/messages.pot

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,26 @@ msgid ""
22
msgstr ""
33
"Content-Type: text/plain; charset=UTF-8\n"
44

5-
#: src/components/Dialog.vue:83
5+
#: src/components/Dialog.vue:84
66
msgid "Authentication required"
77
msgstr ""
88

9-
#: src/components/Dialog.vue:87
9+
#: src/components/Dialog.vue:88
1010
msgid "Confirm"
1111
msgstr ""
1212

13-
#: src/components/Dialog.vue:86
13+
#: src/components/Dialog.vue:87
1414
msgid "Failed to authenticate, please try again"
1515
msgstr ""
1616

17-
#: src/components/Dialog.vue:85
17+
#: src/components/Dialog.vue:86
1818
msgid "Password"
1919
msgstr ""
2020

2121
#: src/main.ts:21
2222
msgid "Password confirmation dialog already mounted"
2323
msgstr ""
2424

25-
#: src/components/Dialog.vue:84
25+
#: src/components/Dialog.vue:85
2626
msgid "This action requires you to confirm your password"
2727
msgstr ""

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"@nextcloud/capabilities": "^1.0.4",
3131
"@nextcloud/l10n": "^1.6.0",
3232
"@nextcloud/router": "^2.0.0",
33-
"@nextcloud/vue": "^7.0.0-beta.0",
33+
"@nextcloud/vue": "^7.0.0-beta.2",
3434
"vue": "^2.7.10"
3535
},
3636
"devDependencies": {

src/components/Dialog.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
<NcModal :id="dialogId"
2525
class="dialog"
2626
size="small"
27+
:container="null"
2728
@close="close">
2829
<div class="dialog__container">
2930
<h2 class="dialog__title">{{ titleText }}</h2>

src/globals.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export const DIALOG_ID = 'password-confirmation-dialog'
2+
export const MODAL_CLASS = 'modal-mask' // NcModal component root class https://github.com/nextcloud/nextcloud-vue/blob/v7.0.0-beta.2/src/components/NcModal/NcModal.vue

src/main.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Vue from 'vue'
22
import DialogComponent from './components/Dialog.vue'
3-
import { DIALOG_ID } from './globals.js'
3+
import { DIALOG_ID, MODAL_CLASS } from './globals.js'
44
import { t } from './utils/l10n.js'
55

66
import type { ComponentInstance } from 'vue'
@@ -27,7 +27,16 @@ export const confirmPassword = (): Promise<void> => {
2727

2828
const mountPoint = document.createElement('div')
2929
mountPoint.setAttribute('id', DIALOG_ID)
30-
document.body.prepend(mountPoint)
30+
31+
const modals = document.querySelectorAll(`.${MODAL_CLASS}`)
32+
const isModalMounted = Boolean(modals.length)
33+
34+
if (isModalMounted) {
35+
const previousModal = modals[modals.length - 1]
36+
previousModal.prepend(mountPoint)
37+
} else {
38+
document.body.prepend(mountPoint)
39+
}
3140

3241
const DialogClass = Vue.extend(DialogComponent)
3342
// Mount point element is replaced by the component

0 commit comments

Comments
 (0)