Components/CardItem

CardItem

A compact list row with avatar, text, and trailing actions.

VerifiedSince 0.3.4

Usage

Basic

Put switches, chevrons, or metadata in the right slot; the row emits no clicks unless clickable is set.

Loading demo...

Best Practices

  • Set clickable only when the row itself performs an action; if only the right slot is interactive, keep the row non-clickable.
  • Pass a role (button, menuitem, or option) when a clickable row isn't inside a semantic list or menu.
  • Use avatarUrl, iconClass, or avatarText for simple media and the avatar slot for complex media.
  • Keep the right slot compact; long controls squeeze the title.
  • On a dark, translucent panel, point --tx-card-item-hover-bg at the host's surface color instead of overriding the rule with :deep.

API Reference

Props

PropTypeDefaultDescription
rolestringundefinedARIA role on the root; there is no default.
titlestring''Primary label, truncated to one line.
subtitlestring''Secondary label below the title, truncated to one line.
descriptionstring''Supporting text below the top row; wraps.
iconClassstring''Icon class for the avatar area.
avatarTextstring''Text for the avatar area.
avatarUrlstring''Avatar image; takes priority over icon and text.
avatarSizenumber36Avatar size in px.
avatarShape'circle' | 'rounded''circle'Avatar shape; rounded uses a 12px radius.
clickablebooleanfalseEnables the pointer cursor, focus, and click / Enter / Space activation.
activebooleanfalseSelected state.
disabledbooleanfalseBlocks focus and activation, and sets aria-disabled.
tabindexnumberundefinedOverrides the automatic tab stop (0 when clickable); listbox hosts pass -1.
align'start' | 'center''start'Cross-axis alignment of the columns; use center for single-line rows.

Events

EventPayloadDescription
clickMouseEventFires on click, Enter, or Space when the row is clickable and not disabled.

Slots

SlotPropsDescription
avatar-Replaces the generated avatar.
title-Replaces the title.
subtitle-Replaces the subtitle.
description-Replaces the description.
right-Actions or metadata at the right of the top row.

Overview

  • Without an avatar slot, avatarUrl, iconClass, or avatarText, the left media column is omitted.
  • A clickable, enabled row gets tabindex="0"; there is no implicit role.
  • Only Enter / Space on the row itself activate it; key presses in right-slot controls pass through.
  • Hovering an active row deepens its accent instead of swapping in the neutral hover fill.
  • Hover and active fills read --tx-card-item-hover-bg / --tx-card-item-active-bg, defaulting to 18% of --tx-bg-color-overlay and 8% of --tx-color-primary; border colors aren't overridable.

Technologies

  • Source: packages/tuffex/packages/components/src/card-item/.
查看源码
packages/tuffex/packages/components/src/card-item/index.ts