trapFocusInMountpoint

fun Tag<HTMLElement>.trapFocusInMountpoint(restoreFocus: Boolean = true, setInitialFocus: InitialFocus = TryToSet)

This function enables a so called focus-trap. This enforces the specific behaviour within the receiver Tag, that switching the focus is only possible on elements that are inside the receiver. No other focusable elements outside the enclosing container will get the focus.

This is often useful for components that acts as overlays like modal dialogs or menus.

This variant should be applied, if the trap area is inside a mount-point, thus its removal from the DOM ends the trapping.

Parameters

restoreFocus

sets the focus back to the element that had the focus before the container with the trap was entered.

setInitialFocus

will automatically focus the first element of the container or that one, which has been tagged by setInitialFocus function if the InitialFocus value has focus=true.

See also