Primitives / DOM

Mounts for focus

Autofocus() focuses the element on insert, then emits Focused: requested, not landed, since a non-focusable element may decline.

FocusScope({ contain?, restore?, initialFocus? }) keeps focus inside an overlay. On insert the container focuses initialFocus, else its first tabbable descendant, else itself. With contain (default), Tab from the last tabbable wraps to the first, Shift+Tab from the first wraps to the last, and focus that lands outside comes straight back; Tab in the middle is the browser's. On unmount, with restore (default), focus returns to the element that had it, if still in the document. A native <dialog> does all of this itself; this is for a custom overlay, a menu, or a command palette. tabbableWithin(element) is exported: focusable, visible descendants with a non-negative tabindex, in order. Its Behavior form is in interaction.

FollowTabStop moves focus within a container to its roving tab stop when a transition the container did not see moves it or removes the focused row. It never takes focus from outside the container. TreeNavigation uses it.

ScrollLock locks the document's scroll while its element is mounted, refcounted so nested overlays release together, with Foldkit's iOS handling; HideOutside marks everything outside its element inert while mounted, keyed by an id the Mount mints so two overlays restore independently. Both are Foldkit's own Dom.lockScroll and Dom.inertOthers as Mounts. A native <dialog> shown modally needs neither.