Skip to content

Commit

Permalink
Merge pull request #26 from github/fix-support-for-meta-shift-plane-w…
Browse files Browse the repository at this point in the history
…hile-retaining-short-upper-chars

fix: support for meta+shift plane while retaining short upper chars
  • Loading branch information
keithamus authored Apr 9, 2020
2 parents 13f210b + 2477610 commit c71a0c6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/hotkey.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
// Returns key character String or null.
export default function hotkey(event: KeyboardEvent) {
return `${event.ctrlKey ? 'Control+' : ''}${event.altKey ? 'Alt+' : ''}${event.metaKey ? 'Meta+' : ''}${
event.shiftKey ? 'Shift+' : ''
event.shiftKey && event.key.toUpperCase() !== event.key ? 'Shift+' : ''
}${event.key}`
}
6 changes: 6 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ describe('hotkey', function() {
document.dispatchEvent(new KeyboardEvent('keydown', {key: 'b'}))
assert.deepEqual(elementsActivated, [])
})

it('triggers elements with capitalised key', function() {
setHTML('<button id="button1" data-hotkey="B">Button 1</button>')
document.dispatchEvent(new KeyboardEvent('keydown', {shiftKey: true, key: 'B'}))
assert.include(elementsActivated, 'button1')
})
})

describe('eventToHotkeyString', function() {
Expand Down

0 comments on commit c71a0c6

Please sign in to comment.