Primitives / foldkit-primitives/interaction

Presence

namespace · packages/primitives/src/interaction/presence.ts:9

export * as Presence from './presence.js'

Presence as a Behavior: draws a phase the Model already holds. A row that is leaving is inert for the whole exit, so it takes no click, Tab or focus and leaves the accessibility tree, while it stays drawn for its animation. It sends no Message and mounts nothing: the phase and the timed Hidden fact belong to the Presence bundle (foldkit-primitives/motion), and focus leaves the row through FocusRecovery, which observes inert.

In the guides

Members

Presence.behavior

function · packages/primitives/src/interaction/presence.ts:34

function behavior<Slots, Input, ParentMessage>(
  bound: SlotView.Bound<Slots, Input, ParentMessage>,
): (
  options: BehaviorOptions<Slots, Input>,
) => Behavior.NamedBehavior<Slots, Input, ParentMessage>
function behavior<Slots>(
  slots: SlotView.Unbound<Slots>,
): <Input, ParentMessage>(
  options: BehaviorOptions<Slots, Input>,
) => Behavior.NamedBehavior<Slots, Input, ParentMessage>

Draws data-presence with the phase and inert for every phase but shown. It is not aria-hidden, which would leave focus inside, nor hidden, which would end the exit animation. Drawn by the view, so a server render has both: a row that is shown has no inert.

Presence.BehaviorOptions

interface · packages/primitives/src/interaction/presence.ts:18

interface BehaviorOptions<Slots, Input> {
  readonly content: keyof Slots & string
  readonly phase: (input: Input, item: SlotItem | undefined) => Phase
}

Presence.bundle

const · packages/primitives/src/motion/presence.ts:78

const bundle: Bundle.Bundle<
  'Presence',
  { readonly durationMs: number },
  {
    readonly phase: 'hidden' | 'shown' | 'hiding'
    readonly generation: number
  },
  | { readonly _tag: 'Hidden'; readonly generation: number }
  | { readonly _tag: 'Show' }
  | { readonly _tag: 'Hide' },
  never,
  never,
  never,
  NoView,
  {},
  {
    show: (
      model: PresenceModel,
    ) => Readonly<{
      model: {
        readonly phase: 'hidden' | 'shown' | 'hiding'
        readonly generation: number
      }
      commands?: Update.Commands<
        | { readonly _tag: 'Hidden'; readonly generation: number }
        | { readonly _tag: 'Show' }
        | { readonly _tag: 'Hide' },
        never
      >
      outMessage?: never
    }>
    hide: (
      model: PresenceModel,
    ) => Readonly<{
      model: {
        readonly phase: 'hidden' | 'shown' | 'hiding'
        readonly generation: number
      }
      commands?: Update.Commands<
        | { readonly _tag: 'Hidden'; readonly generation: number }
        | { readonly _tag: 'Show' }
        | { readonly _tag: 'Hide' },
        never
      >
      outMessage?: never
    }>
  }
>

Presence as a bundle: mount-transition state for exit animations. Hide starts a timed hiding phase; the Hidden fact it yields carries the generation it was scheduled under, so a Show in between wins and the late fact is ignored. The clock is Effect's, so tests drive it.

Presence.isVisible

function · packages/primitives/src/motion/presence.ts:21

function isVisible(model: PresenceModel): boolean

Whether the content renders: shown or mid-exit.

Presence.Phase

type · packages/primitives/src/interaction/presence.ts:16

type Phase = PresenceModel['phase']

shown, hiding or hidden: what Presence's Model holds in phase.