mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-18 15:36:02 +01:00
feat(web/menu): allow passing default index for horizontal lists
This commit is contained in:
@@ -77,7 +77,7 @@ RegisterCommand('testMenu', function()
|
|||||||
lib.setMenuOptions('epic_menu', {
|
lib.setMenuOptions('epic_menu', {
|
||||||
{label = 'Nice 1'},
|
{label = 'Nice 1'},
|
||||||
{label = 'Nice 2', icon = {'fab', 'bitcoin'}},
|
{label = 'Nice 2', icon = {'fab', 'bitcoin'}},
|
||||||
{label = 'Nice 3', icon = 'biohazard', values={'option 1', 'option 2', 'option 3'}}
|
{label = 'Nice 3', icon = 'biohazard', values={'option 1', 'option 2', 'option 3'}, defaultIndex = 2}
|
||||||
})
|
})
|
||||||
lib.showMenu('epic_menu')
|
lib.showMenu('epic_menu')
|
||||||
end,
|
end,
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ export interface MenuItem {
|
|||||||
values?: string[];
|
values?: string[];
|
||||||
description?: string;
|
description?: string;
|
||||||
icon?: IconProp;
|
icon?: IconProp;
|
||||||
|
defaultIndex?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface MenuSettings {
|
interface MenuSettings {
|
||||||
@@ -43,7 +44,7 @@ debugData<MenuSettings>([
|
|||||||
},
|
},
|
||||||
{ label: "Option 1" },
|
{ label: "Option 1" },
|
||||||
{ label: "Option 2" },
|
{ label: "Option 2" },
|
||||||
{ label: "Vehicle class", values: ["Nice", "Super nice", "Extra nice"] },
|
{ label: "Vehicle class", values: ["Nice", "Super nice", "Extra nice"], defaultIndex: 1 },
|
||||||
{ label: "Option 1" },
|
{ label: "Option 1" },
|
||||||
{ label: "Option 2" },
|
{ label: "Option 2" },
|
||||||
{ label: "Vehicle class", values: ["Nice", "Super nice", "Extra nice"] },
|
{ label: "Vehicle class", values: ["Nice", "Super nice", "Extra nice"] },
|
||||||
@@ -150,7 +151,7 @@ const ListMenu: React.FC = () => {
|
|||||||
setVisible(true);
|
setVisible(true);
|
||||||
let arrayIndexes: { [key: number]: number } = {};
|
let arrayIndexes: { [key: number]: number } = {};
|
||||||
for (let i = 0; i < data.items.length; i++) {
|
for (let i = 0; i < data.items.length; i++) {
|
||||||
if (Array.isArray(data.items[i].values)) arrayIndexes[i] = 0;
|
if (Array.isArray(data.items[i].values)) arrayIndexes[i] = data.items[i].defaultIndex || 0;
|
||||||
}
|
}
|
||||||
setIndexStates(arrayIndexes);
|
setIndexStates(arrayIndexes);
|
||||||
listRefs.current[0]?.focus();
|
listRefs.current[0]?.focus();
|
||||||
@@ -161,7 +162,7 @@ const ListMenu: React.FC = () => {
|
|||||||
{visible && (
|
{visible && (
|
||||||
<Tooltip
|
<Tooltip
|
||||||
label={menu.items[selected].description}
|
label={menu.items[selected].description}
|
||||||
isOpen={menu.items[selected].description ? true : false}
|
isOpen={!!menu.items[selected].description}
|
||||||
bg="#25262B"
|
bg="#25262B"
|
||||||
color="#909296"
|
color="#909296"
|
||||||
placement="bottom"
|
placement="bottom"
|
||||||
|
|||||||
Reference in New Issue
Block a user