Skip to content

Commit 6a0f9d8

Browse files
committed
feat: added extra accessibility features
1 parent 2384653 commit 6a0f9d8

2 files changed

Lines changed: 24 additions & 5 deletions

File tree

packages/super-editor/src/components/SuperEditor.vue

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,20 @@ const initEditor = async ({ content, media = {}, mediaFiles = {}, fonts = {} } =
138138
};
139139
140140
const handleSuperEditorKeydown = (event) => {
141+
// cmd/ctrl + opt/alt + shift + M
142+
if ((event.metaKey || event.ctrlKey) && event.altKey && event.shiftKey) {
143+
if (event.code === 'KeyM') {
144+
const toolbar = document.querySelector('.superdoc-toolbar');
145+
if (toolbar) {
146+
toolbar.setAttribute('tabindex', '0');
147+
toolbar.focus();
148+
}
149+
}
150+
}
141151
emit('editor-keydown', { editor: editor.value });
142152
};
143153
154+
144155
const handleSuperEditorClick = (event) => {
145156
emit('editor-click', { editor: editor.value });
146157
let pmElement = editorElem.value?.querySelector('.ProseMirror');

packages/super-editor/src/components/toolbar/ButtonGroup.vue

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ const selectedOption = ref(null);
7878
const handleSelect = (item, option) => {
7979
closeDropdowns();
8080
const value = item.dropdownValueKey.value ? option[item.dropdownValueKey.value] : option.label;
81-
emit('command', { item, argument: value, option });
81+
emit('command', { item, argument: value, option, switchFocusToEditor: true });
8282
selectedOption.value = option.key;
8383
};
8484
@@ -132,6 +132,12 @@ const moveToNextButtonGroup = (e) => {
132132
if (nextButtonGroup) {
133133
nextButtonGroup.setAttribute('tabindex', '0');
134134
nextButtonGroup.focus();
135+
} else {
136+
// Move to the editor
137+
const editor = document.querySelector('.ProseMirror');
138+
if (editor) {
139+
editor.focus();
140+
}
135141
}
136142
};
137143
@@ -149,16 +155,19 @@ const moveToPreviousButtonGroup = (e) => {
149155
// Set tabindex to -1 for all other buttons
150156
const handleKeyDown = (e, item) => {
151157
e.preventDefault();
152-
e.stopPropagation();
153-
154158
switch (e.key) {
155159
case 'Enter':
156160
handleToolbarButtonClick(item, null, false);
157161
break;
162+
case 'Escape':
163+
closeDropdowns();
164+
break;
158165
case 'ArrowRight':
166+
closeDropdowns();
159167
moveToNextButton(e);
160168
break;
161169
case 'ArrowLeft':
170+
closeDropdowns();
162171
moveToPreviousButton(e);
163172
break;
164173
case 'Tab':
@@ -176,7 +185,6 @@ const handleFocus = (e) => {
176185
// Set the focus to the first button inside the button group that is not disabled
177186
const firstButton = e.target.closest('.button-group').querySelector('.toolbar-item-ctn:not(.disabled)');
178187
if (firstButton) {
179-
// Force focus on the first button
180188
firstButton.focus();
181189
}
182190
};
@@ -187,7 +195,7 @@ const handleFocus = (e) => {
187195
:style="getPositionStyle"
188196
class="button-group"
189197
role="group"
190-
@focus="(e) => handleFocus(e)"
198+
@focus="handleFocus"
191199
>
192200
<div
193201
v-for="(item, index) in toolbarItems"

0 commit comments

Comments
 (0)