Display
List
The display list for read-only content, a server-component ul or ol with item rows that compose Avatar and badges; selection lists are Listbox.
List is a styled <ul> (or <ol> with ordered) for content that is
only displayed. It has no JavaScript behavior and renders in React Server
Components. It lives in @salmonui/layout/list with its own stylesheet.
import { List, ListItem } from '@salmonui/layout/list';
import { Avatar } from '@salmonui/layout/avatar';
import '@salmonui/layout/list/styles.css';
import '@salmonui/layout/avatar/styles.css';
<List aria-label="People">
<ListItem>
<Avatar name="Ada Lovelace" size="sm" shape="circle" />
Ada Lovelace
<span className="salmon-list-item-description">Mathematician</span>
</ListItem>
</List>;
List
Open demoA display List of people with avatars and secondary lines, and an invitations List whose items hold Accept and Decline buttons.
- Ada LovelaceMathematician
- Alan TuringComputer scientist
- Grace HopperRear admiral
- Edsger Dijkstra
- Barbara Liskov
.salmon-list-itemis a wrapping flex row, so anAvatar, the text and a trailing badge or time line up; a child with.salmon-list-item-descriptionwraps onto its own secondary line.- Items are separated by a thin line.
List.Itemis the same component asListItem.
List is for display only. A list the user selects from, checks or navigates with the arrow keys is
Listbox (Listbox), which carries the APG
Listbox keyboard model, selection, virtualization and remote data.
Interactive items
Items may hold controls: buttons inside a ListItem stay in the page's
Tab order, with no roving focus to learn.
import { Button } from '@salmonui/buttons/button';
<List aria-label="Invitations">
<ListItem>
<Avatar name="Ada Lovelace" size="sm" shape="circle" />
Ada Lovelace
<Button size="sm" variant="outline">Accept</Button>
</ListItem>
</List>
Selectable lists
A selectable list is a Listbox from @salmonui/dropdowns/listbox. Its props
cover the list features:
datatakes objects, strings or numbers; a primitive is its own value and label. It can also be an@salmonui/datasource withquery: range reads, abortable.getItemValue,getItemLabelandgetItemGroupread the item fields;getItemIconadds an icon;isItemDisableddisables items reactively.getItemPropssets per-item attributes (title,className,style,data-*).getItemGroupwithrenderGroupHeadergroups items; group headers are sticky when virtualized.renderItem({ item, label, selected, active, disabled })renders each item.value/defaultValue/onValueChange(event.items) hold the selection;multiplewith an arrayvalueselects several items.indicator="checkbox"shows checkboxes, withindicatorPosition: 'start' | 'end'(logical, mirrors in RTL); check items through a controlledvalue,showSelectAllor Ctrl+A.virtualizationrenders only the visible items (fixed item height; on above 100 items);maxVisibleItems,styleandclassNamesize the list.- Loading and errors:
aria-busywithrenderLoading,renderError({ error, retry }),onLoadErrorandrenderEmpty. A remote source loads ranges while scrolling, andonScrollpasses through. - The keyboard follows APG Listbox: arrows, Home / End, Space, Ctrl+A, Shift+arrows and type-ahead.
disableddisables the whole list;className/classNames/styles, the inheriteddirandlocaleTextcover styling, RTL and localization.
import { Listbox } from '@salmonui/dropdowns/listbox';
import '@salmonui/dropdowns/listbox/styles.css';
<Listbox
aria-label="Contacts"
data={contacts}
getItemValue={(c) => c.id}
getItemLabel={(c) => c.name}
getItemGroup={(c) => c.team}
getItemProps={(c) => ({ title: c.email })}
multiple
indicator="checkbox"
value={checked}
onValueChange={setChecked}
/>
ListView as Listbox
Open demoA grouped, checkable contact list with item templates, tooltips and a disabled item, written with Listbox.
Checked: 2
Checkboxes at the inline end are indicatorPosition="end"; the position
is logical, so RTL mirrors it.
Icons, per-item attributes, single selection, a fixed height and the disabled state:
ListView icons, item attributes and single selection
Open demoA folder Listbox with item icons, per-item class, title and data attributes, single selection with a change log, a fixed height in items, a disabled switch and right-to-left.
Folders
Folder:
A remote source read in ranges, with virtualization, loading and error states:
Remote ListView as Listbox
Open demoA virtualized Listbox over 2,000 tickets read in ranges from a remote source with latency, a base query filter, a loading spinner, and an error state with Retry.
Tickets (2,000 on the server)
Selected:
The Listbox keyboard model, selection events and every other prop are on the Listbox page.
Not included
These behaviors are left to the application on purpose, because the data belongs to the application and React owns the lifecycle.
Hiding items. Pass a filtered array:
data={items.filter((item) => item.visible)}.
Adding, removing and finding items. There are no item
mutation methods. Keep items in state, update them with setItems(...),
and look items up in that array.
Header. There is no built-in header. Render a heading and connect it:
<h2 id="contacts">Contacts</h2>
<Listbox aria-labelledby="contacts" data={contacts} />
Sorting. There is no sort option; sort once where the data
lives: data.toSorted(byName), or query={{ sorting: [{ columnId: 'name', direction: 'asc' }] }} on a remote source.
Nested lists. Drill-down navigation through child lists is a
mobile navigation pattern rather than a list behavior. Use
TreeView for hierarchical selection, or keep a
path state, render the current level in a Listbox, and add your own back
button.
Nested-list animation. With no nested navigation, there is no slide animation to configure.
Item height refresh. The virtual list uses one fixed item
height, so there is no per-item height to refresh. Set
virtualization={false} for lists whose items differ in height.
HTML encoding. Content is ReactNode and HTML strings are
never parsed, so there is nothing to encode or sanitize. Write JSX in
renderItem.
Persistence. There is no built-in persistence: localStorage
is not readable on the server, so a persisted selection would cause a
hydration mismatch. Save value in onValueChange and pass it back as a
controlled prop.
Lifecycle. A React component unmounts with the tree, so there is no destroy method: use conditional rendering, and put setup code in an effect or a ref callback.
API reference: @salmonui/layout/list and
@salmonui/dropdowns/listbox.
The JavaScript is 0.30 KB gzip and the stylesheet 0.32 KB.