<FocusTrap> is intended to prevent keyboard users from interacting with elements on the page that a mouse user cannot interact with either. An example of this is <Modal> where the user cannot click the items behind the modal. If you want to shift focus based on UI events, consider using the .focus() method instead.
It is required that when using a <FocusTrap> there is logic using only key presses to escape the focus trap. Otherwise, keyboard users will be blocked after they enter a <FocusTrap>.
Basic example
All the examples have controls to enable / disable the focus trap so that page keyboard navigation isn't blocked.
When enabled, only the children of the <FocusTrap> will be able to receive focus. Otherwise, standard DOM focus order follows.
Include trigger in FocusTrap
The includeTriggerInFocusTrap prop includes the triggering element causing the <FocusTrap> to render as part of the focus order.
Restore focus on unmount
The restoreFocusOnUnmount prop returns focus to the triggering element when the <FocusTrap> is unmounted.