@theredhead — Frontend Library - v1.0.0
    Preparing search index...

    Reactive selection model that tracks selected items.

    Exposes read-only signals for the current selection and provides imperative methods to toggle, set, and clear the selection.

    The model uses object-identity (===) to track items. Consumers can optionally supply a trackBy function that maps each item to a stable identity key (e.g. a database ID) — this makes the selection survive data refreshes where the item objects are recreated with new references but represent the same record.

    Type Parameters

    • T = unknown
    Index

    Constructors

    • Type Parameters

      • T = unknown

      Parameters

      Returns SelectionModel<T>

    Properties

    isEmpty: Signal<boolean>

    Whether nothing is selected.

    mode: WritableSignal<SelectionMode>

    The active selection mode.

    selected: Signal<readonly T[]>

    Read-only signal of the currently selected items, in insertion order.

    selectedCount: Signal<number>

    Read-only signal of the number of selected items.

    trackBy: ((item: T) => unknown) | undefined

    Optional function that returns a unique identity key for an item. When provided, selection comparisons use this key instead of ===.

    Methods

    • Clear the entire selection.

      Returns void

    • Deselect a single item.

      Parameters

      • item: T

      Returns void

    • Returns true when every item in the given array is selected. Returns false for empty arrays.

      Parameters

      • items: readonly T[]

      Returns boolean

    • Returns true when at least one — but not all — items are selected. Useful for the "indeterminate" checkbox state.

      Parameters

      • items: readonly T[]

      Returns boolean

    • Returns true if the given item is currently selected.

      Parameters

      • item: T

      Returns boolean

    • Select a single item, replacing any previous selection.

      Parameters

      • item: T

      Returns void

    • Select all items from the provided array. Only meaningful in 'multiple' mode.

      Parameters

      • items: readonly T[]

      Returns void

    • Toggle an item's selection state.

      In single mode, selecting a new item deselects the previous one. In multiple mode, the item is added/removed independently.

      Parameters

      • item: T

      Returns void