Skip to main content

list_item

Function list_item 

Source
pub fn list_item() -> ListItemBuilder
Expand description

§list_item

Render an adaptive Material list row for settings, inboxes, and selection lists.

§Usage

Present list rows in settings, inboxes, or preference screens.

§Parameters

  • modifier — optional modifier chain applied to the list item container.
  • enabled — optional enabled state; defaults to true.
  • selected — externally controlled selection or checked state.
  • selection_mode — action, single-selection, or multiple-selection behavior. The owner maintains exclusivity between single-selection rows.
  • on_selection_change — requested selection in Single/Multiple modes; takes precedence over on_click. Read latest application state in callbacks.
  • headline — primary headline text when content is absent.
  • content — optional custom main content, replacing headline.
  • overline_content — optional custom content replacing overline_text.
  • supporting_content — optional custom content replacing supporting_text. Custom slots inherit their role typography and color. Supply explicit accessibility labels and descriptions when their meaning is not text.
  • overline_text — optional overline text.
  • supporting_text — optional supporting text.
  • leading — optional leading slot.
  • trailing — optional trailing slot.
  • colors — optional color palette override.
  • shape — optional container shape override. A fixed shape overrides position and state shapes.
  • shapes — optional shapes for resting and active states.
  • position — row position within a segmented list; defaults to standalone. Place segmented rows with ListItemDefaults::SEGMENTED_GAP between them.
  • dragged — apply drag colors and shape during an externally managed drag.
  • content_padding — optional inner padding override.
  • tonal_elevation — optional tonal elevation override.
  • shadow_elevation — optional shadow elevation override.
  • min_height — optional minimum height override.
  • vertical_alignment — content alignment; short rows center by default and taller rows align to their top inset.
  • on_long_click — optional long-press action; successful holds suppress ordinary clicks and selection requests. Also exposed as a context action.
  • on_click — action callback, also used as a selection-mode fallback when on_selection_change is absent.
  • interaction_state — optional shared interaction state.
  • accessibility_label — optional accessibility label.
  • accessibility_description — optional accessibility description.

§Examples

use tessera_components::{
    list_item::{ListItemSelectionMode, list_item},
    text::text,
};
use tessera_ui::{remember, tessera};

#[tessera]
fn demo() {
    let selected = remember(|| false);
    material_theme()
        .theme(|| MaterialTheme::default())
        .child(move || {
            list_item()
                .selection_mode(ListItemSelectionMode::Multiple)
                .selected(selected.get())
                .on_selection_change(move |value| selected.set(value))
                .accessibility_label("Inbox")
                .content(|| {
                    text("Inbox");
                })
                .supporting_text("3 new messages");
        });
}