useFocusWithin
Monitor whether the current focus is within a certain area, Same as css attribute [:focus-within](https://developer.mozilla.org/en-US/docs/Web/CSS/:focus-within).
Overview
Monitor whether the current focus is within a certain area, Same as css attribute :focus-within.
Installation
Open inpnpm dlx shadcn@latest add https://shadcn-ahooks.vercel.app/r/useFocusWithin.jsonnpx shadcn@latest add https://shadcn-ahooks.vercel.app/r/useFocusWithin.jsonyarn shadcn@latest add https://shadcn-ahooks.vercel.app/r/useFocusWithin.jsonbun shadcn@latest add https://shadcn-ahooks.vercel.app/r/useFocusWithin.jsonMonitor whether the current focus is within a certain area, Same as css attribute :focus-within.
Examples
Default usage
Pass in DOM element
API
const isFocusWithin = useFocusWithin(
target,
{
onFocus,
onBlur,
onChange
}
);Params
| Property | Description | Type | Default |
| -- | | | - | --- |
| isFocusWithin | Whether the focus is in the current area | boolean |