apps/ui-kit/docs/context-menu.md
Context Menu are not exposed as a component, but it's used by other components.
The default context menu can be extended by providing an array of Menu Item or a function.
The default menu can be replaced with an array:
table.cellContextMenuItems = [
{
label: "Copy",
handler: (event, cell, menuItem) => {},
},
{
label: "Cut",
handler: (event, cell, menuItem) => {},
},
{
label: "Delete",
handler: (event, cell, menuItem) => {},
},
];
Or you can customize the default menu by searching for specific items using
their ids, then adding or removing them as needed.
// Adding a new item relative to an existing item
table.cellContextMenuItems = (event, cell, items) => {
const index = items.findLastIndex((item) => item.id.includes("range-copy"));
return items.toSpliced(index + 1, 0, {
name: "Custom Action",
handler: () => console.log("Custom action executed!", cell),
});
};
// Removing default items
table.cellContextMenuItems = (event, cell, items) => {
return items.filter((item) => item.id.includes("range-copy"));
};
There are two required properties to make a simple Menu Item:
const menuItem = {
label: "Delete",
handler(event, target, menuItem) {},
};
const checkboxMenuItem = {
label: "Show tables",
handler(event, target, menuItem) {},
checked: true,
};
A divider is a special item that adds a horizontal line between menu items.
const dividerMenuItem = {
type: "divider",
};
See the API reference below for more details.