Renamed hoverable -> focusable

This commit is contained in:
Vadim
2021-04-20 22:41:07 +03:00
parent 55335dbb48
commit cc82fcf44f
5 changed files with 54 additions and 42 deletions

View File

@@ -0,0 +1,29 @@
import { createDispatcher } from '../../utils/event'
import {
addFocusinEventListener,
removeFocusinEventListener,
addFocusoutEventListener,
removeFocusoutEventListener,
} from './event'
export function focusable(node) {
const dispatch = createDispatcher(node)
function handleFocusin() {
dispatch('focused', { value: true })
}
function handleFocusout() {
dispatch('focused', { value: false })
}
addFocusinEventListener(node, handleFocusin)
addFocusoutEventListener(node, handleFocusout)
return {
destroy() {
removeFocusinEventListener(node, handleFocusin)
removeFocusoutEventListener(node, handleFocusout)
},
}
}