Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion addon/components/docs-keyboard-shortcuts/component.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Component from '@ember/component';
import { on } from '@ember/object/evented';
import { later } from "@ember/runloop";
import { later } from '@ember/runloop';
import layout from './template';
import { EKMixin, keyUp } from 'ember-keyboard';
import { inject as service } from '@ember/service';
Expand Down Expand Up @@ -55,6 +55,12 @@ export default Component.extend(EKMixin, {
}
}),

hideKeyboardShortcuts: on(keyUp('Escape'), function() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this only trigger for this component or would this interfere with other esc listeners?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not very familiar with ember-keyboard, but based on a read-through of their "priority" docs, my understanding is that this function will be called any time Esc is pressed while a) this {{docs-keyboard-shortcuts}} component is rendered and b) this component's keyboardActivated prop is true.

The ember-cli-addon-docs docs suggest rendering {{docs-keyboard-shortcuts}} in the application.hbs, and its keyboardActivated prop is set to true in its init, so for anyone who opts in to keyboard shortcuts it seems like yes, this callback function will be called on any docs page when Esc is pressed.

This is the case with all the other shortcuts already, though, and (again based on my reading of ember-keyboard docs) the keyup event's propagation won't be stopped, so it seems unlikely that it would interfere with any other keyup listeners on the page.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bantic gotcha, this seems fine to me then

if (!formElementHasFocus() && this.get('isShowingKeyboardShortcuts')) {
this.set('isShowingKeyboardShortcuts', false);
}
}),

actions: {
toggleKeyboardShortcuts() {
this.toggleProperty('isShowingKeyboardShortcuts');
Expand Down
8 changes: 8 additions & 0 deletions addon/components/docs-keyboard-shortcuts/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@
Bring up this help dialog
</td>
</tr>
<tr>
<td>
<code class='docs__keyboard-key'>esc</code>
</td>
<td>
Hide this help dialog
</td>
</tr>

<tr>
<th></th>
Expand Down