All files / src/gestures use-focus-gesture.ts

100% Statements 11/11
66.67% Branches 8/12
100% Functions 3/3
100% Lines 9/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 2333x 33x                 33x 14x 4x     14x 2x     14x 14x    
import { AnimationType } from "../render/utils/types"
import { useDomEvent } from "../events/use-dom-event"
import { FeatureProps } from "../motion/features/types"
 
/**
 *
 * @param props
 * @param ref
 * @internal
 */
export function useFocusGesture({ whileFocus, visualElement }: FeatureProps) {
    const onFocus = () => {
        visualElement.animationState?.setActive(AnimationType.Focus, true)
    }
 
    const onBlur = () => {
        visualElement.animationState?.setActive(AnimationType.Focus, false)
    }
 
    useDomEvent(visualElement, "focus", whileFocus ? onFocus : undefined)
    useDomEvent(visualElement, "blur", whileFocus ? onBlur : undefined)
}