menuOptions
Description
Optional. The function takes the context menu type name (and a file/folder data if necessary) as an input and returns customized context menu optionsIt allows configuring default context menu options.
Usage
menuOptions: (mode: string, item?:{}) => []
Parameters
mode
- (required) the name of the context menu mode that can be one of the following:file
- the list of context menu options for a filefolder
- the context menu mode for foldersadd
- menu options that are available when clicking the Add New buttonbody
- menu options that open on clicking an empty area in the cards or table view modemultiselect
- menu options available when multiple files or folders are selected -item
- (optional) an object with data for a file or folder (if the file or folder mode is set). The parameters are the ones returned by thegetFile
method.
Returns
The function returns an array with context menu options for the requested menu mode and/or item. If the menuOptions
function returns false or an empty array, the context menu will not be displayed. The default array of menu options includes objects with the following parameters for each:
icon
(string) - (optional) the name of an icontext
(string) - (optional) the text for an optionsubtext
(string) - (optional) a hotkey assigned to an optionid
(string) - (optional) the id of an option
The full list of menu options for each menu type is provided here Default context menu options
Example
In the example below we keep only the Delete option for the "/Pictures" folder.
<script>
import { getData, getDrive } from "./common/data";
import { Filemanager, getMenuOptions } from "wx-svelte-filemanager";
function menuOptions(mode, item) {
switch (mode) {
case "folder":
if (item.id === "/Pictures")
return [
{
icon: "wxi-close",
text: "Delete",
hotkey: "Delete",
id: "delete",
},
];
default:
return getMenuOptions(mode);
}
}
</script>
<Filemanager data={getData()} drive={getDrive()} {menuOptions} />
If the menuOptions
function returns false or an empty array, the context menu will not be displayed.
<script>
import { getData, getDrive } from "./common/data";
import { Filemanager, getMenuOptions } from "wx-svelte-filemanager";
function menuOptions(mode, item) {
switch (mode) {
case "file":
case "folder":
if (item.id === "/Code") return false;
default:
return getMenuOptions(mode);
}
}
</script>
<Filemanager data={getData()} drive={getDrive()} {menuOptions} />