mirror of
https://github.com/jxnblk/mdx-deck.git
synced 2024-11-29 13:58:02 +03:00
Add ability to ignore key events
This commit is contained in:
parent
1b0302419b
commit
f7e3220b26
@ -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