Handle Esc key in reply dialog manually

As a component of allowing arbitrary CCs, we must allow for the Esc key
to be pressed to clear autocomplete suggestions. The default behavior of
gr-overlay is to close when Esc is pressed.

This change supplies a property to the reply dialog gr-overlay to
prevent automatically closing on Esc, and fires the cancel event
manually.

Feature: Issue 5832
Change-Id: Iff4d8ea49dace83bb76d0e678ffc548c101658d1
This commit is contained in:
Kasper Nilsson
2017-03-21 16:41:24 -07:00
parent fb97e86963
commit ff0745d4cb
4 changed files with 25 additions and 1 deletions

View File

@@ -485,6 +485,7 @@ limitations under the License.
<gr-overlay id="replyOverlay"
class="scrollable"
no-cancel-on-outside-click
no-cancel-on-esc-key
on-iron-overlay-opened="_handleReplyOverlayOpen"
with-backdrop>
<gr-reply-dialog id="replyDialog"

View File

@@ -14,10 +14,11 @@ See the License for the specific language governing permissions and
limitations under the License.
-->
<link rel="import" href="../../../behaviors/keyboard-shortcut-behavior/keyboard-shortcut-behavior.html">
<link rel="import" href="../../../behaviors/rest-client-behavior.html">
<link rel="import" href="../../../bower_components/polymer/polymer.html">
<link rel="import" href="../../../bower_components/iron-autogrow-textarea/iron-autogrow-textarea.html">
<link rel="import" href="../../../bower_components/iron-selector/iron-selector.html">
<link rel="import" href="../../../behaviors/rest-client-behavior.html">
<link rel="import" href="../../shared/gr-account-chip/gr-account-chip.html">
<link rel="import" href="../../shared/gr-button/gr-button.html">
<link rel="import" href="../../shared/gr-formatted-text/gr-formatted-text.html">

View File

@@ -116,9 +116,14 @@
FocusTarget: FocusTarget,
behaviors: [
Gerrit.KeyboardShortcutBehavior,
Gerrit.RESTClientBehavior,
],
keyBindings: {
'esc': '_handleEscKey',
},
observers: [
'_changeUpdated(change.reviewers.*, change.owner, serverConfig)',
'_ccsChanged(_ccs.splices)',
@@ -162,6 +167,10 @@
selectorEl.selectIndex(selectorEl.indexOf(item));
},
_handleEscKey: function(e) {
this.cancel();
},
_ccsChanged: function(splices) {
if (splices && splices.indexSplices) {
this._processReviewerChange(splices.indexSplices, ReviewerTypes.CC);
@@ -522,6 +531,10 @@
_cancelTapHandler: function(e) {
e.preventDefault();
this.cancel();
},
cancel: function() {
this.fire('cancel', null, {bubbles: false});
this._purgeReviewersPendingRemove(true);
this._rebuildReviewerArrays(this.change.reviewers, this._owner,

View File

@@ -684,5 +684,14 @@ limitations under the License.
done();
});
});
test('emits cancel on esc key', function() {
var cancelHandler = sandbox.spy();
element.addEventListener('cancel', cancelHandler);
MockInteractions.pressAndReleaseKeyOn(element, 27, null, 'esc');
flushAsynchronousOperations();
assert.isTrue(cancelHandler.called);
});
});
</script>