A segmented control: a row of toggle buttons where exactly one is chosen.
<.segmented id="range" value={@range} on_change="set-range" options={~w(day month year)} />
<.segmented field={@form[:view]} options={[{"List", "list"}, {"Board", "board"}]} />
<.segmented id="view" value="board" options={[
%{label: "Board", value: "board", icon: "kanban"},
%{label: "All", value: "all", count: 128}
]} />Options are strings, {label, value} tuples or maps with :label, :value, :icon, :count
and :disabled. It is a role="group" (see role) of buttons with aria-pressed. The choice is made in
the browser (hook LedgerUI.Segmented, priv/static/ledger_ui/hooks/segmented.js): a new
value from the server wins, a patch that does not change it leaves the person's choice
alone, arrow keys/Home/End move the focus (one segment is in the Tab order).
With a name (or field) the control submits through a hidden input that fires input, so a
form's phx-change runs. on_change is an event name (pushed with
%{"id" => id, "value" => value} to target) or a %JS{}.
Summary
Functions
Attributes
id(:string) - Defaults tonil.name(:string) - Defaults tonil.value(:any) - Defaults tonil.field(Phoenix.HTML.FormField) - Defaults tonil.options(:list) - Strings,{label, value}tuples or maps; or write<:option>slots. Defaults to[].label(:string) - Defaults tonil.help(:string) - Defaults tonil.errors(:list) - Defaults to[].size(:string) - Defaults to"md". Must be one of"sm","md", or"lg".shape(:string) - Defaults to"rounded". Must be one of"rounded", or"pill".full(:boolean) - Defaults tofalse.stretch(:boolean) - The canvas form of a full-width control:width:100%on the group,flex:1per button. Defaults tofalse.role(:string) -group(default) or what the surface needs. Defaults to"group".disabled(:boolean) - Defaults tofalse.on_change(:any) - Defaults tonil.target(:any) - Defaults tonil.wrapper_class(:any) - Defaults tonil.class(:any) - Defaults tonil.- Global attributes are accepted. Supports all globals plus:
["form"].
Slots
option- One segment, its content the label (instead ofoptions).valuedefaults to the position;selectedchooses it whenvalueis not given. Accepts attributes:value(:any)label(:string)icon(:string)count(:any)disabled(:boolean)selected(:boolean)