trapFocusWhenever

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

This variant of trapFocusInMountpoint allows to reactively trap a focus based on a conditional Flow of Boolean. This should be applied in all situations, where the DOM subtree of the trap is not inside a mount-point, but only activated or disabled by some Flow.

See also

Parameters

condition

some boolean Flow that will enable the trap only on `true` values.

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.