@wordpress/compose
Version:
WordPress higher-order components (HOCs).
28 lines (19 loc) • 634 B
Markdown
When opening modals/sidebars/dialogs, the focus must move to the opened area and return to the previously focused element when closed. The current hook implements the returning behavior.
- Type: `Function`
A function reference that must be passed to the DOM element being mounted and which needs to return the focus to its original position when unmounted.
```jsx
import { useFocusReturn } from '@wordpress/compose';
const WithFocusReturn = () => {
const ref = useFocusReturn();
return (
<div ref={ ref }>
<Button />
<Button />
</div>
);
};
```