Skip to content
On this page

useFocusWithin

监听当前焦点是否在某个区域之内,同 css 属性 :focus-within

代码演示

API

const isFocusWithin = useFocusWithin(target, {
  onFocus,
  onBlur,
  onChange,
})
const isFocusWithin = useFocusWithin(target, {
  onFocus,
  onBlur,
  onChange,
})

Params

参数说明类型默认值
targetDOM 节点或者 Ref 对象() => Element | Element | JSX.Element-
options额外的配置项Options-

Options

参数说明类型默认值
onFocus获取焦点时触发(e: FocusEvent) => void-
onBlur失去焦点时触发(e: FocusEvent) => void-
onChange焦点变化时触发(isFocusWithin: boolean) => void-

Result

参数说明类型
isFocusWithin焦点是否在当前区域Ref<boolean>

Source

源码文档示例