Primitives / foldkit-primitives/dom

KeepInView

const · packages/primitives/src/dom/keep-in-view.ts:13

const KeepInView: Mount.MountDefinitionWithArgs<
  'KeepInView',
  { selector: Schema.String },
  never
>

Keeps what is marked in view as a Mount: whenever an element in the mounted one's subtree newly matches selector, such as the row just selected in a list, it is scrolled into view the least amount that shows it (nearest). The element keeps its identity and its focus: nothing is redrawn to move it.

It watches with a MutationObserver for as long as it is mounted, which is as long as the list or canvas that can change what is marked.

In the guides