Skip to main content

Dropdown

A togglable popup box containing a list of items to select a single item from.

Clicking the top section of a dropdown opens the list. Selecting an item, clicking anywhere else, or pressing the Escape key will close the dropdown list. The list renders above all other UI elements under the same LayerCollector.

Dark Light
Dark Light

By default, the dropdown list opens below the top section. However, if there is not enough space below, and there is more space above, the dropdown list will open upwards instead.

The height of the top row can also be customized by passing a Size prop. The default size of the top row can be found in Constants.DefaultDropdownHeight.

The height of the dropdown list box is determined by the RowHeight and MaxVisibleRows props. The default height of a list row can be found in Constants.DefaultDropdownRowHeight.

Dropdowns manage their own open/closed state, but otherwise are controlled components. This means that you need to manage the current selected item by passing a value to SelectedItem and a callback value to OnItemSelected. For example:

local function MyComponent()
	local selected, setSelected = React.useState("Red")
	local items = {	"Red", "Green", "Blue" }
	return React.createElement(StudioComponents.Dropdown, {
		Items = items,
		SelectedItem = selected,
		OnItemSelected = setSelected,
	})
end

Dropdowns do not by themselves require a value to always be selected. To explicitly allow the selected value to be cleared by the user, set the ClearButton prop to true. Multiple selections are not supported.

The list of items to select from can be specified either as strings or a DropdownItemDetail array. Using the detailed item format allows custom text and icons to be displayed, as seen below:

local function MyComponent()
	local items = {
		{
			Id = "item-1",
			Text = "First Item",
			Icon = {
				Image = "rbxassetid://...",
				...
			},
		},
		...
	}
	...
	return React.createElement(StudioComponents.Dropdown, {
		Items = items,
		SelectedItem = "item-1",
		...
	})
end

When using the detailed item format, the value in SelectedItem and the values that OnItemSelected is called with correspond to the Id field of an item in the Items array.

Types

Props

Component Props
interface Props {
Items{DropdownItem}
OnItemSelected((newItemstring?) → ())?
SelectedItemstring?
DefaultTextstring?
RowHeightnumber?
MaxVisibleRowsnumber?
ClearButtonboolean?
}
type DropdownItem = string | DropdownItemDetail
interface DropdownItemDetail {
Idstring
Textstring
}
interface DropdownItemIcon {
Imagestring
SizeVector2
Transparencynumber?
ColorColor3?
UseThemeColorboolean?
ResampleModeEnum.ResamplerMode?
RectOffsetVector2?
RectSizeVector2?
}
Show raw api
{
    "functions": [],
    "properties": [],
    "types": [
        {
            "name": "Props",
            "desc": "",
            "fields": [
                {
                    "name": "...",
                    "lua_type": "CommonProps",
                    "desc": ""
                },
                {
                    "name": "Items",
                    "lua_type": "{ DropdownItem }",
                    "desc": ""
                },
                {
                    "name": "OnItemSelected",
                    "lua_type": "((newItem: string?) -> ())?",
                    "desc": ""
                },
                {
                    "name": "SelectedItem",
                    "lua_type": "string?",
                    "desc": ""
                },
                {
                    "name": "DefaultText",
                    "lua_type": "string?",
                    "desc": ""
                },
                {
                    "name": "RowHeight",
                    "lua_type": "number?",
                    "desc": ""
                },
                {
                    "name": "MaxVisibleRows",
                    "lua_type": "number?",
                    "desc": ""
                },
                {
                    "name": "ClearButton",
                    "lua_type": "boolean?",
                    "desc": ""
                }
            ],
            "tags": [
                "Component Props"
            ],
            "source": {
                "line": 116,
                "path": "src/Components/Dropdown/init.luau"
            }
        },
        {
            "name": "DropdownItem",
            "desc": "",
            "lua_type": "string | DropdownItemDetail",
            "source": {
                "line": 5,
                "path": "src/Components/Dropdown/Types.luau"
            }
        },
        {
            "name": "DropdownItemDetail",
            "desc": "",
            "fields": [
                {
                    "name": "Id",
                    "lua_type": "string",
                    "desc": ""
                },
                {
                    "name": "Text",
                    "lua_type": "string",
                    "desc": ""
                },
                {
                    "name": "Icon",
                    "lua_type": "DropdownItemIcon?",
                    "desc": ""
                }
            ],
            "source": {
                "line": 16,
                "path": "src/Components/Dropdown/Types.luau"
            }
        },
        {
            "name": "DropdownItemIcon",
            "desc": "",
            "fields": [
                {
                    "name": "Image",
                    "lua_type": "string",
                    "desc": ""
                },
                {
                    "name": "Size",
                    "lua_type": "Vector2",
                    "desc": ""
                },
                {
                    "name": "Transparency",
                    "lua_type": "number?",
                    "desc": ""
                },
                {
                    "name": "Color",
                    "lua_type": "Color3?",
                    "desc": ""
                },
                {
                    "name": "UseThemeColor",
                    "lua_type": "boolean?",
                    "desc": ""
                },
                {
                    "name": "ResampleMode",
                    "lua_type": "Enum.ResamplerMode?",
                    "desc": ""
                },
                {
                    "name": "RectOffset",
                    "lua_type": "Vector2?",
                    "desc": ""
                },
                {
                    "name": "RectSize",
                    "lua_type": "Vector2?",
                    "desc": ""
                }
            ],
            "source": {
                "line": 36,
                "path": "src/Components/Dropdown/Types.luau"
            }
        }
    ],
    "name": "Dropdown",
    "desc": "A togglable popup box containing a list of items to select a single item from. \n\nClicking the top section of a dropdown opens the list. Selecting an item, clicking anywhere else, \nor pressing the Escape key will close the dropdown list. The list renders above all other UI\nelements under the same LayerCollector.\n\n| Dark | Light |\n| - | - |\n| ![Dark](/StudioComponents/components/dropdown/dark.png) | ![Light](/StudioComponents/components/dropdown/light.png) |\n\nBy default, the dropdown list opens below the top section.  However, if there is not enough \nspace below, and there is more space above, the dropdown list will open upwards instead. \n\nThe height of the top row can also be customized by passing a `Size` prop. The default size of the \ntop row can be found in [Constants.DefaultDropdownHeight].\n\nThe height of the dropdown list box is determined by the `RowHeight` and `MaxVisibleRows` props.\nThe default height of a list row can be found in [Constants.DefaultDropdownRowHeight].\n\nDropdowns manage their own open/closed state, but otherwise are controlled components.\nThis means that you need to manage the current selected item by passing a value to \n`SelectedItem` and a callback value to `OnItemSelected`. For example:\n\n```lua\nlocal function MyComponent()\n\tlocal selected, setSelected = React.useState(\"Red\")\n\tlocal items = {\t\"Red\", \"Green\", \"Blue\" }\n\treturn React.createElement(StudioComponents.Dropdown, {\n\t\tItems = items,\n\t\tSelectedItem = selected,\n\t\tOnItemSelected = setSelected,\n\t})\nend\n```\n\nDropdowns do not by themselves require a value to always be selected. To explicitly allow the \nselected value to be cleared by the user, set the `ClearButton` prop to `true`. \nMultiple selections are not supported.\n\nThe list of items to select from can be specified either as strings or a [DropdownItemDetail] array.\nUsing the detailed item format allows custom text and icons to be displayed, as seen below:\n\n```lua\nlocal function MyComponent()\n\tlocal items = {\n\t\t{\n\t\t\tId = \"item-1\",\n\t\t\tText = \"First Item\",\n\t\t\tIcon = {\n\t\t\t\tImage = \"rbxassetid://...\",\n\t\t\t\t...\n\t\t\t},\n\t\t},\n\t\t...\n\t}\n\t...\n\treturn React.createElement(StudioComponents.Dropdown, {\n\t\tItems = items,\n\t\tSelectedItem = \"item-1\",\n\t\t...\n\t})\nend\n```\n\nWhen using the detailed item format, the value in `SelectedItem` and the values that\n`OnItemSelected` is called with correspond to the `Id` field of an item in the `Items` array.",
    "source": {
        "line": 71,
        "path": "src/Components/Dropdown/init.luau"
    }
}