Files
react/packages/react-events/docs/FocusWithin.md
Nicolas Gallagher 474b650cac [react-events] Rename hook exports (#16533)
For example, 'useHoverResponder' becomes 'useHover'
2019-08-22 13:30:35 -07:00

49 lines
1.4 KiB
Markdown

# FocusWithin
The `useFocusWithin` hooks responds to focus and blur events on its child. Focus events
are dispatched for all input types, with the exception of `onFocusVisibleChange`
which is only dispatched when focusing with a keyboard.
Focus events do not propagate between `useFocusWithin` event responders.
```js
// Example
const Button = (props) => {
const [ isFocusWithin, updateFocusWithin ] = useState(false);
const [ isFocusWithinVisible, updateFocusWithinVisible ] = useState(false);
const focusWithin = useFocusWithin({
onFocusWithinChange={updateFocusWithin}
onFocusWithinVisibleChange={updateFocusWithinVisible}
});
return (
<button
children={props.children}
listeners={focusWithin}
style={{
...(isFocusWithin && focusWithinStyles),
...(isFocusWithinVisible && focusWithinVisibleStyles)
}}
>
);
};
```
## Props
### disabled: boolean = false
Disables the responder.
### onFocusWithinChange: boolean => void
Called once the element or a descendant receives focus, and once focus moves
outside of the element.
### onFocusWithinVisibleChange: boolean => void
Called once the element or a descendant is focused following keyboard
navigation, and once focus moves outside of the element. This can be used to
display focus styles only when the keyboard is being used to focus within the
element's subtree.