Skip to content

Commit 456c8f8

Browse files
authored
Merge pull request #12810 from nextcloud/focus-trap-2
fix(ui): Handle focus trap through provide / inject
2 parents f3060cd + 6391525 commit 456c8f8

6 files changed

Lines changed: 31 additions & 43 deletions

File tree

src/components/AccountSettings.vue

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<p class="settings-hint">
2626
{{ t('mail', 'A signature is added to the text of new messages and replies.') }}
2727
</p>
28-
<SignatureSettings :account="account" @show-toolbar="handleShowToolbar" />
28+
<SignatureSettings :account="account" />
2929
</AppSettingsSection>
3030
<AppSettingsSection id="writing-mode" :name="t('mail', 'Writing mode')">
3131
<p class="settings-hint">
@@ -179,6 +179,12 @@ export default {
179179
NcCheckboxRadioSwitch,
180180
},
181181
182+
provide() {
183+
return {
184+
addToFocusTrap: (trapElement) => this.trapElements.push(trapElement),
185+
}
186+
},
187+
182188
props: {
183189
account: {
184190
required: true,
@@ -234,10 +240,6 @@ export default {
234240
this.$emit('update:open')
235241
},
236242
237-
handleShowToolbar(element) {
238-
this.trapElements.push(element)
239-
},
240-
241243
async onToggleClassification(classificationEnabled) {
242244
this.loadingClassificationToggle = true
243245
await this.mainStore.patchAccount({ account: this.account, data: { classificationEnabled } })

src/components/AppSettingsMenu.vue

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,7 @@
114114
:label="t('mail', 'Text blocks')"
115115
:description="t('mail', 'Reusable pieces of text that can be inserted in messages')">
116116
<List
117-
:text-blocks="getMyTextBlocks()"
118-
@show-toolbar="handleShowToolbar" />
117+
:text-blocks="getMyTextBlocks()" />
119118
<NcButton variant="secondary" wide @click="() => textBlockDialogOpen = true">
120119
<template #icon>
121120
<IconAdd :size="20" />
@@ -126,8 +125,7 @@
126125
<h6>{{ t('mail', 'Shared with me') }}</h6>
127126
<List
128127
:text-blocks="getSharedTextBlocks()"
129-
:shared="true"
130-
@show-toolbar="handleShowToolbar" />
128+
:shared="true" />
131129
</template>
132130
</NcFormGroup>
133131
</NcAppSettingsSection>
@@ -243,8 +241,7 @@
243241
:is-bordered="true"
244242
:html="true"
245243
:placeholder="t('mail', 'Content of the text block')"
246-
:bus="bus"
247-
:show-toolbar="handleShowToolbar" />
244+
:bus="bus" />
248245
<div class="text-block-buttons">
249246
<NcButton
250247
variant="tertiary"
@@ -345,6 +342,12 @@ export default {
345342
IconArrow,
346343
},
347344
345+
provide() {
346+
return {
347+
addToFocusTrap: (trapElement) => this.trapElements.push(trapElement),
348+
}
349+
},
350+
348351
props: {
349352
open: {
350353
required: true,
@@ -744,10 +747,6 @@ export default {
744747
document.body.append(iframe)
745748
},
746749
747-
handleShowToolbar(element) {
748-
this.trapElements.push(element)
749-
},
750-
751750
newTextBlock() {
752751
this.mainStore.createTextBlock({ ...this.localTextBlock })
753752
this.textBlockDialogOpen = false

src/components/Composer.vue

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,7 @@
260260
@input="onEditorInput"
261261
@ready="onEditorReady"
262262
@mention="handleMention"
263-
@submit="onEditorSubmit"
264-
@show-toolbar="handleShow" />
263+
@submit="onEditorSubmit" />
265264
<MailvelopeEditor
266265
v-else
267266
ref="mailvelopeEditor"
@@ -711,6 +710,7 @@ export default {
711710
type: Array,
712711
required: true,
713712
},
713+
714714
},
715715
716716
data() {
@@ -1141,10 +1141,6 @@ export default {
11411141
return false
11421142
},
11431143
1144-
handleShow(event) {
1145-
this.$emit('show-toolbar', event)
1146-
},
1147-
11481144
openPicker() {
11491145
this.isPickerOpen = true
11501146
},

src/components/NewMessageModal.vue

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,7 @@
107107
@draft="onDraft"
108108
@discard-draft="discardDraft"
109109
@upload-attachment="onAttachmentUploading"
110-
@send="onSend"
111-
@show-toolbar="handleShow" />
110+
@send="onSend" />
112111
</KeepAlive>
113112
</div>
114113

@@ -159,6 +158,12 @@ export default {
159158
RecipientInfo,
160159
},
161160
161+
provide() {
162+
return {
163+
addToFocusTrap: (trapElement) => this.additionalTrapElements.push(trapElement),
164+
}
165+
},
166+
162167
props: {
163168
accounts: {
164169
type: Array,
@@ -307,10 +312,6 @@ export default {
307312
}
308313
},
309314
310-
handleShow(element) {
311-
this.additionalTrapElements.push(element)
312-
},
313-
314315
/**
315316
* @param {object} data Message data
316317
* @param {object=} opts Options

src/components/SignatureSettings.vue

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@
3232
:html="true"
3333
:placeholder="t('mail', 'Signature …')"
3434
:bus="bus"
35-
class="signature-editor-wrapper__editor"
36-
@show-toolbar="handleShowToolbar" />
35+
class="signature-editor-wrapper__editor" />
3736
</div>
3837
<p v-if="isLargeSignature" class="warning-large-signature">
3938
{{ t('mail', 'Your signature is larger than 2 MB. This may affect the performance of your editor.') }}
@@ -189,24 +188,11 @@ export default {
189188
})
190189
},
191190
192-
handleShowToolbar(event) {
193-
this.$emit('show-toolbar', event)
194-
},
195191
},
196192
}
197193
</script>
198194

199195
<style lang="scss" scoped>
200-
.ck.ck-editor__editable_inline {
201-
width: 100%;
202-
max-width: 78vw;
203-
height: 100%;
204-
min-height: 100px;
205-
border-radius: var(--border-radius) !important;
206-
border: 1px solid var(--color-border) !important;
207-
box-shadow: none !important;
208-
}
209-
210196
/* Wrapper to visually delimit the signature editor area from surrounding settings */
211197
.signature-editor-wrapper {
212198
margin-top: 8px;

src/components/TextEditor.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ export default {
6969
Ckeditor: CKEditor.component,
7070
},
7171
72+
inject: {
73+
addToFocusTrap: { default: () => {} },
74+
},
75+
7276
props: {
7377
value: {
7478
type: String,
@@ -494,7 +498,7 @@ export default {
494498
}
495499
496500
if (this.html) {
497-
this.$emit('show-toolbar', editor.ui._focusableToolbarDefinitions[0].toolbarView.element)
501+
this.addToFocusTrap('.ck-body-wrapper')
498502
}
499503
500504
this.bus.on('append-to-body-at-cursor', this.appendToBodyAtCursor)

0 commit comments

Comments
 (0)