Skip to main content

rc-list

Shared-column list layout with standard and segmented appearances, optional leading and trailing content, and native-backed selection.

Package
@rcarls/rc-list
Element
<rc-list, rc-list-item>
Native dependency
Author-owned radio or checkbox controls in selecting lists
State model
Native checked/disabled state mirrored to list items
Main events
None

Installation

npm install @rcarls/rc-list
import '@rcarls/rc-list/define';

Live demo

Shared columns

rc-list owns leading, content, and trailing grid columns. Each direct rc-list-item participates in them through CSS subgrid, so content stays aligned even when leading visuals or trailing actions have different sizes. If no visible row uses an optional slot, the corresponding column and gap collapse across the whole list.

Mark an icon in the leading slot with data-rc-list-leading when the active theme should apply its standard icon size and alignment. Other leading media such as images, avatars, and selection controls retain their authored geometry.

<rc-list aria-label="Recent recipes">
<rc-list-item>
<span slot="leading" data-rc-list-leading aria-hidden="true"></span>
Apple pie
<span slot="trailing">42 min</span>
</rc-list-item>
</rc-list>

Primary content truncates to one line with an ellipsis by default. Set --rc-list-item-content-white-space: normal on a list or item for deliberate multi-line rows.

Adapt region placement

The shared column sizes and each item's leading, content, and trailing placements are exposed as a coordinated CSS custom-property contract. Use those tokens when a container query should rearrange the same regions without changing source order, focus behavior, or semantics:

.list-region {
container-type: inline-size;
}

@container (max-width: 24rem) {
.list-region rc-list {
--rc-list-trailing-size: 0;
--rc-list-trailing-gap: 0;
--rc-list-item-grid-template-rows: auto auto;
--rc-list-item-row-gap: 0.25rem;
--rc-list-item-leading-grid-row: 1 / -1;
--rc-list-item-content-grid-row: 1;
--rc-list-item-trailing-grid-column: content-start / content-end;
--rc-list-item-trailing-grid-row: 2;
--rc-list-item-trailing-justify-self: start;
}
}

Keep the named leading-*, content-*, and trailing-* column lines in placement values. They are the stable coordination points supplied by rc-list's shared subgrid.

Variants

variant="standard" is the default continuous list. variant="segmented" creates a grouped set of discrete rows; themes use the item position assigned by the list to shape first, middle, last, and only rows.

Native selection

Use selection="single" with one direct radio per item, or selection="multiple" with one direct checkbox per item. The native input is the source of truth for checked, disabled, form, reset, and accessibility behavior. The component mirrors native state to the row and makes the otherwise non-interactive row surface activate its input. Independent links, buttons, inputs, selects, and textareas keep their own behavior. Radios in a single-selection list should share a name, exactly as they would without the custom element enhancement.

<rc-list variant="segmented" selection="single" aria-label="Sort recipes">
<rc-list-item>
<input slot="leading" type="radio" name="sort" value="recent" checked />
Recently updated
</rc-list-item>
<rc-list-item>
<input slot="leading" type="radio" name="sort" value="title" />
Recipe title
</rc-list-item>
</rc-list>

Programmatic writes to selected, disabled, and interactive are silent. In a selecting list, the next native change synchronizes those presentation states from the input again.

Action targets

For a row whose primary action is an anchor or button rather than its selection input, set interactive and point action-target at that same-root native control. A plain primary click on otherwise non-interactive row content invokes the target. Nested links, buttons, form controls, editable content, and modifier-qualified or non-primary clicks retain their own behavior.

<rc-list aria-label="Theme settings">
<rc-list-item interactive action-target="open-theme">
<span slot="leading" aria-hidden="true"></span>
Theme
<button id="open-theme" type="button" slot="trailing">Choose</button>
</rc-list-item>
</rc-list>

The target remains its own keyboard tab stop. Delegation extends pointer reach without creating a second interactive role on the row.

Scope

The package intentionally does not implement drag-and-drop reordering, swipe-to-reveal actions, virtualization, infinite loading, or pull-to-refresh. Those behaviors have distinct data, focus, scrolling, and platform contracts and can compose with list rows when their APIs are defined.

API

Properties

PropertyMarkupTypeDefaultDescription
variantvariantRCListVariant'standard'Appearance hint.
selectionselectionRCListSelection'none'Native selection coordination mode.
roleJS property onlystring'list'No description provided.

Methods

No public methods are documented in the custom elements manifest.

Events

No custom events are documented in the custom elements manifest.

Slots

NameDescription
(default)Direct `rc-list-item` children.

CSS Custom Properties

PropertyDefaultDescription
--rc-list-padding-inline0Shared inline content padding.
--rc-list-padding-block0List block padding.
--rc-list-leading-sizeminmax(0, max-content)Shared leading column size when any visible item has leading content.
--rc-list-leading-gap1remGap after the leading column.
--rc-list-trailing-sizeminmax(0, max-content)Shared trailing column size when any visible item has trailing content.
--rc-list-trailing-gap1remGap before the trailing column.
--rc-list-row-gap0Gap between rows.

CSS Parts

PartDescription
listShared list grid.

Properties

PropertyMarkupTypeDefaultDescription
selectedselectedbooleanfalsePresentational selected state. Host writes are silent.
disableddisabledbooleanfalsePresentational disabled state. Host writes are silent.
interactiveinteractivebooleanfalseEnables row interaction styling.
actionTargetaction-targetstring''ID of a same-root anchor or button that receives forwarded surface clicks — the same contract as `rc-card`'s `action-target`. Checked before the native radio/checkbox fallback, so a row can combine a selection input with its own `action-target` if it ever needs to (uncommon, but not fought against).
roleJS property onlystring'listitem'No description provided.

Methods

No public methods are documented in the custom elements manifest.

Events

No custom events are documented in the custom elements manifest.

Slots

NameDescription
leadingOptional leading visual or native selection control. Add `data-rc-list-leading` when a theme should apply its standard leading-icon geometry.
(default)Primary row content. It truncates to one line by default.
trailingOptional trailing metadata or action.

CSS Custom Properties

PropertyDefaultDescription
--rc-list-item-min-block-size3remMinimum rendered row height.
--rc-list-item-padding-block0.5remRow block padding.
--rc-list-item-colorCanvasTextRow foreground color.
--rc-list-item-backgroundtransparentRow surface color.
--rc-list-item-selected-colorNot specifiedSelected foreground color.
--rc-list-item-selected-backgroundtransparentSelected surface color.
--rc-list-item-border0Row border shorthand.
--rc-list-item-border-radius0Row corner radius.
--rc-list-item-box-shadownoneRow shadow.
--rc-list-item-divider0Divider border shorthand.
--rc-list-item-divider-inset-inline0Divider inline inset.
--rc-list-item-grid-template-rowsautoInternal row track definition.
--rc-list-item-row-gap0Gap between internal row tracks.
--rc-list-item-leading-grid-columnleading-start / leading-endLeading region column placement.
--rc-list-item-leading-grid-rowautoLeading region row placement.
--rc-list-item-content-grid-columncontent-start / content-endContent region column placement.
--rc-list-item-content-grid-rowautoContent region row placement.
--rc-list-item-content-white-spacenowrapContent wrapping behavior.
--rc-list-item-content-text-overflowellipsisContent overflow marker.
--rc-list-item-trailing-grid-columntrailing-start / trailing-endTrailing region column placement.
--rc-list-item-trailing-grid-rowautoTrailing region row placement.
--rc-list-item-trailing-justify-selfendTrailing region alignment within its grid area.
--rc-list-item-state-layer-colorcurrentColorInteraction state layer color.
--rc-list-item-state-layer-opacity0Resting interaction state layer opacity.
--rc-list-item-hover-state-layer-opacity0.08Hover state opacity.
--rc-list-item-focus-state-layer-opacity0.1Focus state opacity.
--rc-list-item-pressed-state-layer-opacity0.1Pressed state opacity.
--rc-list-item-disabled-opacity0.38Disabled row opacity.
--rc-list-item-transition-duration0msRow state transition duration.
--rc-list-item-transition-easingeaseRow state transition easing.

CSS Parts

PartDescription
rowRow surface and subgrid.
state-layerHover, focus, and pressed state layer.
leadingLeading slot wrapper.
contentDefault content slot wrapper.
trailingTrailing slot wrapper.
dividerRow divider.