SearchCtrlK

  • ↑↓navigate
  • ↵open
  • escclose

Can’t find it? Contact us

SelectionModel

Selection state for list-shaped widgets.

tsx
import { SelectionModel } from "@sdxc/ui/app";

Usage

State model for list, grid, tree, and table row selection. Every mutating method dispatches a plain "change" event exactly once, and only when the selected-key set really changes, so a subscriber can re-render blindly.

Signature

typescript
new SelectionModel(options?: SelectionModel.Options)

Parameters

ParameterTypeDefaultRequiredDescription
optionsSelectionModel.Options—NoInitial mode, known key order, disabled keys, and pre-selected keys. All are optional and default to an empty, "multiple"-mode model with no known keys.

Properties

PropertyTypeDefaultRequiredDescription
modeSelectionModel.Mode—YesCurrent selection cardinality.
keysreadonly SelectionModel.Key[]—YesKnown selectable keys, in the order last provided to the constructor or setKeys.
selectedKeysReadonlySet<SelectionModel.Key>—YesCurrently selected keys.
disabledKeysReadonlySet<SelectionModel.Key>—YesKeys excluded from selection.
anchorKeySelectionModel.Key | null—YesKey that anchors the next selectRange call, or null before any point interaction.
sizenumber—YesNumber of currently selected keys.
isEmptyboolean—Yestrue when no key is selected.
isAllboolean—Yestrue when every non-disabled key in keys is selected. Always false when keys is empty, since there is nothing to select.

Methods

MethodDescription
setMode(mode: SelectionModel.Mode): voidReplaces the selection mode. The current selection clamps to it ("none" empties it, "single" keeps at most the first selected key), dispatching "change" when that clamp shrinks the selected-key set.
setKeys(keys: Iterable<SelectionModel.Key>): voidReplaces the known universe of selectable keys, in order. Selected and anchor keys no longer present in keys are dropped, so removing a rendered row also removes it from the selection.
setDisabledKeys(keys: Iterable<SelectionModel.Key>): voidReplaces the set of keys excluded from selection. Any of those keys currently selected are dropped from the selection.
isSelected(key: SelectionModel.Key): booleanReports whether key is currently selected.
isDisabled(key: SelectionModel.Key): booleanReports whether key is excluded from selection.
select(key: SelectionModel.Key): voidSelects key, replacing the selection in "single" mode or adding to it in "multiple" mode. No-op for a disabled key or in "none" mode. Sets anchorKey to key on success.
deselect(key: SelectionModel.Key): voidRemoves key from the selection, regardless of mode. Sets anchorKey to key when it was selected; no-op otherwise.
toggle(key: SelectionModel.Key): voidFlips whether key is selected, replacing the selection in "single" mode and staying a no-op for a disabled key or in "none" mode. Sets anchorKey on success; a plain click maps to this operation.
selectRange(key: SelectionModel.Key): voidSelects the contiguous span between anchorKey and key in keys order, skipping disabled keys; the anchor stays put so repeated shift-clicks re-span. Anchorless calls run toggle.
selectAll(): voidSelects every non-disabled key in keys. No-op outside "multiple" mode or when keys is empty.
clear(): voidDeselects every key, regardless of mode.

The events, constants and types its module publishes, each imported from @sdxc/ui/app too.

Interface

SelectionModel.Options

Constructor options for SelectionModel.

MemberTypeDefaultRequiredDescription
modeMode—NoSelection cardinality; defaults to "multiple".
keysIterable<Key>—NoOrdered universe of selectable keys, backing SelectionModel.selectRange spans and the full set for SelectionModel.selectAll. Point selection works without it.
disabledKeysIterable<Key>—NoKeys excluded from selection; any of them present in selectedKeys are dropped.
selectedKeysIterable<Key>—NoKeys selected on construction, clamped to mode and disabledKeys.
Type

SelectionModel.Key

Identifier for a selectable item. Row/item identity is left to the consumer — a string slug and a numeric row id are both valid keys.

typescript
type SelectionModel.Key = string | number
Type

SelectionModel.Mode

Selection cardinality a model enforces: "none" accepts no selection at all, "single" keeps at most one selected key, and "multiple" allows any subset of the known keys.

typescript
type SelectionModel.Mode = "none" | "single" | "multiple"
@sdxc/ui

Can’t find it? Contact us