Lexical: Updated toolbars to re-focus on editor on escape press

This commit is contained in:
Dan Brown
2026-05-10 17:28:21 +01:00
parent 6367f007c1
commit 2aba39b176
2 changed files with 13 additions and 2 deletions

View File

@@ -30,7 +30,7 @@ export function isUiBuilderDefinition(object: any): object is EditorUiBuilderDef
export abstract class EditorUiElement {
protected dom: HTMLElement|null = null;
private context: EditorUiContext|null = null;
private abortController: AbortController = new AbortController();
protected abortController: AbortController = new AbortController();
protected abstract buildDOM(): HTMLElement;

View File

@@ -18,9 +18,20 @@ export class EditorContextToolbar extends EditorContainerUiElement {
}
protected buildDOM(): HTMLElement {
return el('div', {
const toolbar = el('div', {
class: 'editor-context-toolbar',
}, this.getChildren().map(child => child.getDOMElement()));
// Focus back on the editor on escape press
toolbar.addEventListener('keydown', (event: KeyboardEvent) => {
if (event.key === 'Escape') {
event.preventDefault();
event.stopPropagation();
this.getContext().editor.focus();
}
}, {signal: this.abortController.signal});
return toolbar;
}
/**