Primitives / foldkit-primitives/dom

ScrollSettle

const · packages/primitives/src/dom/scroll-settle.ts:25

const ScrollSettle: Mount.MountDefinitionWithArgs<
  'ScrollSettle',
  {
    item: Schema.optional<Schema.String>
    axis: Schema.optional<Schema.Literals<readonly ['inline', 'block']>>
    start: Schema.optional<Schema.Number>
  },
  { readonly _tag: 'ScrollSettled'; readonly index: number }
>

Hears a scroller come to rest, as a Mount: after a swipe, a fling, a trackpad or a scroll a Command made, it reports which of its items starts nearest its own start (inside its scroll-padding), the start being the right edge right to left. A snapping carousel reads it as the slide shown.

At insert it first scrolls, at once, to item start (the Mount's args are read only then, so this is where a redrawn or restored scroller begins), and reports where it lies, since a scroller drawn already at rest sends no scrollend. It listens for scrollend where the browser has it, and otherwise for a scroll that is quiet for SETTLE_QUIET milliseconds.

In the guides