Examples

John Doe
$120.00
Payment Received
Yesterday
Loading Item

SVG transforms and semantic suppression

Transformed SVG icons
Consumer-owned semantics
0

Narrow fit

No tokens: a long value pushes the label out of the row

Email ID
accounts.payable.department@a-very-long-merchant-domain.example.com

Label floor and shrinkable right cell: the value truncates

Email ID
accounts.payable.department@a-very-long-merchant-domain.example.com

Same tokens, short value: it stays flush right

Email ID
Paid

Stacked: left, center and right cells in DOM order

Email ID
Verified

Stacked with an expanded accordion

Email ID
Verified
Expanded details

Stacked while loading

Email ID

Stacked with only left and right content

Paid

Nested items inherit the tokens; a per-instance reset opts one out

Outer
Inherits
stacked
Reset
row

Documentation

A multi-section list row with left image (with fallback), center label, right image, and optional text on the right. Supports an accordion-expandable bottom section. Each section (left image, right image, center text, top section, whole item) has its own click handler. Shows a loading overlay and optional right-side circular loader spinner. The preventFocus prop removes focus outlines for non-keyboard navigation contexts. Has no selection/checkbox concept at all — for a checkbox-driven selectable row, use CheckListItem instead.

label renders as escaped plain text by default. Markup only reaches the page through a sanitize.htmlSanitizer a consumer supplies — see Rendering markup in the label below.

Only the region that was actually given its own click handler becomes an interactive control (role="button", a tab stop, and Enter/Space activation) — see the Nested interactive semantics section below.

Usage

<script>
  import { ListItem } from '@juspay/svelte-ui-components';
</script>

<ListItem />

Props

Prop Type Required Default Description
leftImageUrl string | null No - URL for the left-side image. Rendered using the Img component with fallback support.
leftImageFallbackUrl string | null No - Fallback image URL if leftImageUrl fails to load.
rightImageUrl string | null No - URL for the right-side image (e.g., an arrow or action icon).
transformSvg (svg: string) => string No - Rewrites either image's SVG markup before it is inlined. Providing it enables SVG inlining for both image URLs.
label string | null No - Center text content. Used for the main list item label. Rendered as escaped plain text by default; pass sanitize to render it as markup instead. See Rendering markup in the label below.
sanitize ListItemSanitizeOptions No - Governs how label is rendered when it contains markup: escaped plain text (default), or markup through a caller-supplied htmlSanitizer. See Rendering markup in the label below.
useAccordion boolean No false When true, wraps the bottomContent in an Accordion component for expand/collapse animation.
rightContentText string | null No - Text displayed on the right side of the list item (e.g., a price or status).
testId string No - Value for data-pw on the outer item container.
topSectionTestId string No - Value for data-pw on the top section (left + center + right).
rightImageTestId string No - Value for data-pw on the right image wrapper.
leftImageTestId string No - Value for data-pw on the left image wrapper.
centerTextTestId string No - Value for data-pw on the center text element.
showLoader boolean No false When true, shows a semi-transparent animated overlay that fills across the item (progress bar animation).
showRightContentLoader boolean No false When true, shows a circular Loader spinner in the right content area.
expand boolean No false Bindable. Controls whether the accordion bottom section is expanded or collapsed.
preventFocus boolean No false When true, suppresses the focus outline for mouse/touch-triggered focus on interactive elements. Does not affect tabindex, so the element is still a real Tab stop, and a genuine keyboard Tab still shows the indicator (:focus-visible), per WCAG 2.4.7.
suppressRoleAndTabindex boolean No false Explicit opt-in that removes ListItem's synthetic role and tabindex attributes from the item and its clickable subregions. Mouse click handlers remain active. Use when the consumer owns the semantic interactive control.
classes string No - CSS class string applied to the component's top-level element. Useful for theming — define classes with CSS variable overrides and pass them to create variant styles.
role string No 'button' ARIA role for the outer item container. Set to 'option' when using ListItem inside a role="listbox" container (e.g., autocomplete dropdowns). When 'option', tabindex is automatically set to -1 for proper listbox focus management.
ariaSelected boolean No - Sets aria-selected on the item container. Use when the ListItem represents a selectable option (e.g., the currently highlighted item in a listbox).
id string No - Sets the id attribute on the item container. Needed for aria-activedescendant references from a parent combobox input.

Snippets

Svelte 5 Snippet props — pass content blocks to the component.

Snippet Type Description
leftContent Snippet A Svelte 5 Snippet for custom content in the left area (beside or replacing the left image).
centerContent Snippet A Svelte 5 Snippet for custom content in the center area (beside or replacing the label).
rightContent Snippet A Svelte 5 Snippet for custom content in the right area (beside the right image).
bottomContent Snippet A Svelte 5 Snippet for content below the main row. Only renders when useAccordion is true; displayed inside an Accordion that expands/collapses based on the expand prop.

Events

Event Type Description
onleftimageclick (event: MouseEvent) => void Fires when the left image is clicked. Passing this prop is also what makes the left image wrapper itself a real button — see the Nested interactive semantics section.
onrightimageclick (event: MouseEvent) => void Fires when the right image is clicked. Passing this prop is also what makes the right image wrapper itself a real button.
oncentertextclick (event: MouseEvent) => void Fires when the center text/label area is clicked. Passing this prop is also what makes the center text itself a real button.
onitemclick (event: MouseEvent) => void Fires when the entire list item container is clicked (including all sub-areas, since a click on any of them bubbles up to the root).
ontopsectionclick (event: MouseEvent) => void Fires when the top section (left + center + right row, excluding the accordion bottom) is clicked. Passing this prop is also what makes the top section itself a real button.
onkeydown (event: KeyboardEvent) => void Fires when a key is pressed while any focusable section of the list item has focus.

CSS Variables

Override these custom properties to theme the component.

Variable Default CSS Property Description
--list-item-loader-foreground #86898d --loader-foreground Color of the Loader spinner foreground.
--list-item-loader-background #ffffff --loader-background Color of the Loader spinner background/center.
--list-item-loader-foreground-end #ffffff --loader-foreground-end End color of the Loader spinner gradient.
--list-item-loader-background-color #00000030 background Background overlay color when showLoader is true.
--list-item-background-color transparent background-color Background color of the list item.
--list-item-cursor pointer cursor Cursor style when hovering the list item.
--list-item-box-shadow none box-shadow Box shadow of the list item.
--list-item-box-width - width Width of the list item.
--list-item-border-radius 0px border-radius Corner rounding of the list item.
--list-item-margin - margin Outer margin of the list item.
--list-item-padding - padding Inner padding of the list item.
--list-item-border - border Border of the list item.
--list-item-transition - transition Transition animation for the list item (e.g., on hover).
--list-item-hover-background-color var(--list-item-background-color) background-color Background color on hover.
--list-item-hover-border var(--list-item-border) border Border on hover.
--list-item-top-section-flex-direction row flex-direction Direction of the top row; column stacks the cells.
--list-item-top-section-align-items - align-items Vertical alignment for the top content row.
--list-item-top-section-gap - gap Gap between top row content areas.
--list-item-left-content-display flex display
--list-item-left-image-height 24px --image-height Height of the left image.
--list-item-left-image-width 24px --image-width Width of the left image.
--list-item-left-image-padding 0px --image-padding Padding around the left image.
--list-item-left-image-border-radius 0px --image-border-radius Corner rounding of the left image.
--list-item-left-image-margin 0px --image-margin Margin around the left image.
--list-item-left-image-filter none --image-filter CSS filter applied to the left image.
--list-item-left-image-background - --image-background Background behind the left image.
--list-item-left-image-border - --image-border Border of the left image.
--list-item-left-image-hover-background var(--list-item-left-image-background) background Background color of left image on hover.
--list-item-left-image-hover-border var(--list-item-left-image-border) border Border of left image on hover.
--list-item-left-image-object-fit - --image-object-fit Object-fit of the left image.
--list-item-center-content-min-width 0 min-width Minimum width of the center cell (a label floor).
--list-item-center-text-justify-content flex-start justify-content Vertical alignment of center text.
--list-item-center-text-padding 0px 20px padding Padding around the center text.
--list-item-center-text-color #2f3841 color Color of the center text.
--list-item-center-text-font-size 12px font-size Font size of the center text.
--list-item-center-text-font-weight 300 font-weight Font weight of the center text.
--list-item-center-text-vertical-align - align-items Vertical alignment inside the center text.
--list-item-center-text-margin - margin Margin around the center text.
--list-item-center-text-border - border Border around the center text.
--list-item-center-text-cursor pointer cursor Cursor for the center text.
--list-item-center-text-font-family - font-family Font family of the center text.
--list-item-right-content-display flex display Display mode of the right content area.
--list-item-right-content-flex - flex Flex sizing for the right content area.
--list-item-right-content-min-width auto min-width Minimum width of the right cell; 0 lets it shrink.
--list-item-right-content-loader-margin - margin
--list-item-right-image-height 18px --image-height Height of the right image.
--list-item-right-image-width 18px --image-width Width of the right image.
--list-item-right-image-padding 0px --image-padding Padding around the right image.
--list-item-right-image-border-radius 0px --image-border-radius Corner rounding of the right image.
--list-item-right-image-margin 0px --image-margin Margin around the right image.
--list-item-right-image-filter - --image-filter CSS filter applied to the right image.
--list-item-right-image-background - --image-background Background behind the right image.
--list-item-right-image-border - --image-border Border of the right image.
--list-item-right-image-hover-background var(--list-item-right-image-background) --image-hover-background Background color of right image on hover.
--list-item-right-image-hover-border var(--list-item-right-image-border) --image-hover-border Border of right image on hover.
--list-item-right-content-text-color #2f3841 color Color of the right side text.
--list-item-right-content-text-font-size 12px font-size Font size of the right side text.
--list-item-right-content-text-font-weight 300 font-weight Font weight of the right side text.
--list-item-right-content-text-vertical-align - align-items
--list-item-right-content-text-padding 0px padding
--list-item-right-content-text-margin 0px margin
--list-item-right-content-text-border - border
--list-item-right-content-text-cursor pointer cursor
--list-item-right-content-text-font-family - font-family
--list-item-right-content-text-justify-content - justify-content
--list-item-loader-duration 8s animation Duration of the loading progress bar animation.

.right-content now declares min-width through --list-item-right-content-min-width (default auto, the value it computed to before), and Svelte scopes that rule to specificity (0,2,0). A consumer rule that sets min-width on .right-content therefore stops winning when its specificity is below (0,2,0), or is exactly (0,2,0) and its stylesheet loads before ListItem's. Raise the rule to (0,3,0) or set --list-item-right-content-min-width instead.

Fitting narrow screens and long values

ListItem lays its left, center and right cells out as a row and cannot ship a breakpoint of its own: the width that matters is the width of the container it sits in, which ListItem cannot know. Three tokens let the consumer's own CSS decide, using the query that matches that container: @media when the list spans the page layout, @container when it sits in a column that can be narrower than the window.

Stack the cells. Set --list-item-top-section-flex-direction: column on the consumer's own container, inside the consumer's own media or container query, and the left, center and right cells stack in DOM order, so reading and focus order are unchanged. Pair it with the existing align-items and gap tokens; stretch gives every cell the full width.

@media (max-width: 767px) {
  .order-list {
    --list-item-top-section-flex-direction: column;
    --list-item-top-section-align-items: stretch;
    --list-item-top-section-gap: 1rem;
  }
}

For a list inside a column rather than the page, query the column. The styled element must sit inside the container, not be it:

.order-column {
  container-type: inline-size;
}

@container (max-width: 30rem) {
  .order-list {
    --list-item-top-section-flex-direction: column;
  }
}

Only row and column are supported: the -reverse values reorder the cells visually against the DOM. All three cells always render, so a cell with nothing in it is an empty flex child and still adds one gap to a stack. --list-item-left-content-display: none removes the left cell.

Custom properties inherit, so a container that stacks its rows also stacks every ListItem inside it, including one rendered in bottomContent. To opt such an item out, set the token on that item's own wrapper to row or to initial. unset and inherit leave it stacked, because both take the container's value.

Keep a label and let a long value shrink. The center cell is flex: 1 with a minimum width of 0, so a long right-hand value that cannot wrap squeezes the label to nothing, and the right cell cannot shrink below its content on its own. Set --list-item-center-content-min-width to reserve room for the label and --list-item-right-content-min-width: 0 to let the right cell shrink. The floor applies to the whole center cell, so it includes the center text's padding (0px 20px by default): at a 16px root, 4.5rem with the default padding leaves 32px for the text, which is why the example zeroes it. The content inside the right cell must itself be shrinkable (min-width: 0 and overflow: hidden, plus text-overflow: ellipsis to truncate), otherwise it overflows the smaller cell.

.contact-row {
  --list-item-center-content-min-width: 4.5rem;
  --list-item-center-text-padding: 0px;
  --list-item-right-content-min-width: 0;
}
  • Set the center floor only on rows that always have a label: an empty center cell still reserves it.
  • An invalid value, such as a unitless 72, is invalid at computed-value time and falls to the property's initial value (auto for min-width, row for flex-direction), not to the default in the table above.
  • The rightContentText span keeps its own minimum width and does not truncate. Use rightContent for a value that should.

Internal Dependencies

This component uses the following library components internally:

  • Accordion
  • Loader
  • Img

Web Component

Tag: <sui-list-item>

<sui-list-item label="Item Title">
  <img slot="left-content" src="/avatar.jpg" />
  <span slot="center-content">Description</span>
  <span slot="right-content">$10.00</span>
  <div slot="bottom-content">Extra info</div>
</sui-list-item>

Like every --list-item-* token, the layout tokens can be set on the <sui-list-item> host or on any ancestor: custom properties cross the open shadow root.

Slots

Slot Name Maps to Snippet Description
left-content leftContent Content on the left side (e.g., avatar, icon).
center-content centerContent Center area content (e.g., description).
right-content rightContent Content on the right side (e.g., price, action).
bottom-content bottomContent Content below the main row.

Web Component Events

onleftimageclick, onrightimageclick, oncentertextclick, onitemclick, and ontopsectionclick are available as JS properties, and each also dispatches a same-named DOM custom event (bubbles, composed, detail: the MouseEvent argument) for a consumer who only calls addEventListener:

const item = document.querySelector('sui-list-item');
item.addEventListener('itemclick', (e) => console.log(e.detail));
item.addEventListener('leftimageclick', (e) => console.log(e.detail));

onkeydown is a JS-property callback only and does not dispatch a DOM event: it is already a native HTMLElement handler, so an item.addEventListener('keydown', ...) listener already sees the real event that bubbles out of the shadow root on its own, and a synthetic duplicate under the same name would double-deliver it.

Web components. sui-list-item declares sanitize as an object property, so htmlSanitizer can only be supplied from script — element.sanitize = { rawHtml: 'sanitize', htmlSanitizer }. There is no attribute form, because an attribute is a string and this option is a function. A vanilla-JS consumer setting sanitize as an HTML attribute gets escaping, the default, rather than an error.

Rendering markup in the label

label renders as escaped plain text by default: <b>Bold</b> shows those characters literally rather than rendering as bold. There is no sanitizer to configure and no way to make it render more without opting in — this is deliberate for the common case, a list row built from a title string that may come from user input or an external feed.

<!-- Renders the literal characters "<b>Loud</b>", not a bold word. -->
<ListItem label="<b>Loud</b>" />

If you genuinely need label rendered as markup, set sanitize.rawHtml to 'sanitize' and supply sanitize.htmlSanitizer. Your function is called once, with the raw label string, and whatever it returns is rendered through {@html}, unmodified — this component does not re-check it, and cannot: re-escaping the result would turn the feature back into 'escape'.

DOMPurify is not bundled with this library and is not a peer dependency — install a sanitizer in your own app (npm i dompurify, or anything else you trust). Nothing here imports one.

<script lang="ts">
  import DOMPurify from 'dompurify';
  import { ListItem } from '@juspay/svelte-ui-components';
</script>

<ListItem
  label="<b>Payment Received</b>"
  sanitize={{ rawHtml: 'sanitize', htmlSanitizer: (html) => DOMPurify.sanitize(html) }}
/>

This library deliberately does not implement HTML sanitization and does not depend on a sanitizer — the same position MarkdownText's htmlSanitizer takes. Escaping everything is a provably safe default, so a sanitizer written here could only ever subtract from it, and HTML sanitization is a specialist problem this package should not carry as a dependency.

A few properties worth knowing, identical in spirit to MarkdownText's:

  • Omitting the sanitizer keeps the escaping. sanitize={{ rawHtml: 'sanitize' }} with no htmlSanitizer behaves exactly like the default. A half-configured list item does not start emitting raw HTML.
  • A failing sanitizer falls back to escaping. If yours throws, or returns anything that is not a string, label is escaped instead. The unsanitized string is never emitted.
  • It has to work on the server too. ListItem renders the result through {@html} from a $derived, so on a server-rendered page the sanitizer runs during SSR and again on hydration. A browser-only sanitizer (DOMPurify with no DOM around it) throws during SSR, falls back to escaped output there, then succeeds on the client, and the two renders disagree. Give it a server implementation, or leave sanitize unset on server-rendered routes.

Migrating from the previous unconditional {@html label}

Before this change, label was always rendered through {@html} with no escaping — any consumer passing markup got it rendered. That is no longer the default: label is now escaped plain text unless sanitize opts back in. A consumer that relied on the old behaviour needs one of:

  • The label was always plain text anyway. No change needed — escaped plain text and unescaped plain text render identically when there is no markup in it.
  • The label does contain markup and it should keep rendering as markup. Add sanitize={{ rawHtml: 'sanitize', htmlSanitizer: (html) => html }} to reproduce the previous unconditional passthrough exactly (a no-op "sanitizer"). This is not recommended if label can ever contain untrusted text — supply a real sanitizer such as DOMPurify's sanitize instead.

SVG transformation

Pass transformSvg to rewrite left and right SVG image markup before it is inlined. This is useful when an app needs SVG paths to inherit its surface colour.

<ListItem
  leftImageUrl="/icons/status.svg"
  rightImageUrl="/icons/chevron.svg"
  transformSvg={(svg) => svg.replaceAll('#000000', 'currentColor')}
/>

Nested interactive semantics

The root item keeps its documented default: role="button" and tabindex="0" (or role="option"/tabindex="-1" when role="option" is passed), regardless of whether onitemclick is supplied, exactly as before.

The four sub-regions — top section, left image, center text, and right image — do not share that default. Each one only becomes a real button (role="button", a tab stop, and Enter/Space activation) when it is handed its own click handler (ontopsectionclick, onleftimageclick, oncentertextclick, onrightimageclick respectively). A sub-region with no handler of its own renders as a plain, non-focusable element with no role and no tabindex — it no longer nests a button inside the root's button just because it happens to render content. This follows the library's own rule (DESIGN_PRINCIPLES.md principle 4): a region takes an interactive role only when it was actually given a click handler.

<!-- Only the root is a button. The top section, image wrappers, and label render as
     plain elements — no nested buttons, no extra tab stops. -->
<ListItem label="Payment Received" rightContentText="Yesterday" onitemclick={handleItemClick} />

<!-- The left image is now its own button too, nested inside the root's button. This is
     the consumer's explicit composition (both a root handler and a sub-region handler
     were supplied) -- a click on the image fires onleftimageclick and then bubbles into
     onitemclick, and Enter/Space on the focused image activates only its own handler. -->
<ListItem
  label="Payment Received"
  leftImageUrl="/icons/status.svg"
  onitemclick={handleItemClick}
  onleftimageclick={handleLeftImageClick}
/>

Every zone that is interactive this way also gets working keyboard activation: pressing Enter or Space while it has focus fires its click handler exactly once, the same as a pointer click. onkeydown, when supplied, is still forwarded from every zone regardless of whether that zone is interactive — including a zone whose own keydown listener merely re-observes a keypress bubbling up from an interactive descendant, which is why it can be called more than once per keypress in a nested composition like the second example above.

Consumer-owned semantics

ListItem renders synthetic button roles and tab stops by default (root always; each sub-region only when given its own click handler, per the Nested interactive semantics section above). When a surrounding consumer supplies the interactive semantics, set suppressRoleAndTabindex to remove those paired attributes — from the root and from every sub-region, even ones with their own handler — without changing click handlers.

<ListItem suppressRoleAndTabindex onitemclick={handleItemClick} />

Accessibility

Under prefers-reduced-motion: reduce the continuous fill becomes five discrete jumps rather than being removed outright: a bare "stop" would freeze the bar at its base width: 100% and read as finished for the whole duration. Stepping holds each interval's PRIOR value, so the bar can under-report elapsed time but never overstate it. The step count is deliberately not a token — an invalid steps() value drops the declaration and restores the continuous slide, so a tunable would let a consumer switch the guard off by accident.