Prevent tab-event closing the chart range settings
This commit is contained in:
@@ -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)
|
||||
}
|
||||
Reference in New Issue
Block a user