Accessible and uniform-styled implementation of a dropdown menu.
Dropdown.basic
{ dropdownMsg = ForDropdownMsg
, onSelectMsg = GotSelectItemMsg
, state = model.dropdownState
}
|> Dropdown.withPlaceholder "Choose a book"
|> Dropdown.withItems model.books
|> Dropdown.withSelected model.selectedBook
|> Dropdown.withItemToText Books.getTitle
|> Dropdown.renderElement renderConfigBasicConfig assembles the required configuration for having a simple dropdown.
{ dropdownMsg = ForDropdownMsg
, onSelectMsg = GotSelectItemMsg
, state = model.dropdownState
}Constructs a basic dropdown. Also defines the handling function for messages, and the current dropdown's state.
basic
{ dropdownMsg = ForDropdownMsg
, onSelectMsg = GotSelectItemMsg
, state = model.dropdownState
}Constructs a filterable dropdown. Also defines the handling function for messages, and the current dropdown's state.
filterable
{ dropdownMsg = ForDropdownMsg
, onSelectMsg = GotSelectItemMsg
, state = model.dropdownState
}Keep this one in your Model, it holds the dropdown's current state.
Opaque type for the internal dropdown messages
The correct way of instantiating a Dropdown.State.
{ -- ...
, state = Dropdown.init "dropdown-id"
-- ...
}Given a message, apply an update to the Dropdown.State.
Do not ignore the returned Effect, it may include remote select's messages.
( newModel, newCmd ) =
Dropdown.update renderConfig subMsg dropdownChanges the component's placeholder text.
Dropdown.withPlaceholder "Choose a book"
someDropdownChanges the filterable component's placeholder text.
Dropdown.withPlaceholder "Choose a book"
someDropdownChanges the component's list of elements.
Dropdown.withItems
[ { id = 0, name = "Entry A" }
, { id = 1, name = "Entry B" }
]
someDropdownMarks the element as selected.
Dropdown.withSelected (List.head model.entries)
someDropdownChanges the way elements are formatted.
Dropdown.withItemToText .name
someDropdownEnd of the builder's life. The result of this function is a ready-to-insert Elm UI's Element.
The
Dropdown item msgtype is used for describing the component for later rendering.