Corex.List (Corex v0.2.0)

View Source

Flat selectable items for Combobox, Listbox, and Select.

Build items with Corex.List.new/1 or Corex.List.Item.new/1. Each row is a Corex.List.Item with required :label and optional :value (defaults to item-1, item-2, … when built through new/1, or list-<integer> from Corex.Item.generate_value/1 when built only through Item.new/1), plus :to, :redirect, :new_tab, :disabled, :group, and :meta.

What the items attr accepts

Combobox, Listbox, and Select accept two shapes, and this is the whole contract:

  1. A Corex.List.Item struct, which is what new/1 returns. Use this.
  2. A plain map with an atom :label key, plus any of the optional fields above. A missing :value is generated. This exists so a query result can render without a build step, and only atom keys are read.

Anything else is dropped with a warning rather than raising, because items are often built from database rows and one malformed row should not take down the LiveView. Nothing else is supported: string keys, keyword lists, and structs of other types all fall into the dropped case.

When the parent sets redirect, selection can navigate using each item’s :to or value as destination; per-item :redirect is :href, :patch, :navigate, or false to opt out. With redirect enabled, the client runs single-select in Zag even if the form uses multiple.

Summary

Functions

Creates a list of List.Item structs from a list of attribute maps.

Functions

new(items)

@spec new([Corex.List.Item.t() | map() | keyword()]) :: [Corex.List.Item.t()]

Creates a list of List.Item structs from a list of attribute maps.

For each map or keyword list, if :value is omitted, it is set to "item-<index>" (1-based), matching Corex.Content.new/1.

Raises ArgumentError if items is not a list or contains invalid items.