Skip to main content

Dropdown

Properties

PropertyTypeDescription
textstringText displayed in the dropdown
itemstableMenu item content, See Items
typebutton, defaultType of dropdown
buttonTypestringButton-type of dropdown See Button
buttonStyletableCSS Properties of dropdown button
buttonPropstableProperties of button. See Button
placementstringPlacement of popup from dropdown. See Placement
arrowboolean, tableSee Arrow
triggerclick, hover, contextMenuHow the dropdown is triggered
openbooleanControls whether dropdown is opened
autoFocusbooleanWhether dropdown will have focus
disabledbooleanWhether dropdown is disabled
menutableSee Menu

Properties (type = button)

PropertyTypeDescription
loadingbooleanWhether dropdown is loading
dangerbooleanDisplays buttons as red
iconstringIcon to open the dropdown
sizesmall, middle, largeSize of buttons
menuButtonTypestringType of button
These properties are for when type == "button"

List of Icons

Ant Design Dropdown

Ant Design Menu Properties

Children

Dropdown does not support children.

Example

local items = {
{
label = "Xean Xeansen",
key = "1",
},
{
label = "Walter Waltersen",
key = "2",
},
{
type = "divider"
},
{
label = "More -> Xean",
key = "more:xean",
children = {
{
label = "Kick",
key = "xean:kick",
},
{
label = "Mute",
key = "xean:mute",
}
}
}
}

myUI:createElement("Dropdown", {
text = "Dropdown Text",
items = items,
onClick = function(_, _, event)
print("Teleport To")
end,
menu = {
selectable = true,
onClick = function(_, _, event)
local key = event.key;
local keyPath = event.keyPath;
print("menu -> onClick: Key: ", key)
--print("menu -> onClick: ", json.encode(event))
end,
onSelect = function(_, _, event)
local keyPath = event.keyPath;
local selectedKeys = event.selectedKeys
print("menu -> onSelect: ", json.encode({keyPath, selectedKeys}, {indent = true}))
--print("menu -> onSelect: ", json.encode(event))
end,
onDeselect = function(_, _, event)
local keyPath = event.keyPath;
local selectedKeys = event.selectedKeys
print("menu -> onDeselect: ", json.encode({keyPath, selectedKeys}, {indent = true}))
--print("menu -> onDeselect: ", json.encode(event))
end,
onOpenChange = function(_, _, openKeys)
print("menu -> onOpenChange: ", json.encode(openKeys))
end,
},
}),

This is how it looks:

image

text

The text displayed within the dropdown.

items

Table containing the content of the dropdown.

PropertyDescriptionTypeDefault
dangerDisplay the danger stylebooleanfalse
disabledWhether menu item is disabledbooleanfalse
iconThe icon of the menu itemstring-
keyUnique ID of the menu itemstring-
labelMenu labelstring-
titleSet display title for collapsed itemstring-
childrenSub-menusMenuItemType[]-

type

The type of dropdown. Just changes how the "element itself" looks.

In the below example the text "Teleport To" is a button, that will not open the dropdown:

image

buttonType

The type of button when type = "default".

Can be any of the following: primary, default, dashed, text, link.

buttonType = "link":

image

buttonType = "text":

image

buttonStyle

Styling of the button when type = "default". You can see more here (Button)

buttonProps

Props of the button when type = "default". You can see more here (Button)

Things like onClick etc.

placement

Placement of the popup for the dropdown, can be any of the following:

bottomLeft bottom bottomRight topLeft top topRigh

placement = "top":

image

arrow

Can be either a boolean or a table, like so arrow = {pointAtCenter = boolean}.

When true a arrow will point towards the element that opened the dropdown.

When {pointAtCenter = true} the arrow will point in the center of the element that opened the dropdown.

trigger

How the dropdown is triggered.

click means the user has to click to open the dropdown.

hover means the user just have to hover to open the dropdown.

contextMenu means the user has to right-click to open the dropdown.

open

Controls weather the dropdown is opened/closed.

When you set this you'll have to handle the opening/closing of the dropdown yourself.

autoFocus

Weather the dropdown should have focus when displayed to the user.

disabled

Weather the dropdown is disaplyed.

image

Table containing properties for menu.

PropertyDescriptionType
selectableAllows selecting menu itemsboolean
multipleAllows selection of multiple itemsboolean
modeDirection/Type of menuvertical horizontal inline
defaultOpenKeysList of default opened keys. (For entries with children)string[]
defaultSelectedKeysTable of default selected keys. (When selectable=true)string[]
expandIconIcon for menus containing sub-menusstring
forceSubMenuRender"Render submenu into DOM before it becomes visible"boolean
inlineCollapsed"Specifies the collapsed status when menu is inline mode"boolean
inlineIndent"Indent (in pixels) of inline menu items on each level"number
styleCSS Properties fors styling menutable/CSSProperties
subMenuCloseDelay"Delay time to hide submenu when mouse leaves (in seconds)"number
subMenuOpenDelay"Delay time to show submenu when mouse enters (in seconds)"number
themeColor theme of the menulight dark
triggerSubMenuAction"Which action can trigger submenu open/close"hover click
onClickCalled when a menu item is clickedfunction(event)
onSelectCalled when a menu item is selectedfunction(event)
onDeselectCalled when a menu item is deselected (multiple mode only)function(event)
onOpenChangeCalled when sub-menus are opened or closedfunction(openKeys)
onClick

Event is fired when user clicks a sub-menu/item.

onClick = function(_, _, event)
local key = event.key;
local keyPath = event.keyPath;
print("menu -> onClick: Key: ", key)
end
onSelect

Event is fired when selectable = true and the user selects an item or sub-item.

onSelect = function(_, _, event)
local keyPath = event.keyPath;
local selectedKeys = event.selectedKeys
print("menu -> onSelect: ", json.encode({keyPath, selectedKeys}, {indent = true}))
end
onDeselect

Event is fired when selectable = true and the user deselects an item or sub-item.

onOpenChange

Event is fired when any sub-menu is opened or closed.

onOpenChange = function(_, _, openKeys)
print("menu -> onOpenChange: ", json.encode(openKeys))
end