Focus, selection, popups and the other pieces your components are made of.

Browse the helpers by topic. Each name links to its guide and examples.

Import helpers from @ui-sdk/core unless a different entrypoint is shown.

Focus and Keys

HelperWhat It Does
createRovingFocusGives a group one Tab stop and moves focus with the arrow keys.
createGridFocusMoves focus by row and column, including cells that aren't rendered yet.
byCellUpdates only the cell focus leaves and the cell it lands on.
spatialMoveChooses the next item from its position on screen.
nearestInDirectionFinds the nearest item in a direction without moving focus.
createTypeaheadFinds an item as someone types its name.
createFocusRecoveryRestores focus when the focused item is removed.
keepFocusPreserves focus through a change that moves an element.
inputHintsPicks the on-screen keyboard and autofill for a kind of field.

Text

HelperWhat It Does
createInputHistoryBrings back earlier entries with ArrowUp and ArrowDown, like a terminal.
isTypeaheadKeyChecks whether a key can be used for typeahead.
labelOfReads an element's label for matching typed text.
isComposingChecks whether an input event is part of text that's still being composed.
pageLocaleReads the language of the page, or of one section of it.
userLocaleReads the browser's preferred language.
toLocaleTurns a tag like en_US into one that Intl accepts.

Search Matching

Import these helpers from @ui-sdk/core/text-match.

HelperWhat It Does
fuzzyScoreScores how well a piece of text matches what someone typed.
matchRangesFinds where the typed text appears in a piece of text.
matchSegmentsSplits text into matched and unmatched pieces you can render.

Selection

HelperWhat It Does
createSelectionTracks selected items, including multiple selections and ranges.
createLassoSelects items touched by a rectangle drawn with the pointer.
createCellRangeSelects a rectangular range of grid cells.
byCellRangeUpdates only the cells that join or leave a range.
cellRangeMessageProvides the default announcements for a range of cells.
cellsToTextConverts cell values to text for copying.
textToCellsParses pasted text into rows of cell values.

Drag and Drop

HelperWhat It Does
bindDragTracks a pointer drag with capture, thresholds, and cancellation.
dragThresholdSets the standard drag threshold to 3 pixels.
createReorderReorders a list or grid with the pointer or keyboard.
createTreeReorderReorders and nests tree items with their descendants.
createTransferMoves items within or between lists.
bindDragPreviewShows a copy of the dragged element above the page.
createAutoScrollScrolls a container when a drag approaches its edge.
settleDraftKeeps a draft visible while a controlled value catches up.
reorderMessageProvides the default announcements for reordering a list.
subtreeEndFinds the first row index after a subtree.
treeReorderMessageProvides the default announcements for reordering a tree.
transferMessageProvides the default announcements for moving items between lists.

Dragging and Resizing

HelperWhat It Does
createMoveMoves freely positioned objects with the pointer or keyboard.
createResizeResizes boxes from their edges and corners.
createSwipeActionsReveals actions behind a row and supports full-swipe actions.
bindHoldRuns an action once a press is held, and can repeat it while held.
bindRepeatSteps once when a button is pressed, and keeps stepping while held.
createAreaPicks a value along two axes, such as a point on a pad.
createSpansDraws, moves, and resizes ranges on tracks.
stackSpansPlaces overlapping ranges in separate lanes.
createPreviewTracks a value being tried before it is chosen.
moveMessageProvides the default announcements for changes in position.
resizeMessageProvides the default announcements for resizing boxes.
isSpanFreeChecks whether a proposed range overlaps another on its track.
spansMessageProvides the default announcements for changes to ranges.

Lists

HelperWhat It Does
createListboxHighlights options with the arrow keys, and filters them as someone types.
createVirtualizerCalculates which rows to render and where to place them.
createStickToBottomFollows new content while preserving the reader's place when they scroll up.
bindScrollPickerPicks the option at the center of a scrolling list, like a wheel.
createInlineEditManages editing, committing, and canceling a value in place.

Trees

HelperWhat It Does
createTreeCollectionLooks up parents, children, levels, and visible nodes.
treeDataNodesConverts nested items into nodes for a tree collection.
treeFromPathsBuilds nested tree data from file paths.
visibleTreeRowsFlattens open branches into rows with parent, level, and index data.
treeCheckedStatesCalculates checked, unchecked, and mixed states across a tree.
toggleTreeCheckedReturns the next checked value when a node is toggled.

Transitions and Gestures

HelperWhat It Does
bindPanelCoordinates panel height, transitions, and focus when opening or closing.
hiddenAttrsSets visibility attributes for hidden or searchable content.
bindFindableReveals hidden content when the browser finds a match.
supportsHiddenUntilFoundChecks whether the browser can search hidden content.
animateInApplies the starting state for a CSS entrance animation.
animateOutApplies the exit state and calls your completion callback after animations finish.

Gesture Calculations

Import these helpers from @ui-sdk/core/gesture.

HelperWhat It Does
createVelocityTrackerMeasures velocity from recent pointer positions.
projectDistanceEstimates how far a moving value will travel as it slows down.
solveSpringCalculates a spring's position and velocity over time.
rubberBandAdds resistance as a value moves past an edge.
sectorOfConverts a stroke's direction into a sector, such as a radial menu item.

Popups and Layers

HelperWhat It Does
createPopupManages opening, closing, positioning, and focus using a popup preset.
popupStateCreates the initial open, mounted, and payload state.
popupTriggerBuilds a trigger slot that opens and closes the popup.
popupContentBuilds a content slot with presence, placement, and focus handling.
popupCloseBuilds a slot that closes the popup.
popupTitleConnects a visible title to the popup's accessible name.
popupDescriptionConnects descriptive text to the popup.
popupArrowBuilds an arrow slot that follows the popup's placement.
popupBackdropBuilds a backdrop slot behind a modal popup.
popupViewportBuilds a full-screen container slot for a popup sheet.
popupSlotsBuilds the standard popup parts together.
positionPlaces an element beside an anchor and updates its placement.
bindLayerRegisters a floating element for Escape and outside-press dismissal.
bindPersistentLayerKeeps an element usable across layers, including modal popups.
isDismissalIdentifies a dismissal reason, such as Escape or an outside press.
supportsTopLayerChecks whether the browser supports the top layer used by popups.

Popup presets choose the interaction for a popover, dialog, tooltip, or hover card. Popup controllers open existing popup components from code and wait for a result. Import each from its component entrypoint, such as @ui-sdk/core/popover.

Preferences

HelperWhat It Does
createPreferenceHolds a choice from a list, notifies subscribers, and can save it between visits.
createColorSchemeBuilds on a preference to choose light, dark, or the browser's scheme.
colorSchemeOfReads the color scheme a browser sends with a request.
preferencesScriptPuts saved preferences on their attributes before the first paint.
createPointerKindReports whether the main pointer is a finger or a mouse, and whether it can hover.
pointerKindOfGuesses the pointer kind from a request's headers.

Storage

HelperWhat It Does
createLocalStorageKeeps a value in localStorage, for every tab, until it's removed.
createSessionStorageKeeps a value in sessionStorage, for the tab, while it's open.
createCookieStorageKeeps a value in a cookie, which the server reads too.

Canvas

HelperWhat It Does
createViewportPans and zooms a canvas and converts between screen and canvas coordinates.
createConnectTracks connections between ports with the pointer or keyboard.
connectMessageProvides the default announcements for connection steps.

Platform

HelperWhat It Does
announceReads a message out to screen readers.
prepareAnnouncementsAdds the regions screen readers listen to before the first message.
isRTLChecks whether an element's text runs right to left.
matchesShortcutChecks whether a key press matches a shortcut, such as mod+b.
formatShortcutWrites a shortcut the way the user's platform shows it.
ariaKeyshortcutsWrites a shortcut as an aria-keyshortcuts value.

Mobile

HelperWhat It Does
bindViewportFollows the visible viewport and reports each change.
bindAvoidKeyboardLifts an element above the on-screen keyboard.

Changes and History

HelperWhat It Does
createChangeAsks to change a state value, calling its callback first.
createCommitReports the final value when an interaction ends.
dispatchCalls an action's callback, such as onDelete, and tells you if it was canceled.
createUndoStackKeeps snapshots of a value you record, so you can undo and redo.
createControllerLets code outside a component call its methods.
sourceOfTells whether an event came from a mouse, touch, pen, keyboard, or code.
isFocusFromKeyboardChecks whether focus just arrived from the keyboard.

Watching Changes

Import these helpers from @ui-sdk/core/observe.

HelperWhat It Does
observeCalls you with every change to the components on a page.
elementOfFinds the element of the component a change came from.
withSourceKeeps a change's source across an await.

Building Blocks

HelperWhat It Does
definePrimitiveDefines a component's options, state, and parts once for every framework.
idPartEscapes an item value so it can be part of an id.
elementsReturns a component's bound parts in page order.
openAttrsReturns the usual attributes for an open or closed part.
checkedAttrsReturns the usual attributes for a checked, unchecked, or mixed part.
cssTurns style declarations into a style attribute and skips empty values.
liveWrites attributes for state that changes often, without rendering again.
selectsTells each part which state changes it needs to hear about.
directKeeps chosen attributes current between renders.

Agents

Import these helpers from @ui-sdk/core/agent.

HelperWhat It Does
createAgentLets an agent read the components on a page and use them.
agentToolsDescribes the snapshot, act, and query tools for your model.
registerToolsOffers the same tools to an agent built into the browser.

History

Import these helpers from @ui-sdk/core/history.

HelperWhat It Does
createHistoryRecords every change to the page's components and who made it, so you can step back or undo one source.
describeEntryWrites a short sentence for a history entry.
stageChangesTries a set of values on the real controls and lets you put the old ones back.

Values and Testing

Number, Date, Color, and Image cover formatting, parsing, and math for each kind of value. Each has its own entrypoint, such as @ui-sdk/core/number. Testing covers the checks for a component of your own.