Enode — API Reference
    Preparing search index...
    • Keeps the keyboard inside an open modal dialog and puts it back afterwards.

      Parameters

      • ref: RefObject<HTMLElement | null>

        The dialog's panel. It needs tabIndex={-1} so it can hold the focus itself.

      • open: boolean

        Whether the dialog is shown (and its panel is on the page).

      • options: ModalFocusOptions = {}

        Where the focus goes first; see ModalFocusOptions.

      Returns void

      While open: the panel takes the focus (or its first field, when asked to), Tab and Shift+Tab stay among the panel's controls, and when the dialog closes the focus returns to the control that opened it — the one that had the focus, or, where that is gone or the browser gave none (Safari, a menu's item), the control pressed just before. Of several open modals only the one opened last answers Tab. When the control that holds the focus leaves the page while the modal stays (a sheet's next step), the panel takes the focus. A focus that has moved out of the panel on purpose (into a menu over it) is not pulled back, and with keepTyping a text field elsewhere that somebody is typing in keeps the focus when the modal opens.