Prevent tab-event closing the chart range settings

This commit is contained in:
Thomas Nordquist
2019-06-24 12:47:22 +02:00
parent b27df0c0d8
commit 005fba5ca3
2 changed files with 37 additions and 54 deletions

View File

@@ -1,31 +0,0 @@
import { KeyCodes } from '../utils/KeyCodes'
import { useCallback } from 'react'
export function useKeyEventHandler(key: KeyCodes, callback: () => void, dependencies: Array<any> = []) {
return useKeyEventHandlers([{ key, callback }], dependencies)
}
export function useKeyEventHandlers(
actions: Array<{
key: KeyCodes
callback: (event: KeyboardEvent) => void
preventDefault?: boolean
stopPropagation?: boolean
}>,
dependencies: Array<any> = []
) {
return useCallback(() => {
return function handleKeyEvent(event: KeyboardEvent) {
const action = actions.find(a => a.key === event.keyCode)
if (action) {
action.callback(event)
if (action.preventDefault !== false) {
event.preventDefault()
}
if (action.stopPropagation !== false) {
event.stopPropagation()
}
}
}
}, dependencies)
}