use-focus-return
Captures last focused element on the page and returns focus to it once given condition is met
Source
Docs
Package
Usage
The use-focus-return hook automatically returns focus to the last focused element when a given condition is met.
For example, it is used in the Modal component to restore focus after the modal was closed.
Close the modal with the Escape key and see how focus returns to the button after the modal closes:
In most cases, you should use this hook with use-focus-trap.
If the shouldReturnFocus option is set to false, you can call the returned function to focus the last active element:
Definition
Exported types
UseFocusReturnOptions and UseFocusReturnReturnValue types are exported from the @mantine/hooks package;
you can import them in your application: