View as Markdown

API reference: @salmonui/dropdowns/listbox

ListboxSinglePropsinterface

import type { ListboxSingleProps } from '@salmonui/dropdowns/listbox';
interface ListboxSingleProps<T> extends ListboxBaseProps<T> {
    readonly multiple?: false;
    readonly value?: ListboxKey | null;
    readonly defaultValue?: ListboxKey | null;
    readonly onValueChange?: (value: ListboxKey | null, event: ListboxValueChangeEvent<T>) => void;
}

Single selection (default).

ListboxSingleProps members (55, 51 inherited)
NameSignatureDescription
multipleoptionalreadonly multiple?: false;
valueoptionalreadonly value?: ListboxKey | null;
defaultValueoptionalreadonly defaultValue?: ListboxKey | null;
onValueChangeoptionalreadonly onValueChange?: (value: ListboxKey | null, event: ListboxValueChangeEvent<T>) => void;
datainheriteddata: ListboxDataSource<T> | readonly T[];

Items (an array, never copied), or a remote @salmonui/data source.

getItemValueoptionalinheritedgetItemValue?: ((item: T) => ListboxKey);

Default: a primitive is its own value; objects read value. Keep accessors stable (module scope or useCallback).

getItemLabeloptionalinheritedgetItemLabel?: ((item: T) => string);

Default: a primitive is its own label; objects read label.

getItemGroupoptionalinheritedgetItemGroup?: ((item: T) => string | null | undefined);

Default: objects read group. Items of one group must be contiguous.

getItemIconoptionalinheritedgetItemIcon?: ((item: T) => ReactNode);
isItemDisabledoptionalinheritedisItemDisabled?: ((item: T) => boolean);

Default: objects read disabled. Evaluated on render (reactive).

layoutoptionalinheritedlayout?: "grid" | "list";

'grid': the APG Grid pattern (role="grid", rows of columns cells) for items holding their own controls, and tile galleries. Tab and the arrow keys reach the active cell's controls; selection does not follow focus. No group headers or reordering. Default 'list'.

columnsoptionalinheritedcolumns?: number;

Items per row with layout="grid". Default 1.

indicatoroptionalinheritedindicator?: "check" | "checkbox";

Marker of selected options. Default 'check'.

indicatorPositionoptionalinheritedindicatorPosition?: "end" | "start";

Side of the marker: 'start' (default) or 'end', logical so it mirrors in RTL.

showSelectAlloptionalinheritedshowSelectAll?: boolean;

Tri-state "select all" checkbox above the list (multiple).

maxSelectedoptionalinheritedmaxSelected?: number;

Most values multiple may hold; further options become unavailable.

searchableoptionalinheritedsearchable?: boolean;

A search field above the list filters it.

searchOperatoroptionalinheritedsearchOperator?: ListboxSearchOperator<T>;

Default 'startsWith'.

matchCaseoptionalinheritedmatchCase?: boolean;
ignoreAccentsoptionalinheritedignoreAccents?: boolean;
searchPlaceholderoptionalinheritedsearchPlaceholder?: string;
onSearchChangeoptionalinheritedonSearchChange?: ((event: { readonly text: string; }) => void);

Fires when the search text changes.

debounceoptionalinheriteddebounce?: number;

Remote search debounce in ms. Default 300; local data filters on every keystroke.

minSearchLengthoptionalinheritedminSearchLength?: number;

Remote: searches shorter than this send no request.

maxResultsoptionalinheritedmaxResults?: number;

Caps the number of listed items.

queryoptionalinheritedquery?: ListboxQuery;

Remote: base filters and sort merged into every read.

searchFieldsoptionalinheritedsearchFields?: readonly string[];

Remote: fields the search text runs over. Default ['label'].

virtualizationoptionalinheritedvirtualization?: boolean;

Virtual list (fixed item height). Default: on above 100 items.

maxVisibleItemsoptionalinheritedmaxVisibleItems?: number;

List height in items. Default 8.

highlightMatchesoptionalinheritedhighlightMatches?: boolean;

Mark the search text in labels (<mark>).

renderItemoptionalinheritedrenderItem?: ((state: ListboxItemState<T>) => ReactNode);
renderGroupHeaderoptionalinheritedrenderGroupHeader?: ((state: { readonly group: string; }) => ReactNode);
renderEmptyoptionalinheritedrenderEmpty?: ((state: { readonly reason: "noData" | "noMatch"; }) => ReactNode);
renderErroroptionalinheritedrenderError?: ((state: { readonly error: unknown; readonly retry: () => void; }) => ReactNode);
renderLoadingoptionalinheritedrenderLoading?: (() => ReactNode);
getItemPropsoptionalinheritedgetItemProps?: ((item: T, state: { readonly selected: boolean; readonly disabled: boolean; }) => ListboxItemProps | undefined);
onLoadErroroptionalinheritedonLoadError?: ((error: unknown) => void);

Remote: called when a read fails.

loadingoptionalinheritedloading?: boolean;

Forces the busy state (aria-busy); set automatically while a remote read is pending.

nameoptionalinheritedname?: string;

Form field name: renders a hidden native <select> that submits the value.

requiredoptionalinheritedrequired?: boolean;
formoptionalinheritedform?: string;
disabledoptionalinheriteddisabled?: boolean;
readOnlyoptionalinheritedreadOnly?: boolean;
reorderableoptionalinheritedreorderable?: boolean;

Alt+Up / Alt+Down and drag within the list fire onReorder.

onReorderoptionalinheritedonReorder?: ((event: ListboxReorderEvent<T>) => void);
dragGroupoptionalinheriteddragGroup?: string;

Lists with the same group accept each other's items by drag and drop.

onItemDragStartoptionalinheritedonItemDragStart?: ((event: ListboxDragStartEvent<T>) => void);
onItemDragoptionalinheritedonItemDrag?: ((event: ListboxDragEvent) => void);
onItemDropoptionalinheritedonItemDrop?: ((event: ListboxDropEvent<T>) => void);
localeTextoptionalinheritedlocaleText?: Partial<ListboxLocaleText>;
classNameoptionalinheritedclassName?: string;
styleoptionalinheritedstyle?: CSSProperties;
classNamesoptionalinheritedclassNames?: Partial<Record<ListboxPart, string>>;
stylesoptionalinheritedstyles?: Partial<Record<ListboxPart, CSSProperties>>;
refoptionalinheritedref?: Ref<HTMLDivElement>;

The focusable role="listbox" (or role="grid" with layout="grid") element.