Reflex Logo
Docs Logo
Library

/

Overlay

/

Context Menu

A Context Menu is a popup menu that appears upon user interaction, such as a right-click or a hover.

A Context Menu is composed of a context_menu.root, a context_menu.trigger and a context_menu.content. The context_menu_root contains all the parts of a context menu. The context_menu.trigger is the element that the user interacts with to open the menu. It wraps the element that will open the context menu. The context_menu.content is the component that pops out when the context menu is open.

The context_menu.item contains the actual context menu items and sits under the context_menu.content.

The context_menu.sub contains all the parts of a submenu. There is a context_menu.sub_trigger, which is an item that opens a submenu. It must be rendered inside a context_menu.sub component. The context_menu.sub_content is the component that pops out when a submenu is open. It must also be rendered inside a context_menu.sub component.

The context_menu.separator is used to visually separate items in a context menu.

In this example, we will show how to open a dialog box from a context menu, where the menu will close and the dialog will open and be functional.

API Reference

rx.context_menu.root

Menu representing a set of actions, displayed at the origin of a pointer right-click or long-press.

Context Menu (right click)

PropType | ValuesDefaultInteractive
modal
bool
-
dir
"ltr" | "rtl"
-

Event Triggers

See the full list of default event triggers
TriggerDescription
on_open_changeFired when the open state changes.

rx.context_menu.item

The component that contains the context menu items.

Context Menu (right click)

PropType | ValuesDefaultInteractive
color_scheme
"tomato" | "red" | ...
-
shortcut
str
-
as_child
bool
False
disabled
bool
-
text_value
str
-

Event Triggers

See the full list of default event triggers
TriggerDescription
on_selectFired when the item is selected.

rx.context_menu.separator

Separates items in a context menu.

Props

No component specific props

rx.context_menu.trigger

Wraps the element that will open the context menu.

Context Menu (right click)

PropType | ValuesDefaultInteractive
disabled
bool
-

rx.context_menu.content

The component that pops out when the context menu is open.

Context Menu (right click)

PropType | ValuesDefaultInteractive
size
"1" | "2"
-
variant
"solid" | "soft"
-
color_scheme
"tomato" | "red" | ...
-
high_contrast
bool
-
as_child
bool
False
loop
bool
False
force_mount
bool
-
side
"top" | "right" | ...
"top"
side_offset
Union[int, float]
0
align
"start" | "center" | ...
"center"
align_offset
Union[int, float]
-
avoid_collisions
bool
True
collision_padding
Union[float, int, dict]
0
sticky
"partial" | "always"
"partial"
hide_when_detached
bool
False

Event Triggers

See the full list of default event triggers
TriggerDescription
on_close_auto_focusFired when focus moves back after closing.
on_escape_key_downFired when the escape key is pressed.
on_pointer_down_outsideFired when a pointer down event happens outside the context menu.
on_focus_outsideFired when focus moves outside the context menu.
on_interact_outsideFired when the pointer interacts outside the context menu.

rx.context_menu.sub

Contains all the parts of a submenu.

Context Menu (right click)

PropType | ValuesDefaultInteractive
open
bool
-
default_open
bool
-

Event Triggers

See the full list of default event triggers
TriggerDescription
on_open_changeFired when the open state changes.

rx.context_menu.sub_trigger

An item that opens a submenu.

Context Menu (right click)

PropType | ValuesDefaultInteractive
as_child
bool
False
disabled
bool
-
text_value
str
-

rx.context_menu.sub_content

The component that pops out when a submenu is open.

Context Menu (right click)

PropType | ValuesDefaultInteractive
as_child
bool
False
loop
bool
False
force_mount
bool
-
side_offset
Union[int, float]
0
align_offset
Union[int, float]
-
avoid_collisions
bool
True
collision_padding
Union[float, int, dict]
0
sticky
"partial" | "always"
"partial"
hide_when_detached
bool
False

Event Triggers

See the full list of default event triggers
TriggerDescription
on_escape_key_downFired when the escape key is pressed.
on_pointer_down_outsideFired when a pointer down event happens outside the context menu.
on_focus_outsideFired when focus moves outside the context menu.
on_interact_outsideFired when interacting outside the context menu.

Built with Reflex