This module provides a customizable accessible select dropdown. It uses the builder pattern:
new to create a base input.withPlaceholder or withIsRequired.view to render it.Initialize the Select model.
init : DashboardModel
init =
{ languageSelectModel = AvardaUi.Select.init "language" }Msg type for the Select component. Use this for the wrap msg in your own Msg type.
type DashboardMsg
= HandleLanguageSelect (AvardaUi.Select.Msg Language)
| NoUpdateUpdate function for the Select component. Call this in your update function to handle Select's internal messages
update : Model -> Msg -> ( Model, Cmd Msg )
update model msg =
case msg of
HandleLanguageSelect selectMsg ->
let
( updatedSelectModel, selectCmd ) =
AvardaUi.Select.update
HandleLanguageSelect
selectMsg
model.languageSelectModel
in
( { model | languageSelectModel = updatedSelectModel }, selectCmd )Create a new Select component.
AvardaUi.Select.new
{ label = "Choose a language"
, selectModel = dashboardModel.languageSelectModel
, optionToString = .name
}Render the Select as HTML.
Always call this after you've built up the input with new and chained settings.
AvardaUi.Select.new {...}
|> AvardaUi.Select.withIsRequired True
|> AvardaUi.Select.viewYou can pass extra options / callbacks to this component using updateWith
update : Model -> Msg -> ( Model, Cmd Msg )
update model msg =
case msg of
HandleLanguageSelect selectMsg ->
let
( updatedSelectModel, selectCmd ) =
AvardaUi.Select.updateWith [ AvardaUi.Select.onSelect SaveLanguageToStorage ]
HandleLanguageSelect
selectMsg
model.languageSelectModel
in
( { model | languageSelectModel = updatedSelectModel }, selectCmd )Use for triggering a message when an option is selected.
Use to fix issue with scrolling option into view when used in ShadowDOM. elm/browser cannot find the element ID when this component is used by an app which uses ShadowDOM
type alias ScrollOptionIntoViewCmd msg =
String -> Cmd msgSet the selected option.
Provide a list of options to the Select. Note that this needs to be used as a builder, when you are creating a Select, not on init
Get the currently selected option. If none is selected, returns Nothing.
Get information if Select is open or not.
Show an error message and mark the Select as invalid.
Mark the Select as required.
Disable the select. Visually dims and prevents user actions.
Change the border radius of the Select.
Adjust the gap between the Select and the dropdown menu.
Set a maximum height for the dropdown menu.
Provide a custom view function for rendering options.
Provide a custom view function for the selected option.
Add additional styles.
Add additional menu container styles.
Set the CSS position of the Select container.
Set a custom ARIA label (instead of label element).
Sets the background color of the floating label.
This is useful when the color of the background behind the select is something else then #FFFFFF.
Model type for the Select component. Use this in your own model.