OList
OList renders an array of items as an accessible native list, with one scoped slot for the item content and optional built-in pagination.
Usage
Step by step
- Import
OListfrom theooko-ui/listpublic subpath. - Pass the array to
itemsand render each item in the default slot, which receivesitemand itsindex. Name the list witharia-labeloraria-labelledby. - Set
pageSizeto paginate the items locally. Bindv-model:pageonly when the page must be read or restored; the list otherwise keeps its own page.
Example
The rendered example and its source come from the same Vue single-file component.
- Draft the release notes
- Review the pull request
- Update the changelog
Interactive playground
Change the number of items, toggle pagination, and edit the page size to see the list and its pagination update. Set the item count to zero to show the empty slot.
- Item 1
- Item 2
- Item 3
Props
| Prop | Type | Default | Description |
|---|---|---|---|
items | readonly T[] | undefined | Items to render, one list item each. |
getItemKey | ((item: T, index: number) => PropertyKey) | undefined | Returns a stable, unique key for an item; the item index is used when omitted. |
pageSize | number | undefined | Number of items per page; shows the built-in pagination when the items exceed one page. |
page | number | undefined | Current page, starting at one; the list keeps its own page when omitted. |
Events
| Event | Payload | Description |
|---|---|---|
update:page | number | Requests a new current page. |
Slots
| Slot | Props | Description |
|---|---|---|
default | { /** Item being rendered. */ item: T; /** Index of the item in items, across pages. */ index: number; } | Renders the content of one list item. |
empty | none | Content displayed instead of the list when items is empty. |
CSS custom properties
| Custom property | Default | Description |
|---|---|---|
--o-list-item-padding | var(--o-space-2) var(--o-space-3) | Sets the padding inside each list item. |
--o-list-divider | 1px solid var(--o-border-color-subtle) | Sets the border shorthand drawn between list items. |
Override example
css
:root {
--o-list-item-padding: var(--o-space-3) var(--o-space-4);
--o-list-divider: 0;
}Define the same custom properties on a container instead of :root to limit an override to one part of an application.
Accessibility
- Items render as
lielements inside a nativeul. Theulrestatesrole="list"because Safari drops list semantics from lists without bullets. - Every attribute except
classandstyleis forwarded to theul, soaria-label,aria-labelledby, andidname and identify the list itself.classandstylestay on the root wrapper. - The built-in pagination is an
OPaginationnavigation placed after the list, with its accessible name, keyboard behavior, and polite page status. Focus stays on the pagination control after a page change. - The empty slot replaces the list, so assistive technologies do not announce an empty list.
- Items are not interactive by themselves. Put native links or buttons in the slot when an item triggers an action.
Behavior and edge cases
- Without
pageSize, every item renders and no pagination is shown. WithpageSize, the pagination appears only when the items exceed one page. - A
pageSizebelow one or not finite disables pagination. Apageoutside the available pages is clamped, without emittingupdate:page, for example afteritemsshrinks. pageis optional: when bound, the list shows that page and emitsupdate:pageon requests; when omitted, the list stores the page itself.- The slot
indexis the item's index initems, across pages. Items are keyed by that index unlessgetItemKeyreturns a stable key, which is recommended when items can be reordered, inserted, or removed. - For server-side pages, pass only the current page to
items, leavepageSizeunset, and place anOPaginationbound to the server page next to the list. - The built-in pagination uses the compact
OPaginationpreset unless an app default selects another preset.OListitself exposes no app defaults. - Without an empty slot, an empty
itemsarray renders an empty list.