Skip to content

Commit a4a2ff7

Browse files
Fixed issue when esacpe key is pressed to close prompt
1 parent 3dcdba7 commit a4a2ff7

File tree

1 file changed

+34
-2
lines changed
  • app/code/Magento/Ui/view/base/web/js/modal

1 file changed

+34
-2
lines changed

app/code/Magento/Ui/view/base/web/js/modal/prompt.js

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ define([
1111
'underscore',
1212
'mage/template',
1313
'text!ui/template/modal/modal-prompt-content.html',
14+
'Magento_Ui/js/lib/key-codes',
1415
'jquery-ui-modules/widget',
1516
'Magento_Ui/js/modal/modal',
1617
'mage/translate'
17-
], function ($, _, template, promptContentTmpl) {
18+
], function ($, _, template, promptContentTmpl, keyCodes) {
1819
'use strict';
1920

2021
$.widget('mage.prompt', $.mage.modal, {
@@ -64,13 +65,31 @@ define([
6465
click: function () {
6566
this.closeModal(true);
6667
}
67-
}]
68+
}],
69+
keyEventHandlers: {
70+
71+
/**
72+
* Escape key press handler,
73+
* close modal window
74+
* @param {Object} event - event
75+
*/
76+
escapeKey: function (event) {
77+
if (this.options.isOpen && this.modal.find(document.activeElement).length ||
78+
this.options.isOpen && this.modal[0] === document.activeElement) {
79+
this._close();
80+
}
81+
}
82+
}
6883
},
6984

7085
/**
7186
* Create widget.
7287
*/
7388
_create: function () {
89+
_.bindAll(
90+
this,
91+
'keyEventSwitcher'
92+
);
7493
this.options.focus = this.options.promptField;
7594
this.options.validation = this.options.validation && this.options.validationRules.length;
7695
this._super();
@@ -118,6 +137,18 @@ define([
118137
return formTemplate;
119138
},
120139

140+
/**
141+
* Listener key events.
142+
* Call handler function if it exists
143+
*/
144+
keyEventSwitcher: function (event) {
145+
var key = keyCodes[event.keyCode];
146+
147+
if (this.options.keyEventHandlers.hasOwnProperty(key)) {
148+
this.options.keyEventHandlers[key].apply(this, arguments);
149+
}
150+
},
151+
121152
/**
122153
* Remove widget
123154
*/
@@ -177,3 +208,4 @@ define([
177208
return $('<div class="prompt-message"></div>').html(config.content).prompt(config);
178209
};
179210
});
211+

0 commit comments

Comments
 (0)