Skip to content

Commit

Permalink
fix: Fix tab focus when other elements are displayed next to text tha…
Browse files Browse the repository at this point in the history
…t are within a focus trap

Signed-off-by: Julius Härtl <jus@bitgrid.net>
  • Loading branch information
juliusknorr committed Jan 18, 2024
1 parent 2c30edb commit b4f7e90
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
17 changes: 10 additions & 7 deletions src/components/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -637,16 +637,10 @@ export default {

onFocus() {
this.emit('focus')

// Make sure that the focus trap doesn't catch tab keys while being in the contenteditable
window._nc_focus_trap?.[0]?.pause()
},

onBlur() {
this.emit('blur')

// Hand back focus to the previous trap
window._nc_focus_trap?.[0]?.unpause()
this.$el.focus()
},

onAddImageNode() {
Expand Down Expand Up @@ -744,6 +738,15 @@ export default {
this.$editor.commands.insertContent('\t')
this.$editor.commands.focus()
event.preventDefault()
event.stopPropagation()
return
}

if (event.key === 'Tab') {
const possibleEditorTabCommand = this.$editor.can().sinkListItem() || this.$editor.can().liftListItem() || this.$editor.can().goToNextCell() || this.$editor.can().goToPreviousCell()
if (possibleEditorTabCommand) {
event.stopPropagation()
}
return
}

Expand Down
3 changes: 1 addition & 2 deletions src/components/Editor/ContentContainer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
<EditorOutline />
</div>
<slot />
<EditorContent tabindex="0"
role="document"
<EditorContent role="document"
class="editor__content text-editor__content"
:editor="$editor" />
<div class="text-editor__content-wrapper__right" />
Expand Down
4 changes: 4 additions & 0 deletions src/css/prosemirror.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ div.ProseMirror {
font-size: var(--default-font-size);
outline: none;

&.ProseMirror-focused {
outline: 2px solid var(--color-main-text) !important;
}

:target {
// Menubar height: 44px + 3px bottom + 3px top padding
scroll-margin-top: 50px;
Expand Down

0 comments on commit b4f7e90

Please sign in to comment.