useFocusWithin

Detect when the focus is inside an element or any of its children.

This is custom React hooks, you need to follow the Basic Rules when you use it.

General

The border changes while any input inside has the focus.

APIs

useFocusWithin

const useFocusWithin = <T extends HTMLElement = HTMLElement>(options?: {
  onFocus?: (event: FocusEvent) => void
  onBlur?: (event: FocusEvent) => void
}) => {
  ref: RefObject<T | null>
  focused: boolean
}
Edit this page on GitHub