#49 : Separate handlers for touchable and non toachable devices

This commit is contained in:
Vadim
2021-08-06 22:25:02 +03:00
parent ab3a66e06a
commit b66ab30a0d
7 changed files with 68 additions and 21 deletions

View File

@@ -1,25 +1,31 @@
import { createDispatcher } from '../../utils/event'
import { get } from '../../utils/object'
import {
addFocusinEventListener,
removeFocusinEventListener,
addFocusoutEventListener,
removeFocusoutEventListener,
removeFocusoutEventListener
} from './event'
export function focusable(node) {
const dispatch = createDispatcher(node)
/**
* focusable events are for mouse events only
*/
export function focusable(node, options) {
// pass custom dispatch fn in order to re-translate dispatched event
const dispatch = get(options, 'dispatch', createDispatcher(node))
function handleFocusin() {
addFocusoutEventListener(node, handleFocusout)
dispatch('focused', { value: true })
}
function handleFocusout() {
dispatch('focused', { value: false })
removeFocusoutEventListener(node, handleFocusout)
}
addFocusinEventListener(node, handleFocusin)
addFocusoutEventListener(node, handleFocusout)
return {
destroy() {
removeFocusinEventListener(node, handleFocusin)