1
1
mirror of https://github.com/jxnblk/mdx-deck.git synced 2024-12-01 13:32:13 +03:00

Merge pull request #18 from johno/ignore-keys

Add ability to ignore key events
This commit is contained in:
Brent Jackson 2018-07-31 18:01:51 -04:00 committed by GitHub
commit 2b14a268c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 0 deletions

View File

@ -152,6 +152,7 @@ export class SlideDeck extends React.Component {
components: defaultComponents,
width: '100vw',
height: '100vh',
ignoreKeyEvents: false
}
state = {
@ -162,6 +163,10 @@ export class SlideDeck extends React.Component {
update = fn => this.setState(fn)
handleKeyDown = e => {
if (this.props.ignoreKeyEvents) {
return
}
if (e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return
switch (e.key) {
case 'ArrowRight':

View File

@ -451,6 +451,19 @@ describe('components', () => {
expect(root.state.index).toBe(0)
})
test('ignoreKeyEvents does not fire handle events when set to true', () => {
window.history.pushState(null, null, '/#1')
const root = renderIntoDocument(
<SlideDeck ignoreKeyEvents={true} slides={[() => false, () => false]} />
)
const e = new KeyboardEvent('keydown', {
key: 'ArrowLeft'
})
expect(root.state.index).toBe(1)
document.body.dispatchEvent(e)
expect(root.state.index).toBe(1)
})
test.skip('handles hashchange events', () => {
window.history.pushState(null, null, '/')
const root = renderIntoDocument(