List
Alignment target:@astryxdesign/core v0.7.1 · List
Props #
List #
| Name | Type | Default | Description |
|---|---|---|---|
density | ListDensity | 'balanced' | Spacing density for the rows: compact (4px of block padding), balanced (8px), or spacious (12px, which also widens the inline padding by one step). A single row can override it with its own density. |
hasDividers | boolean | false | Whether to rule a line between neighbouring rows. The last row never draws one, and rows lose their rounded corners while dividers are on. |
edge | 'padded' | 'flush' | 'outset' | 'bleed' | 'padded' | Where each row's text, dividers, and hover and selection backgrounds sit relative to the list's edges and the padding of the container around it. padded keeps the row's own inline padding. flush removes it, so text starts on the line of a heading above the list and lines and backgrounds stop at the text. outset keeps text on that line and lets lines and backgrounds reach into the container's padding. bleed puts text on the container's padding line and runs lines and backgrounds to its edges with square corners, like table rows. A row's first content — its marker, icon, or avatar, otherwise its label — is what lines up with the heading. outset and bleed read the padding published by the nearest container that shares it (Card, Section, BottomSheet, a padded ScrollableArea, or a Layout region) and look like padded when there is none. |
edgeCompensation | 'inline' | - | Deprecated: use edge="outset", which this sets. Still works; edge wins when both are set. |
listStyle | ListMarkerStyle | 'none' | The marker drawn in front of each row: none, disc (filled bullet), circle (outlined bullet), or decimal (numbers). decimal renders the list as an <ol>. |
start | number | 1 | The first number of an ordered list, only used when listStyle="decimal". It is written both to the start attribute of the <ol> and to the CSS counter. |
header | string | - | Plain-text title rendered above the list and associated with it through aria-labelledby. Use the header slot for rich content. |
ListItem #
| Name | Type | Default | Description |
|---|---|---|---|
label | string | number | - | The primary text identifying the row. A string or a number truncates to one line; use the label slot for rich content. |
description | string | number | - | Secondary text below the label, also truncated to one line. Use the description slot for multiple lines or rich content. |
density | ItemDensity | - | Overrides the density of the surrounding List. When omitted the row inherits the list's density, or balanced outside a list. |
onClick | (event: MouseEvent) => void | - | Click handler. It renders a button that fills the row's content area and enables the hover and pressed states. Write @click in a template. |
interactiveRef | MaybeRefOrGetter<HTMLElement | null | undefined> | - | A ref to a control inside the row that already carries its keyboard access and action, such as a checkbox in startContent. The row becomes an enlarged click target that forwards surface clicks to that control and renders no button of its own, so it adds no second tab stop. Mutually exclusive with onClick and href, which are ignored while it is set. |
href | string | - | Link URL. A link element is rendered inside the row. |
target | '_blank' | '_self' | - | Where the link opens, only used with href. _blank automatically adds noopener and noreferrer. |
rel | string | - | Link relationship tokens, merged and de-duplicated with the ones added automatically. |
isDisabled | boolean | false | Disabled state. The row becomes inert, its content dims, and aria-disabled="true" is written. A row that carries its own role is left non-inert, because its parent owns the interaction. |
isSelected | boolean | false | Selected state. Written as aria-selected="true" when the role permits it, and as aria-current="true" otherwise. An aria-current you pass yourself wins. |
Item #
| Name | Type | Default | Description |
|---|---|---|---|
as | string | Component | 'div' | The root element. Give a component only when the row carries a role, so the parent keeps keyboard access and the row adds no second tab stop. |
align | 'center' | 'start' | 'center' | Vertical alignment of the start and end content slots. Use start when either end is taller than one line of text. |
labelLines | number | - | Maximum lines before the label truncates. A string label truncates to one line when this is omitted; slot content is never truncated. |
descriptionLines | number | - | Maximum lines before the description truncates. A string description truncates to one line when this is omitted; slot content is left alone in a stacked layout. |
layout | 'stacked' | 'inline' | 'stacked' | How the label and description sit together. inline shares one line and ellipsizes the description first, keeping the row height fixed for hosts such as a trigger. |
isHighlighted | boolean | false | The highlighted appearance, which is what keyboard focus and hover paint. Menu-like components use it for the row they have moved to. |
Item also accepts everything ListItem accepts: label, description, density, onClick, interactiveRef, href, target, rel, isDisabled, and isSelected.
swipeActions are the actions a touch drag reveals. leading opens when the row is dragged toward its end, and trailing opens toward its start. swipeBehavior defaults to reveal, which stays open after release. commit slides out and runs the outermost action once the drag passes the threshold, and that side should hold one action. A mouse drag does not start, so each action also needs a control in the row itself.
Slots #
List #
| Name | Description |
|---|---|
default | The entries of the list, usually ListItem. |
header | Content rendered above the list, associated with it through aria-labelledby. |
ListItem / Item #
| Name | Description |
|---|---|
startContent | Content before the label: an icon, an avatar, or a checkbox. |
label | Rich content replacing the label prop. It is exempt from the automatic truncation. |
description | Rich content replacing the description prop. |
endContent | Content after the label: a badge, a timestamp, or a chevron. |
marker | The marker drawn at the head of the row as a direct child. Item exposes it; ListItem fills it from the list's listStyle. |
Exposed #
| Name | Signature | Description |
|---|---|---|
element | ComputedRef<HTMLUListElement | HTMLOListElement | null> | The list element itself. A list with a header is wrapped, and this is still the list element inside the wrapper. |
ListItem and Item also expose element (the root element), focus(), and blur(); focusing lands on the control inside the row that can actually take focus.
Native attributes #
List #
The root element is a <ul>, or an <ol> when listStyle="decimal". A header adds a wrapper element around it.
The following go to the list element:
- HTML attributes.
aria-*attributes.data-*attributes.class.style.
The component writes role="list", data-density, data-dividers, data-list-style, and data-edge (the resolved padded, flush, outset, or bleed), plus data-edge-compensation while the deprecated prop is set. Without a rendered header an aria-labelledby you pass is kept; with one, the list's own header takes over.
ListItem / Item #
The root element is a <div> by default, and an <li> for ListItem.
The following go to the root element:
- HTML attributes such as
roleandid. aria-*attributes. Anaria-currentyou pass wins over the one derived from the selected state.data-*attributes.class.style.
The component writes data-density, data-align, data-interactive, data-selected, data-disabled, data-highlighted, data-inert, aria-disabled, and the derived aria-selected / aria-current. Those are not overridden by an attribute of the same name passed in.