hono-preact
Overview
Quick Start
The Route Table
Layouts & Nesting
Adding Pages
Active Links
Server Loaders
Loading States
Reloading Data
Prefetching
Streaming
Live Loaders
Realtime Channels
Server Actions
Validation
Optimistic UI
View Transitions
Middleware
CSRF Protection
CLI
Vite Config
Project Structure
Composing Hono Middleware
WebSockets
Rooms & Presence
renderPage
Link Prefetch
Build & Deploy
Overview
Dialog
Popover
Tooltip
Menu
Context Menu
Select
Combobox
Toast
renderElement
useControllableState
mergeRefs
useListNavigation
useTypeahead
useListboxSelection
usePosition
usePositioner
useDismiss
useFocusReturn
useSafeArea
usePresence

useListboxSelection#

useListboxSelection is the selection core shared by Select and Combobox. It owns single- and multi-select value tracking, an option registry that resolves display labels in DOM order (so a closed control can show the selected label without rendering its list), and hidden form-field serialization. Reach for it when building a custom listbox-style control that needs the same selection semantics as the built-in components.

See also: useListNavigation, Select, Combobox.

Demo#

  • Apple
  • Banana
  • Cherry
  • Date

selected: (none)

Signature#

import { useListboxSelection } from 'hono-preact-ui';

function useListboxSelection<Value = string>(
  opts: UseListboxSelectionOptions<Value>
): ListboxSelection;

Options#

OptionTypeNotes
valueValue | Value[] | undefinedThe controlled selected value(s).
setValue(next: Value | Value[]) => voidCalled with the next selection: a bare Value in single-select, a Value[] in multi-select.
multiplebooleanWhether multiple options can be selected.
setOpen(open: boolean) => voidCalled to close the control after a single-select choice.
isValueEqual(a: Value, b: Value) => booleanOptional. Custom equality; defaults to Object.is.
serializeValue(value: Value) => stringOptional. Serializes a value for the hidden form field.
itemToString(value: Value) => stringOptional. Resolves a display label when no option is registered for a value.
namestringOptional. Hidden form-field name; enables native form submission.
disabledbooleanOptional. Disables selection.

Result#

MemberTypeNotes
isSelected(optionValue: unknown) => booleanWhether a value is currently selected.
toggle(optionValue: unknown) => voidSelect or deselect a value (closes the control in single-select).
registerOption(id, value, label) => () => voidRegister an option in the label registry; returns a cleanup fn.
selectedLabels() => string[]Selected labels in registry (DOM) order.
selectedItems() => OptionEntry[]Selected options in value order, labels resolved via the registry.
labelFor(value: unknown) => stringResolve a single value's display label.
optionCountnumberNumber of currently-registered options.
hiddenFieldsComponentChild[] | nullHidden <input>s for native form submission, or null.