Skip to content

Commit a1dbdc3

Browse files
HtmlEditor: Fix for context menu not closing when escape button pressed (DevExpress#28954)
1 parent 2db15de commit a1dbdc3

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

packages/devextreme/js/__internal/ui/html_editor/modules/m_tableContextMenu.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ if (Quill) {
7171
eventsEngine.off(this.editorInstance._getContent(), CONTEXT_MENU_EVENT);
7272
}
7373

74+
_onContextMenuInitialized(e) {
75+
e.component.registerKeyHandler('escape', () => {
76+
this.editorInstance.focus();
77+
});
78+
}
79+
7480
_createContextMenu(items) {
7581
const $container = $('<div>').appendTo(this.editorInstance.$element());
7682
const menuConfig = this._getMenuConfig(items);
@@ -160,6 +166,9 @@ if (Quill) {
160166
target: this._quillContainer,
161167
showEvent: null,
162168
hideOnParentScroll: false,
169+
onInitialized: (e) => {
170+
this._onContextMenuInitialized(e);
171+
},
163172
items: customItems,
164173
};
165174
}

packages/devextreme/testing/tests/DevExpress.ui.widgets.htmlEditor/htmlEditorParts/tableContextMenuIntegration.tests.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const CONTEXT_MENU_OVERLAY_SELECTOR = '.dx-context-menu.dx-overlay-content';
3333
const ITEM_HAS_SUBMENU_CLASS = 'dx-menu-item-has-submenu';
3434
const ITEM_HAS_TEXT_CLASS = 'dx-menu-item-has-text';
3535
const SUBMENU_CLASS = 'dx-submenu';
36+
const HTML_EDITOR_CONTENT_CLASS = 'dx-htmleditor-content';
3637
const SUBMENU_ITEMS_SELECTOR = `.${SUBMENU_CLASS} .${SUBMENU_CLASS} .${ITEM_HAS_TEXT_CLASS}`;
3738

3839
module('Table context menu integration', {
@@ -383,6 +384,21 @@ module('Table context menu integration', {
383384

384385
assert.strictEqual($table.length, 0, 'Table is deleted');
385386
});
387+
388+
test('Pressing escape button should return focus to html editor', function(assert) {
389+
this.createWidget();
390+
391+
const contextMenu = this.getContextMenu();
392+
const $editorContent = $(`.${HTML_EDITOR_CONTENT_CLASS}`);
393+
394+
contextMenu.trigger($.Event('keydown', { key: 'Escape', keyCode: 27, which: 27 }));
395+
this.clock.tick(10);
396+
397+
const shadowRoot = document.activeElement.shadowRoot;
398+
const activeElement = shadowRoot ? shadowRoot.activeElement : document.activeElement;
399+
400+
assert.strictEqual(activeElement, $editorContent.get(0), 'Editor should regain focus after Escape');
401+
});
386402
});
387403

388404
module('Custom context menu', {}, () => {

0 commit comments

Comments
 (0)