Skip to main content

SearchableListItem

Trait SearchableListItem 

Source
pub trait SearchableListItem: Clone {
    type Value: Clone + PartialEq;

    // Required methods
    fn title(&self) -> SharedString;
    fn value(&self) -> &Self::Value;

    // Provided methods
    fn display_title(&self) -> Option<AnyElement> { ... }
    fn render(&self, _: &mut Window, _: &mut App) -> impl IntoElement { ... }
    fn matches(&self, query: &str) -> bool { ... }
    fn disabled(&self) -> bool { ... }
}
Expand description

An item that can appear in a searchable list (Select, ComboBox).

Required Associated Types§

Required Methods§

Source

fn title(&self) -> SharedString

Short display label shown in the dropdown row and in the trigger by default.

This is also what assistive technology reads as the committed value, so it has to stand on its own as text even when Self::display_title draws something richer.

Source

fn value(&self) -> &Self::Value

The value that identifies this item.

Provided Methods§

Source

fn display_title(&self) -> Option<AnyElement>

Override the trigger display element (e.g. “Country (US)” instead of just “United States”).

Returns None to fall back to title().

This is presentation only. An element is not text, so the accessible value keeps reporting Self::title; if the two would read differently, put the meaning a listener needs in title().

Source

fn render(&self, _: &mut Window, _: &mut App) -> impl IntoElement

Render this item’s row content inside the dropdown.

Override to add icons, avatars, secondary text, etc. The default renders title().

Source

fn matches(&self, query: &str) -> bool

Whether this item matches the search query.

Defaults to case-insensitive substring match on title().

Source

fn disabled(&self) -> bool

Whether this item should be shown as non-interactive (grayed-out, unclickable).

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl SearchableListItem for &'static str

Source§

type Value = &'static str

Source§

fn title(&self) -> SharedString

Source§

fn value(&self) -> &Self::Value

Source§

impl SearchableListItem for SharedString

Source§

impl SearchableListItem for String

Source§

type Value = String

Source§

fn title(&self) -> SharedString

Source§

fn value(&self) -> &Self::Value

Implementors§