glaze/basecoat/select
Basecoat documentation: https://basecoatui.com/components/select/
A custom select with a styled dropdown. Requires Basecoat’s JavaScript.
For the native <select> element, see glaze/basecoat/native_select.
The selected value is submitted through a hidden input named name.
Mark the initial option with selected, or set a
placeholder.
Recipe
import glaze/basecoat/select
fn fruit() {
select.select("fruit", "fruit", [], [], [
select.group("Fruits", [
select.option("apple", [], [html.text("Apple")]),
select.option("banana", [select.selected()], [html.text("Banana")]),
]),
])
}
Values
pub fn close_on_select() -> attribute.Attribute(msg)
For select_multiple: close the dropdown after
each pick. Put this in attrs.
pub fn group(
label: String,
children: List(element.Element(msg)),
) -> element.Element(msg)
pub fn option(
value: String,
attrs: List(attribute.Attribute(msg)),
children: List(element.Element(msg)),
) -> element.Element(msg)
pub fn placeholder(text: String) -> attribute.Attribute(msg)
Shown while nothing is selected. Put this in attrs.
pub fn scroll_area(
max_height: String,
children: List(element.Element(msg)),
) -> element.Element(msg)
Wrap long option lists to make them scroll, e.g. scroll_area("18rem", options).
pub fn select(
id: String,
name: String,
attrs: List(attribute.Attribute(msg)),
trigger_attrs: List(attribute.Attribute(msg)),
children: List(element.Element(msg)),
) -> element.Element(msg)
attrsgo on the root element.trigger_attrsgo on the button that opens the dropdown, e.g. for its width.
pub fn select_multiple(
id: String,
name: String,
attrs: List(attribute.Attribute(msg)),
trigger_attrs: List(attribute.Attribute(msg)),
children: List(element.Element(msg)),
) -> element.Element(msg)
Lets the user pick several options. The hidden input holds a JSON array of the selected values.
pub fn selected() -> attribute.Attribute(msg)
Put this on an option to select it initially.
pub fn separator() -> element.Element(msg)