Skip to main content

ContextMenu

caution

All props/parameters are optional unless they are marked with an asterisk ( * ).

caution

This component requires the use of the common module contextMenu.

Example

import { common, components } from "replugged";
const { contextMenu } = common;
const { Button, ContextMenu: Menu } = components;

const ExampleContext = (): React.ReactElement => (
<Menu.ContextMenu navId="example-context" onClose={contextMenu.close}>
<Menu.MenuGroup>{/* Your Menu components here */}</Menu.MenuGroup>
<Menu.MenuItem id="example-item" label="Menu Item" action={() => console.log("Pressed!")} />
<Menu.MenuItem id="example-submenu" label="Menu Item">
{/* Add Menu components here to create a submenu */}
</Menu.MenuItem>
<Menu.MenuSeparator />
</Menu.ContextMenu>
);

<Button onContextMenu={(event) => contextMenu.open(event, () => <ExampleContext />)}>
Right-click me
</Button>;

Subcomponents

ComponentDescription
ContextMenu.ContextMenuMenu root component
ContextMenu.MenuCheckboxItemCheckbox item
ContextMenu.MenuControlItemComponent used to create custom items
ContextMenu.MenuGroupGroup other components
ContextMenu.MenuItemNormal item or it can also contain other components to create a submenu
ContextMenu.MenuRadioItemRadio item
ContextMenu.MenuSeparatorItem divider

Enums

EnumDescription
ContextMenu.ItemColorsContext menu colors
DEFAULT | BRAND | DANGER | PREMIUM | PREMIUM_GRADIENT | SUCCESS

Types

Props:

NameTypeDefaultDescription
classNamestringComponent class name
hideScrollerbooleanWhether the scroller is hidden
navId* stringContext menu id
onClose* () => voidFunction ran when the context menu got closed; check out contextMenu.close
onSelect() => voidFunction ran when clicking an item
styleCSSPropertiesComponent style
variantstringflexibleWhether the context menu width is flexible or fixed

Props:

NameTypeDefaultDescription
actionMouseEventHandler<HTMLDivElement>Function ran when clicking the item
checkedbooleanfalseCheckbox state
classNamestringComponent class name
colorContextMenu.ItemColorsContextMenu.ItemColors.DEFAULTItem color
disabledbooleanfalseWhether the checkbox is disabled
focusedClassNamestringFocused element class name
id* stringItem id
labelstringItem label
subtextstringAdditional text under the label

Props:

info

This component has more possible props:

NameTypeDefaultDescription
colorContextMenu.ItemColorsContextMenu.ItemColors.DEFAULTItem color
control* (data: { onClose: () => void; disabled: boolean; isFocused: boolean }, ref?: Ref<{ activate: () => boolean; blur: () => void; focus: () => void }>) => ReactElementControl item render function
disabledbooleanfalseWhether the item is disabled
id* stringItem id
labelstringItem label
showDefaultFocusbooleanfalseWhether the item is focusable

Props:

NameTypeDefaultDescription
classNamestringComponent class name
colorContextMenu.ItemColorsContextMenu.ItemColors.DEFAULTItem color
labelstringItem label

Props:

info

This component has more possible props:

NameTypeDefaultDescription
actionMouseEventHandler<HTMLDivElement>Function ran when clicking the item
classNamestringComponent class name
colorContextMenu.ItemColorsContextMenu.ItemColors.DEFAULTItem color
disabledbooleanfalseWhether the item is disabled
dontCloseOnActionIfHoldingShiftKeybooleanfalseWhether not to close the context menu while holding down the shift key and clicking the item
focusedClassNamestringFocused element class name
hintReactNodeItem hint
iconComponentType<unknown>Item icon
iconPropsRecord<string, unknown>Props for the icon component
id* stringItem id
imageUrlstringSource URL of the image
labelstringItem label
onFocus() => voidFunction ran when the item gets focused
showIconFirstbooleanfalseWhether the icon is shown before the label
sparklebooleanfalseWhether the submenu icon shows a sparkle effect
subMenuIconClassNamestringSubmenu icon element class name
subtextReactNodeAdditional text under the label

Props:

NameTypeDefaultDescription
actionMouseEventHandler<HTMLDivElement>Function ran when clicking the item
checkedbooleanfalseRadio state
colorContextMenu.ItemColorsContextMenu.ItemColors.DEFAULTItem color
disabledbooleanfalseWhether the radio is disabled
id* stringItem id
labelstringItem label
subtextstringAdditional text under the label

Props:

NameTypeDefaultDescription
colorContextMenu.ItemColorsContextMenu.ItemColors.DEFAULTItem color
disabledbooleanfalseWhether the item is disabled
id* stringItem id
interactivebooleanfalseWhether the item is navigable
showDefaultFocusbooleanfalseWhether the item is focusable

Props:

NameTypeDefaultDescription
actionMouseEventHandler<HTMLDivElement>Function ran when clicking the item
colorContextMenu.ItemColorsContextMenu.ItemColors.DEFAULTItem color
disabledbooleanfalseWhether the item is disabled
dontCloseOnActionIfHoldingShiftKeybooleanfalseWhether not to close the context menu while holding down the shift key and clicking the item
id* stringItem id
keepItemStylesbooleanfalseWhether use the normal menu item classes
navigablebooleantrueWhether the item is navigable
render* (data: { color: ContextMenu.ItemColors; disabled: boolean; isFocused: boolean }) => ReactNodeCustom item render function

Props:

info

The props of this component extend the props of the ContextMenu.MenuItem component.

NameTypeDefaultDescription
subMenuClassNamestringSubmenu element class name

Props:

info

The props of this component extend the props of the ContextMenu.MenuItem component.

NameTypeDefaultDescription
onChildrenScroll() => voidEach child's height
childRowHeight* numberEach child's height
listClassNamestringList element class name