Skip to content

Commit 245a69a

Browse files
banticRobbieTheWagner
authored andcommitted
Use "Escape" key to dismiss Keyboard Shortcuts modal (ember-learn#394)
Adds a keyUp listener for 'Escape' that dismisses the shortcuts modal when invoked. Also fixes an unrelated inconsistency in quote style in the keyboard-shortcuts component.
1 parent 3352c6e commit 245a69a

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

addon/components/docs-keyboard-shortcuts/component.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Component from '@ember/component';
22
import { on } from '@ember/object/evented';
3-
import { later } from "@ember/runloop";
3+
import { later } from '@ember/runloop';
44
import layout from './template';
55
import { EKMixin, keyUp } from 'ember-keyboard';
66
import { inject as service } from '@ember/service';
@@ -53,6 +53,12 @@ export default Component.extend(EKMixin, {
5353
}
5454
}),
5555

56+
hideKeyboardShortcuts: on(keyUp('Escape'), function() {
57+
if (!formElementHasFocus() && this.get('isShowingKeyboardShortcuts')) {
58+
this.set('isShowingKeyboardShortcuts', false);
59+
}
60+
}),
61+
5662
actions: {
5763
toggleKeyboardShortcuts() {
5864
this.toggleProperty('isShowingKeyboardShortcuts');

addon/components/docs-keyboard-shortcuts/template.hbs

+8
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@
4949
Bring up this help dialog
5050
</td>
5151
</tr>
52+
<tr>
53+
<td>
54+
<code class='docs__keyboard-key'>esc</code>
55+
</td>
56+
<td>
57+
Hide this help dialog
58+
</td>
59+
</tr>
5260

5361
<tr>
5462
<th></th>

0 commit comments

Comments
 (0)