Skip to content

Dropdown ​

A dropdown menu built on UIDropDownMenuTemplate with an optional label. It opens a scrollable pullout of selectable items and supports both single-select and multi-select ( checkbox) modes.

Create with AceGUI:Create("Dropdown"). It inherits the Common Widget API.

Widget type: Dropdown

The pullout and its individual entries (Dropdown-Pullout, Dropdown-Item-Toggle, Dropdown-Item-Execute, etc.) are internal helper widgets created automatically. You normally only interact with the Dropdown widget's own methods below.

Methods ​

SetList ​

method#
lua
widget:SetList(list?, order?, itemType?)

Replaces the menu contents from a table. Clears any existing items (and the auto-added close button) and rebuilds the pullout.

Parameters

ParameterTypeDefaultDescription
list (optional)tableA value → text table. Passing nil empties the list.
order (optional)tableArray of keys giving the display order. If omitted, keys are sorted automatically (numeric keys/strings numerically, everything else as strings).
itemType (optional)string"Dropdown-Item-Toggle"Widget type for each entry. An invalid type raises an error.

AddItem ​

method#
lua
widget:AddItem(value, text, itemType?)

Adds a single entry to the existing list (also stored in the list table).

Parameters

ParameterTypeDefaultDescription
valueanyThe item's value/key.
textstringThe displayed text.
itemType (optional)string"Dropdown-Item-Toggle"Item widget type.

SetValue ​

method#
lua
widget:SetValue(value)

Selects a value: sets the displayed text from the list entry for that value and stores it as the current value. (Single-select use.)

Parameters

ParameterTypeDefaultDescription
valueanyThe key to select.

GetValue ​

method#
lua
widget:GetValue()

Returns the currently selected value.

Returns

TypeDescription
anyThe currently selected value.

SetText ​

method#
lua
widget:SetText(text?)

Sets the text shown in the closed dropdown directly, without changing the selected value.

Parameters

ParameterTypeDefaultDescription
text (optional)stringThe string to display, or nil for empty.

SetLabel ​

method#
lua
widget:SetLabel(text?)

Sets an optional label above the dropdown. With a label the widget height becomes 40; without it, 26.

Parameters

ParameterTypeDefaultDescription
text (optional)stringThe label string, or nil/"" to hide it.

SetMultiselect ​

method#
lua
widget:SetMultiselect(multi)

Switches between single-select and multi-select (checkbox) mode. In multi-select mode the closed text shows the comma-joined list of checked entries and a "Close" button is appended to the pullout.

Parameters

ParameterTypeDefaultDescription
multibooleantrue for multi-select (checkbox) mode, false for single-select.

GetMultiselect ​

method#
lua
widget:GetMultiselect()

Returns whether multi-select mode is enabled.

Returns

TypeDescription
booleanWhether multi-select mode is enabled.

SetItemValue ​

method#
lua
widget:SetItemValue(item, value)

In multi-select mode, sets the checked state of a specific entry and refreshes the displayed multi-text. No-op when not in multi-select mode.

Parameters

ParameterTypeDefaultDescription
itemanyThe value/key identifying the entry.
valuebooleanThe checked state to apply.

SetItemDisabled ​

method#
lua
widget:SetItemDisabled(item, disabled)

Enables or disables a specific entry in the pullout.

Parameters

ParameterTypeDefaultDescription
itemanyThe value/key identifying the entry.
disabledbooleantrue to disable, false to enable.

SetPulloutWidth ​

method#
lua
widget:SetPulloutWidth(width?)

Overrides the width of the opened pullout. When nil, the pullout matches the dropdown's own width.

Parameters

ParameterTypeDefaultDescription
width (optional)numberPixel width, or nil to auto-match the dropdown's own width.

SetDisabled ​

method#
lua
widget:SetDisabled(disabled)

Enables or disables the dropdown. A disabled dropdown greys its text/label and cannot be opened.

Parameters

ParameterTypeDefaultDescription
disabledbooleantrue to disable, false to enable.

ClearFocus ​

method#
lua
widget:ClearFocus()

Closes the pullout if it is open.

Defaults ​

On acquire the widget resets to: height 44, width 200, no label, auto pullout width, and an empty list. On release it closes and releases its pullout and clears text, value, disabled, and multiselect state.

Callbacks ​

OnValueChanged ​

callback#
lua
OnValueChanged(value, checked?)

Fired when the user selects/toggles an entry. In single-select mode the handler receives just the newly selected value and the pullout then closes. In multi-select mode it also receives the toggled entry's checked state. Subscribe with widget:SetCallback.

Parameters

ParameterTypeDefaultDescription
valueanyThe selected/toggled entry's value.
checked (optional)booleanThe entry's new checked state. Multi-select only; omitted in single-select mode.

OnOpened ​

callback#
lua
OnOpened()

Fired when the pullout opens. Subscribe with widget:SetCallback.

OnClosed ​

callback#
lua
OnClosed()

Fired when the pullout closes. Subscribe with widget:SetCallback.

OnEnter ​

callback#
lua
OnEnter()

Fired when the mouse enters the dropdown (also locks the button highlight). Subscribe with widget:SetCallback.

OnLeave ​

callback#
lua
OnLeave()

Fired when the mouse leaves the dropdown. Subscribe with widget:SetCallback.

Example ​

lua
local dd = AceGUI:Create("Dropdown")
dd:SetLabel("Choose a class")
dd:SetList({
    WARRIOR = "Warrior",
    MAGE    = "Mage",
    PRIEST  = "Priest",
}, { "WARRIOR", "MAGE", "PRIEST" })
dd:SetValue(db.class)
dd:SetCallback("OnValueChanged", function(widget, event, value)
    db.class = value
end)

Ace3, a World of Warcraft addon framework.