Renamed hoverable -> focusable
This commit is contained in:
21
src/actions/focusable/event.js
Normal file
21
src/actions/focusable/event.js
Normal file
@@ -0,0 +1,21 @@
|
||||
// focusin event
|
||||
export function addFocusinEventListener(source, cb) {
|
||||
source.addEventListener('mouseenter', cb)
|
||||
source.addEventListener('touchstart', cb)
|
||||
}
|
||||
export function removeFocusinEventListener(source, cb) {
|
||||
source.removeEventListener('mouseenter', cb)
|
||||
source.removeEventListener('touchstart', cb)
|
||||
}
|
||||
|
||||
// focusout event
|
||||
export function addFocusoutEventListener(source, cb) {
|
||||
source.addEventListener('mouseleave', cb)
|
||||
source.addEventListener('touchend', cb)
|
||||
source.addEventListener('touchcancel', cb)
|
||||
}
|
||||
export function removeFocusoutEventListener(source, cb) {
|
||||
source.removeEventListener('mouseleave', cb)
|
||||
source.removeEventListener('touchend', cb)
|
||||
source.removeEventListener('touchcancel', cb)
|
||||
}
|
||||
29
src/actions/focusable/focusable.js
Normal file
29
src/actions/focusable/focusable.js
Normal 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)
|
||||
},
|
||||
}
|
||||
}
|
||||
1
src/actions/focusable/index.js
Normal file
1
src/actions/focusable/index.js
Normal file
@@ -0,0 +1 @@
|
||||
export * from './focusable'
|
||||
Reference in New Issue
Block a user