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:
commit
2b14a268c1
@ -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':
|
||||
|
@ -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(
|
||||
|
Loading…
Reference in New Issue
Block a user