Skip to main content

Function: createDropdown()

createDropdown(world, parent, options): Dropdown

Defined in: ui/utilities/create-dropdown.ts:170

Creates a dropdown: a header button (see createButton) showing the currently selected option and a chevron indicator on its right edge, with a UiDropdownEcsComponent added, plus one option-row button per entry in options, stacked below the header and hidden until the header is clicked open. Selecting an option updates the header's label, raises onValueChanged, and closes the list. The chevron flips between chevronClosedText and chevronOpenText in step with dropdown.isOpen.

Known limitation: clicking outside the open list doesn't close it - only clicking the header again or selecting an option does. Register your own listener (e.g. on a full-canvas click-catcher, gated on dropdown.isOpen) if your game needs that.

Parameters​

world​

EcsWorld

The ECS world to create the dropdown entity in.

parent​

number

The parent entity - a canvas (see createUiCanvas) or another UI element.

options​

CreateDropdownOptions

Options for configuring the dropdown. headerSprite, optionSprite, options, and fontAtlas have no sensible default and must always be provided.

Returns​

Dropdown

The created dropdown: its header entity/button, its option row buttons, its chevron label entity, its UiDropdownEcsComponent, and onValueChanged for the common case of registering a single listener.