diff --git a/src/index.js b/src/index.js index cf022b6..1a46fdd 100644 --- a/src/index.js +++ b/src/index.js @@ -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': diff --git a/test/index.js b/test/index.js index c3ab83e..11f7aed 100644 --- a/test/index.js +++ b/test/index.js @@ -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( + 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(