/ui/elements/dropdown

The dropdown elements module exports the dropdown method to create a dropdown element group from a params argument.

Requires

Methods

(inner) dropdown(params) → {HTMLElement}

The dropdown method returns a dropdown element created from the params argument.

Parameters:
NameTypeDescription
paramsObject

Parameter for the creation of the dropdown element.

Properties
NameTypeAttributesDefaultDescription
params.placeholderstring<optional>
''

The placeholder for the list of options.

params.spanstring<optional>

Alternative property for the placeholder.

params.multiboolean<optional>

Allow multiple choice if true.

params.keepPlaceholderboolean<optional>

set this flag to true in order to keep the original placeholder after an option is selected.

params.pillsboolean<optional>

Applies pills component to show selected values.Available for mutliple choice.

params.entriesObject<optional>

Array of option elements. Expected format: [{title: 'Title for Option 1', option: 'option1'}, ...]. Add property selected: true for entry selected by default. title will appear as the description, option is a value passed as selected.

params.headerOnClickfunction<optional>

Callback to execute when a header is clicked. Overrides default function.

Returns:

HTML dropdown element

Type: 
HTMLElement

(inner) headerOnClick(e)

The headerOnClick method handles the click event for the dropdown header.

The active class will be toggled on the dropdown element.

The active class of all other dropdown in the document will be removed if event target is toggled to active.

The size and position of the dropdown and it's ul child element will be determined from the document body viewport as well the dropdown elements.

Parameters:
NameTypeDescription
eEvent

Click event

(inner) liOnClick(e, entry)

The default on click event methods for li elements in a dropdown list.

Parameters:
NameTypeDescription
eevent

Click event.

entryObject

Object associated with li element.

Properties
NameTypeAttributesDefaultDescription
e.targetHTMLElement

The li element.

entry.titlestring<optional>
entry.option

Text shown in li element.

entry.optionstring

Value associated with li element.

(inner) ulElement(params) → {HTMLElement}

Create a

    element with nested
  • elements for a dropdown.

Parameters:
NameTypeDescription
paramsObject

Parameter for the creation of the dropdown element.

Properties
NameTypeAttributesDescription
params.liOnClickfunction<optional>

Callback to execute when an element in the list is clicked. Overrrides default function.

Returns:
    element for dropdown.
Type: 
HTMLElement