FiveM Docs
Core Resources

esx_menu_default

esx_menu_default reference for ESX Legacy. Build keyboard list menus with ESX.UI.Menu.Open, sliders, element fields, menu methods, keybinds and fixes.

esx_menu_default is the classic ESX list menu: a vertical list of buttons and sliders that players navigate with the arrow keys and Enter. It does not take mouse focus, so the player can keep moving while the menu is open. You open it with ESX.UI.Menu.Open('default', ...) from a client script.

Overview

Resourceesx_menu_default
SideClient only
Menu typedefault
Dependencieses_extended, esx_lib (loaded via @esx_lib/imports.lua)
UIReact build in web/build, Font Awesome icons

The manifest only declares es_extended as a dependency, but the resource loads @esx_lib/imports.lua. Start esx_lib before esx_menu_default or the resource fails with xLib errors.

The resource has no config.lua. Menus are stacked: when you open a second menu, it is shown on top, and closing it brings back the previous one.

ESX.UI.Menu.Open

ESX.UI.Menu.Open(menuType, namespace, name, data, submit, cancel, change, close)
NameTypeDescription
menuTypestring'default' for this resource.
namespacestringUsually GetCurrentResourceName(). Menus in this namespace are closed when the resource stops.
namestringUnique menu name inside the namespace.
datatableMenu data, see below.
submitfunction(data, menu)?Enter pressed on a usable element.
cancelfunction(data, menu)?Backspace pressed.
changefunction(data, menu)?Highlight moved or a slider value changed.
closefunction()?Runs after menu.close().

Returns the menu object (see Menu object).

FieldTypeDescription
titlestringMenu header. HTML is rendered.
alignstring?top-left, top-right, bottom-left, bottom-right, center, left-center or right-center. Defaults to right-center.
elementstableArray of elements.

Element fields

FieldTypeDescription
labelstringText of the row. HTML is rendered.
namestring?Your identifier, used to branch in callbacks.
descriptionstring?Second line below the label. HTML is rendered.
iconstring | tableFont Awesome icon name, e.g. 'burger' (solid set), or { 'fab', 'discord' } for another set.
type'slider'?Omit for a button.
valuenumber?Current slider value. For sliders with options it is the zero-based index into options.
minnumber?Slider minimum (default 0). Ignored when options is set.
maxnumber?Slider maximum (default 0). Ignored when options is set.
optionsstring[]?Text values for a slider. The slider cycles through them.
unselectableboolean?Skipped by arrow navigation, Enter does nothing. Good for headers.
usableboolean?false keeps the row selectable but blocks submit, change and slider steps.
disableRightArrowboolean?Hides the arrow icon on a button.

Sliders wrap around: pressing Right on the maximum jumps to the minimum and vice versa. Any extra fields you add (for example price) are passed back to your callbacks unchanged.

Callback data

submit and change receive:

FieldDescription
data.currentThe highlighted element (a copy with selected = true).
data.elementsAll elements, each with a selected flag.
data._namespace, data._nameMenu identifiers.

cancel receives only _namespace and _name in data.

Before change runs, the menu writes each element's value and selected state back into menu.data.elements, so menu.data always matches what the player sees.

Example

client/main.lua
local function openShopMenu()
    local elements = {
        { label = 'Food', unselectable = true, icon = 'utensils' },
        { label = 'Bread', name = 'bread', price = 5, type = 'slider', value = 1, min = 1, max = 20, icon = 'bread-slice' },
        { label = 'Water', name = 'water', price = 3, type = 'slider', value = 1, min = 1, max = 20, icon = 'bottle-water' },
        { label = 'Payment', name = 'payment', type = 'slider', value = 0, options = { 'Cash', 'Bank' }, icon = 'wallet' },
        { label = 'Close', name = 'close', icon = 'xmark', disableRightArrow = true },
    }

    ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'shop', {
        title = '24/7 Shop',
        align = 'top-left',
        elements = elements,
    }, function(data, menu)
        local item = data.current

        if item.name == 'close' then
            return menu.close()
        end

        if item.name == 'payment' then return end

        local payment = menu.data.elements[4].value == 0 and 'money' or 'bank'
        TriggerServerEvent('my_shop:buy', item.name, item.value, payment)
    end, function(data, menu)
        menu.close()
    end)
end

RegisterCommand('shop', openShopMenu, false)

ESX.UI.Menu.Open returns a menu object. The same object is passed as menu to every callback.

MemberDescription
menu.close()Closes this menu and runs the close callback.
menu.refresh()Re-sends menu.data to the UI. Call it after changing data.
menu.update(query, newData)Merges newData into every element matching all query fields.
menu.setElement(index, key, value)Sets one field of the element at index.
menu.setElements(elements)Replaces the element list.
menu.setTitle(title)Changes the title.
menu.removeElement(query)Removes elements that match any field in query.
menu.dataThe data table you passed in.
menu.type, menu.namespace, menu.nameIdentifiers.
menu.update({ name = 'bread' }, { label = 'Bread (sold out)', usable = false })
menu.refresh()

The setters only change Lua data. Nothing changes on screen until you call menu.refresh().

Other menu functions

These are generic ESX.UI.Menu helpers that work for every menu type (default, dialog, list).

FunctionDescription
ESX.UI.Menu.Close(type, namespace, name, cancel)Closes a specific menu. With cancel = true the cancel callback runs instead of close.
ESX.UI.Menu.CloseAll(cancel)Closes every open menu.
ESX.UI.Menu.GetOpened(type, namespace, name)Returns the menu object or nil.
ESX.UI.Menu.IsOpen(type, namespace, name)Alias of GetOpened; truthy when open.
ESX.UI.Menu.GetOpenedMenus()Returns the internal list of open menus (may contain nil holes).
ESX.UI.Menu.RegisterType(type, open, close)Registers a custom menu type. Used by the menu resources themselves.

Controls

All keys are FiveM key mappings, so players can rebind them under Settings > Key Bindings > FiveM.

Default keyKey mappingAction
Enter+menu_default_enterSubmit the highlighted element (200 ms debounce)
Backspace+menu_default_backspaceCancel
Arrow Up+menu_default_topMove up (skips unselectable rows, wraps)
Arrow Down+menu_default_downMove down
Arrow Left / Right+menu_default_left / +menu_default_rightChange slider value

Keys are ignored while the pause menu is open.

Common issues

  • attempt to index a nil value (global 'xLib'): esx_lib is missing or starts after this resource.
  • Menu does not close: submit and cancel never close the menu automatically. Call menu.close().
  • Same menu opens twice: ESX.UI.Menu.Open does not check for duplicates. Guard with if ESX.UI.Menu.IsOpen('default', GetCurrentResourceName(), 'shop') then return end or call ESX.UI.Menu.CloseAll() first.
  • Changes to elements are not visible: call menu.refresh() after setElement, update or setTitle.
  • Untrusted text breaks the menu: label, description and title are rendered as HTML. Escape player names or other user input before you show them.

Frequently asked questions

Independent documentation

esx-fivem.com is a community project and is not affiliated with the ESX Framework team. Facts on this page were checked against the upstream source. Official resources: docs.esx-framework.org and github.com/esx-framework.
Edit on GitHub

Last updated on

On this page