Skip to content

Commit 17a7efb

Browse files
author
Ruslan Farkhutdinov
committed
Popup: Support _ignoreCloseOnChildEscape option
1 parent b76a304 commit 17a7efb

3 files changed

Lines changed: 25 additions & 9 deletions

File tree

packages/devextreme/js/__internal/ui/popup/m_popup.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ export interface PopupProperties extends Properties {
180180
useDefaultToolbarButtons?: boolean;
181181

182182
useFlatToolbarButtons?: boolean;
183+
184+
_ignoreCloseOnChildEscape?: boolean;
183185
}
184186

185187
class Popup<
@@ -227,18 +229,19 @@ class Popup<
227229
}
228230

229231
_keyboardHandler(options: KeyboardKeyDownEvent, onlyChildProcessing?: boolean): void {
230-
if (!onlyChildProcessing) {
231-
const e = options.originalEvent;
232-
const $target = $(e.target);
232+
// eslint-disable-next-line @typescript-eslint/naming-convention
233+
const { _ignoreCloseOnChildEscape } = this.option();
234+
const e = options.originalEvent;
235+
const $target = $(e.target);
233236

234-
if (this._$content && !$target.is(this._$content)
237+
if (this._$content && !$target.is(this._$content)
235238
&& options.keyName === ESC_KEY_NAME
236-
&& !e.isDefaultPrevented()) {
237-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
238-
this.hide();
239+
&& !e.isDefaultPrevented()
240+
&& !_ignoreCloseOnChildEscape) {
241+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
242+
this.hide();
239243

240-
return;
241-
}
244+
return;
242245
}
243246

244247
super._keyboardHandler(options, onlyChildProcessing);
@@ -266,6 +269,7 @@ class Popup<
266269
useDefaultToolbarButtons: false,
267270
useFlatToolbarButtons: false,
268271
autoResizeEnabled: true,
272+
_ignoreCloseOnChildEscape: undefined,
269273
};
270274
}
271275

packages/devextreme/js/__internal/ui/toolbar/internal/toolbar.menu.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ export default class DropDownMenu extends Widget<DropDownMenuProperties> {
286286
showTitle: false,
287287
fullScreen: false,
288288
ignoreChildEvents: false,
289+
_ignoreCloseOnChildEscape: true,
289290
_fixWrapperPosition: true,
290291
});
291292
this._popup.registerKeyHandler('space', (

packages/devextreme/testing/tests/DevExpress.ui.widgets/popup.tests.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2714,6 +2714,17 @@ QUnit.module('keyboard navigation', {
27142714

27152715
assert.strictEqual(this.popup.option('visible'), true, 'popup remains visible after pressing esc on a child element that prevents default');
27162716
});
2717+
2718+
QUnit.test('should remain visible when child element presses escape and _ignoreCloseOnChildEscape is true', function(assert) {
2719+
this.init({ dragEnabled: false, _ignoreCloseOnChildEscape: true });
2720+
2721+
const $input = $('<input>').appendTo(this.popup.$content());
2722+
const keyboard = keyboardMock($input);
2723+
2724+
keyboard.keyDown('esc');
2725+
2726+
assert.strictEqual(this.popup.option('visible'), true, 'popup remains visible when _closeOnChildEscape is false');
2727+
});
27172728
});
27182729

27192730
QUnit.module('rendering', {

0 commit comments

Comments
 (0)