@gridui/interaction
v1.3.1
Published
Cancelable interaction change details
Readme
Interaction
@gridui/interaction owns the React-free cancelable change notification shared
by choice controls. It has no component, stylesheet, or theme dependency.
changeDetails(event) returns ChangeDetails: the original event, a live
isCanceled flag, and an idempotent cancel() function. Each notification has
independent cancellation state. The emitting control decides when to inspect
that state and whether to commit its proposed change.
Release history
Package-owned records live in .changeset/history.
closesNavigation(event, target, download) identifies uncancelled primary
activation in the same browsing context, preserving modifier keys and downloads.
isSameDocumentAnchor(href, current) compares origin, pathname, search and a
nonempty fragment so overlay compositions can preserve native anchor focus.
Both helpers accept browser-independent values and own no routing policy.
getNavigationActivation(event) reads the current native anchor, including the
document's base target and download attribute. It returns anchor, document,
or null for an activation that should not dismiss navigation. Callers own
navigation state and focus restoration. Sidebar and SiteNavigation share this
DOM adapter as well as the pure link predicates.
isComposingKeyEvent(event) recognizes native keyboard events owned by an IME,
including the processing-key fallback used by some input methods. Pass a React
keyboard event's nativeEvent. Check it before treating Enter, Escape, or arrow
keys as commands; keep any existing composition lifecycle tracking.
listenForDragCancellation(element, onCancel) observes Escape and window blur
only for the lifetime of an active pointer drag. It listens to the element's
owning window; Escape is claimed during window capture, before an enclosing
Radix overlay's document-capture dismissal. IME processing and already handled
Escape events are left alone. The returned cleanup function is idempotent.
Call cleanup when a drag completes, is canceled, or its owner unmounts. The callback owns rollback, pointer-capture release and any controlled-state notification; this helper owns no geometry, persistence, or React lifecycle.
Searchable lists
calculateSearchList(items, options) supplies shared result availability,
active-item fallback and clamped next/previous/first/last navigation.
Provide a stable string key, current highlighted key, optional preferred
predicate and optional isNavigable predicate. Disabled commands can remain
visible while being excluded from navigation; selection controls choose their
own disabled-item policy. The input records and their order remain unchanged.
searchResultsAvailable({ loading, errorLabel }) rejects loading results and any
defined error label, including an empty string. getSearchResultLabel(count,
options) applies the same loading/error/empty/results status priority.
Select and CommandPalette share these mechanisms while owning text matching,
grouping, query lifecycle, ARIA identities, selection and popup focus themselves.
