Skip to content

makeSelectionArea

makeSelectionArea turns an element into a box-selection region. Selection starts when the user presses the modifier key(s) and drags inside this element; draggable items that match groups and intersect the box are selected. It must be used inside a DnDProvider.

Signature

ts
makeSelectionArea(ref, options?): { isSelecting, style }
  • ref — template ref to the container element (e.g. the area where selection happens). The element is registered on mount and unregistered on unmount.
  • options — optional config. Omitted options use defaults where applicable.

Returns:

  • isSelectingComputedRef<boolean>. true while this area is the active selection (pointer down + drag with modifier).
  • styleComputedRef<CSSProperties>. CSS for the selection box (position, size). Use it on a div (e.g. overlay) to draw the box; when not selecting, it is {}.

Options

Extends base options:

OptionTypeDescription
disabledboolean | Ref<boolean>When true, this area does not start selection.
groupsstring[] | Ref<string[]>Groups for matching draggables (same group = can be selected).

Selection-area specific:

OptionTypeDescription
modifier{ keys: TModifierKeys | Ref<TModifierKeys>, method: TModifierMethod | Ref<TModifierMethod> }Key(s) that must be held to start selection. Default: { keys: ['ControlLeft'], method: 'every' }.
eventsISelectableAreaEventsCallback when selection ends. See Events.

Events

CallbackDescription
onSelectedCalled when selection ends (pointer up) with the list of selected elements: (selected: HTMLElement[]) => void.

See also

Released under the MIT License.