Tabbing Functions

reset()

Releases the focus trap, so that every element on the page is reachable by Tab again.

Call it from browser code when the dialog, popup, or menu that set the trap closes, and when its component unmounts while it's open. It has no effect while the page renders on the server.

There's one trap for the whole page, so the method releases it whichever component set it. It does nothing when there's no trap, so calling it twice is safe.

When it releases the trap, the method:

  • Restores the tabindex that each element had before the trap, overwriting any tabindex your code set on it while the trap was on.
  • Leaves focus where it is, so return focus to the element that opened the dialog or menu yourself.
  • Changes the page in the next animation frame, not immediately.

Method Declaration

Copy

Examples


setParentComponents()

Traps keyboard focus in the specified containers, so that Tab and Shift+Tab reach only elements inside them.

Call it when a dialog, popup, or menu opens over the page, so that site visitors using a keyboard can't reach controls hidden behind it.

It takes the following elements outside the containers out of the Tab order: buttons, form fields, iframes, links with an href, and elements with a tabindex. Other focusable elements, such as contenteditable regions, media controls, and anything inside a shadow root, stay reachable.

Call it from browser code, such as an event handler or an effect, once the containers are on the page, because:

  • It has no effect while the page renders on the server.
  • IDs that match no element on the page take all of these elements on the page out of the Tab order, including the ones you meant to keep reachable. An empty array does the same.
  • The page changes in the next animation frame, and the trap covers only the elements on the page at that point.

The method doesn't move focus, so move focus to an element inside a container yourself.

There's one trap for the whole page, so each call replaces the current trap rather than adding to it. To release the trap, call reset().

Method Declaration

Copy

Method Parameters

parentCompIdsstring[]Required

Values of the container elements' id attributes.

Examples

Last updated: 21 October 2026

Did this help?