Menu
A list of actions or options opened from a trigger.
This demo runs the real GPUI component on WebGPU, which this browser does not expose.
Try Chrome or Edge 113+, or Safari 26+. In Firefox, enable dom.webgpu.enabled.
You can also run it natively: cargo run -p showcase menu
The demo failed to start in this browser.
You can run it natively instead: cargo run -p showcase menu
Live examples are not supported on most mobile browsers yet — open this page on a desktop or tablet to run the demo.
Recent phones with WebGPU may manage it (downloads ~18 MB):
#Anatomy
Import the component's parts and compose them under its root:
use base_gpui::menu::{
MenuArrow,
MenuBackdrop,
MenuCheckboxItem,
MenuCheckboxItemIndicator,
MenuGroup,
MenuGroupLabel,
MenuItem,
MenuLinkItem,
MenuPopup,
MenuPortal,
MenuPositioner,
MenuRadioGroup,
MenuRadioItem,
MenuRadioItemIndicator,
MenuRoot,
MenuSeparator,
MenuSubmenuRoot,
MenuSubmenuTrigger,
MenuTrigger,
};
MenuRoot::new()
.child(
MenuRadioGroup::new()
.child(
MenuGroupLabel::new(),
)
.child(
MenuRadioItem::new()
.child(
MenuRadioItemIndicator::new(),
),
)
.child(
MenuSeparator::new(),
),
)
.child(
MenuTrigger::new(),
);
The anatomy is a structural overview. Parts with mutually exclusive modes may need separate instances; each part's section below documents its configuration.
#MenuRoot
Coordinates the component's state and supplies context to its child parts.
use base_gpui::menu::MenuRoot;
MenuRoot::new()
.id("example-id")
.default_open(true)
.open(true)
.trigger_id("example-id")
.default_trigger_id("example-id")
.disabled(true)
.modal(true)
.loop_focus(true)
.orientation(/* orientation: MenuOrientation */)
.close_parent_on_esc(true)
.highlight_item_on_hover(true)
.on_open_change(|/* callback arguments */| { /* handle change */ })
.on_open_change_complete(|/* callback arguments */| { /* handle change */ })
.style_with_state(|/* callback arguments */| { /* handle change */ })
.context_menu_parent()
.menubar_link(/* link: MenuMenubarLink */)
.is_disabled();
#Builders
| Builder | Signature & description |
|---|---|
.new | pub fn new() -> SelfCreates a MenuRoot with its default configuration. |
.child | pub fn child(mut self, child: impl Into<MenuChild<P>>) -> Self
Adds one typed child to this part. |
.children | pub fn children(mut self, children: impl IntoIterator<Item = impl Into<MenuChild<P>>>) -> Self
Adds multiple typed children in iteration order. |
.child_any | pub fn child_any(mut self, child: impl IntoElement) -> Self
Adds one arbitrary renderable child to this part. |
.id | pub fn id(mut self, id: impl Into<ElementId>) -> Self
Sets the stable GPUI element identity. Use a unique value when multiple instances can appear in the same view. |
.default_open | pub fn default_open(mut self, default_open: bool) -> Self
Sets the initial open state for an uncontrolled component. |
.open | pub fn open(mut self, open: bool) -> Self
Controls whether the component is open. |
.trigger_id | pub fn trigger_id(mut self, trigger_id: impl Into<ElementId>) -> Self
Sets the trigger id configuration for this part. |
.default_trigger_id | pub fn default_trigger_id(mut self, trigger_id: impl Into<ElementId>) -> Self
Sets the initial trigger id for uncontrolled state. |
.disabled | pub fn disabled(mut self, disabled: bool) -> Self
When true, prevents user interaction with this part. |
.modal | pub fn modal(mut self, modal: bool) -> Self
Controls whether the overlay behaves modally and blocks interaction outside it. |
.loop_focus | pub fn loop_focus(mut self, loop_focus: bool) -> Self
Controls whether keyboard focus wraps from the last enabled item to the first and vice versa. |
.orientation | pub fn orientation(mut self, orientation: MenuOrientation) -> Self
Sets the component's horizontal or vertical orientation and corresponding keyboard behavior. |
.close_parent_on_esc | pub fn close_parent_on_esc(mut self, close_parent_on_esc: bool) -> Self
Controls whether close parent on esc behavior is enabled. |
.highlight_item_on_hover | pub fn highlight_item_on_hover(mut self, highlight_item_on_hover: bool) -> Self
Controls whether highlight item on hover behavior is enabled. |
.on_open_change | pub fn on_open_change(mut self, on_open_change: impl Fn(bool, &mut MenuOpenChangeDetails<P>, &mut Window, &mut App) + 'static,) -> Self
Registers a callback invoked when open change occurs. |
.on_open_change_complete | pub fn on_open_change_complete(mut self, on_open_change_complete: impl Fn(bool, &MenuOpenChangeDetails<P>, &mut Window, &mut App) + 'static,) -> Self
Registers a callback invoked when open change complete occurs. |
.style_with_state | pub fn style_with_state(mut self, style: impl Fn(MenuRootStyleState, Div) -> Div + 'static,) -> Self
Styles the part from its current behavioral state while preserving separation between behavior and visual design. |
.context_menu_parent | pub fn context_menu_parent(mut self) -> SelfWiring seam used by |
.menubar_link | pub fn menubar_link(mut self, link: MenuMenubarLink) -> Self
Wiring seam used by the Menubar's child wiring: injects the menubar link that makes this menu a menubar-parented menu. |
.is_disabled | pub fn is_disabled(&self) -> boolThe menu-level disabled fact, read by menubar child wiring for the initial trigger slot metadata. MenuRoot also supports the GPUI traits implemented in its source, such as standard styling or child composition. |
#MenuSubmenuRoot
Coordinates the component's state and supplies context to its child parts.
use base_gpui::menu::MenuSubmenuRoot;
MenuSubmenuRoot::new()
.id("example-id")
.default_open(true)
.open(true)
.disabled(true)
.loop_focus(true)
.orientation(/* orientation: MenuOrientation */)
.close_parent_on_esc(true)
.highlight_item_on_hover(true)
.on_open_change(|/* callback arguments */| { /* handle change */ })
.on_open_change_complete(|/* callback arguments */| { /* handle change */ })
.style_with_state(|/* callback arguments */| { /* handle change */ });
#Builders
| Builder | Signature & description |
|---|---|
.new | pub fn new() -> SelfCreates a MenuSubmenuRoot with its default configuration. |
.id | pub fn id(mut self, id: impl Into<ElementId>) -> Self
Sets the stable GPUI element identity. Use a unique value when multiple instances can appear in the same view. |
.child | pub fn child(mut self, child: impl Into<MenuSubmenuRootChild<P>>) -> Self
Adds one typed child to this part. |
.child_any | pub fn child_any(mut self, child: impl IntoElement) -> Self
Adds one arbitrary renderable child to this part. |
.default_open | pub fn default_open(mut self, default_open: bool) -> Self
Sets the initial open state for an uncontrolled component. |
.open | pub fn open(mut self, open: bool) -> Self
Controls whether the component is open. |
.disabled | pub fn disabled(mut self, disabled: bool) -> Self
When true, prevents user interaction with this part. |
.loop_focus | pub fn loop_focus(mut self, loop_focus: bool) -> Self
Controls whether keyboard focus wraps from the last enabled item to the first and vice versa. |
.orientation | pub fn orientation(mut self, orientation: MenuOrientation) -> Self
Sets the component's horizontal or vertical orientation and corresponding keyboard behavior. |
.close_parent_on_esc | pub fn close_parent_on_esc(mut self, close_parent_on_esc: bool) -> Self
Controls whether close parent on esc behavior is enabled. |
.highlight_item_on_hover | pub fn highlight_item_on_hover(mut self, highlight_item_on_hover: bool) -> Self
Controls whether highlight item on hover behavior is enabled. |
.on_open_change | pub fn on_open_change(mut self, on_open_change: impl Fn(bool, &mut MenuOpenChangeDetails<P>, &mut Window, &mut App) + 'static,) -> Self
Registers a callback invoked when open change occurs. |
.on_open_change_complete | pub fn on_open_change_complete(mut self, on_open_change_complete: impl Fn(bool, &MenuOpenChangeDetails<P>, &mut Window, &mut App) + 'static,) -> Self
Registers a callback invoked when open change complete occurs. |
.style_with_state | pub fn style_with_state(mut self, style: impl Fn(MenuRootStyleState, Div) -> Div + 'static,) -> Self
Styles the part from its current behavioral state while preserving separation between behavior and visual design. MenuSubmenuRoot also supports the GPUI traits implemented in its source, such as standard styling or child composition. |
#MenuSubmenuTrigger
Interactive control that opens, closes, or activates the component.
use base_gpui::menu::MenuSubmenuTrigger;
MenuSubmenuTrigger::new()
.id("example-id")
.label("label")
.disabled(true)
.open_on_hover(true)
.delay(/* delay: Duration */)
.close_delay(/* close_delay: Duration */)
.label_value()
.disabled_value()
.open_on_hover_value()
.delay_value()
.close_delay_value()
.wired(0, /* focus_handle: FocusHandle */)
.with_contexts(/* parent: MenuContext<P> */, /* child */, 0)
.style_with_state(|/* callback arguments */| { /* handle change */ });
#Builders
| Builder | Signature & description |
|---|---|
.new | pub fn new() -> SelfCreates a MenuSubmenuTrigger with its default configuration. |
.id | pub fn id(mut self, id: impl Into<ElementId>) -> Self
Sets the stable GPUI element identity. Use a unique value when multiple instances can appear in the same view. |
.label | pub fn label(mut self, label: impl Into<SharedString>) -> Self
Sets the label configuration for this part. |
.disabled | pub fn disabled(mut self, disabled: bool) -> Self
When true, prevents user interaction with this part. |
.open_on_hover | pub fn open_on_hover(mut self, open_on_hover: bool) -> Self
Controls whether open on hover behavior is enabled. |
.delay | pub fn delay(mut self, delay: Duration) -> Self
Sets the delay before the related transition or interaction begins. |
.close_delay | pub fn close_delay(mut self, close_delay: Duration) -> Self
Sets the delay before an open component closes after the closing interaction. |
.label_value | pub fn label_value(&self) -> Option<SharedString>Sets the label value configuration for this part. |
.disabled_value | pub fn disabled_value(&self) -> boolSets the disabled value configuration for this part. |
.open_on_hover_value | pub fn open_on_hover_value(&self) -> boolControls whether open on hover value behavior is enabled. |
.delay_value | pub fn delay_value(&self) -> DurationSets the delay value configuration for this part. |
.close_delay_value | pub fn close_delay_value(&self) -> DurationControls whether close delay value behavior is enabled. |
.wired | pub fn wired(mut self, index: usize, focus_handle: FocusHandle) -> Self
Sets the wired configuration for this part. |
.with_contexts | pub fn with_contexts(mut self, parent: MenuContext<P>, child: MenuContext<P>, item_index: usize,) -> Self
Sets the with contexts configuration for this part. |
.style_with_state | pub fn style_with_state(mut self, style: impl Fn(MenuSubmenuTriggerStyleState, Div) -> Div + 'static,) -> Self
Styles the part from its current behavioral state while preserving separation between behavior and visual design. MenuSubmenuTrigger also supports the GPUI traits implemented in its source, such as standard styling or child composition. |
#MenuTrigger
Interactive control that opens, closes, or activates the component.
use base_gpui::menu::MenuTrigger;
MenuTrigger::new()
.id("example-id")
.disabled(true)
.payload(/* payload: P */)
.open_on_hover(true)
.delay(/* delay: Duration */)
.close_delay(/* close_delay: Duration */)
.aria_label("label")
.style_with_state(|/* callback arguments */| { /* handle change */ });
#Builders
| Builder | Signature & description |
|---|---|
.new | pub fn new() -> SelfCreates a MenuTrigger with its default configuration. |
.id | pub fn id(mut self, id: impl Into<ElementId>) -> Self
Sets the stable GPUI element identity. Use a unique value when multiple instances can appear in the same view. |
.disabled | pub fn disabled(mut self, disabled: bool) -> Self
When true, prevents user interaction with this part. |
.payload | pub fn payload(mut self, payload: P) -> Self
Sets the payload configuration for this part. |
.open_on_hover | pub fn open_on_hover(mut self, open_on_hover: bool) -> Self
Controls whether open on hover behavior is enabled. |
.delay | pub fn delay(mut self, delay: Duration) -> Self
Sets the delay before the related transition or interaction begins. |
.close_delay | pub fn close_delay(mut self, close_delay: Duration) -> Self
Sets the delay before an open component closes after the closing interaction. |
.aria_label | pub fn aria_label(mut self, label: impl Into<SharedString>) -> Self
Accessible label announced for the trigger. When set, render the visible trigger text as |
.style_with_state | pub fn style_with_state(mut self, style: impl Fn(MenuTriggerStyleState<P>, Div) -> Div + 'static,) -> Self
Styles the part from its current behavioral state while preserving separation between behavior and visual design. MenuTrigger also supports the GPUI traits implemented in its source, such as standard styling or child composition. |
#MenuPortal
Hosts overlay content outside the normal child layout.
use base_gpui::menu::MenuPortal;
MenuPortal::new()
.keep_mounted(true)
.style_with_state(|/* callback arguments */| { /* handle change */ });
#Builders
| Builder | Signature & description |
|---|---|
.new | pub fn new() -> SelfCreates a MenuPortal with its default configuration. |
.child | pub fn child(mut self, child: impl Into<MenuPortalChild<P>>) -> Self
Adds one typed child to this part. |
.child_any | pub fn child_any(mut self, child: impl IntoElement) -> Self
Adds one arbitrary renderable child to this part. |
.keep_mounted | pub fn keep_mounted(mut self, keep_mounted: bool) -> Self
Keeps the part mounted when inactive or closed so child state can be preserved. |
.style_with_state | pub fn style_with_state(mut self, style: impl Fn(MenuPortalStyleState, Div) -> Div + 'static,) -> Self
Styles the part from its current behavioral state while preserving separation between behavior and visual design. MenuPortal also supports the GPUI traits implemented in its source, such as standard styling or child composition. |
#MenuPositioner
Measures the anchor and positions floating content.
use base_gpui::menu::MenuPositioner;
MenuPositioner::new()
.side("example-id")
.align(/* align: MenuAlign */)
.side_offset("example-id")
.align_offset(/* align_offset: Pixels */)
.collision_padding(/* collision_padding: Pixels */)
.keep_mounted(true)
.keep_mounted_from_portal()
.style_with_state(|/* callback arguments */| { /* handle change */ });
#Builders
| Builder | Signature & description |
|---|---|
.new | pub fn new() -> SelfCreates a MenuPositioner with its default configuration. |
.child | pub fn child(mut self, child: impl Into<MenuPositionerChild<P>>) -> Self
Adds one typed child to this part. |
.child_any | pub fn child_any(mut self, child: impl IntoElement) -> Self
Adds one arbitrary renderable child to this part. |
.side | pub fn side(mut self, side: MenuSide) -> Self
Sets the preferred side of the anchor on which floating content appears. |
.align | pub fn align(mut self, align: MenuAlign) -> Self
Sets floating content alignment along the selected side. |
.side_offset | pub fn side_offset(mut self, side_offset: Pixels) -> Self
Sets the distance between floating content and its anchor. |
.align_offset | pub fn align_offset(mut self, align_offset: Pixels) -> Self
Offsets floating content along its alignment axis. |
.collision_padding | pub fn collision_padding(mut self, collision_padding: Pixels) -> Self
Sets the minimum space retained between floating content and viewport edges. |
.keep_mounted | pub fn keep_mounted(mut self, keep_mounted: bool) -> Self
Keeps the part mounted when inactive or closed so child state can be preserved. |
.keep_mounted_from_portal | pub fn keep_mounted_from_portal(mut self) -> SelfSets the keep mounted from portal configuration for this part. |
.style_with_state | pub fn style_with_state(mut self, style: impl Fn(MenuPositionerStyleState, Div) -> Div + 'static,) -> Self
Styles the part from its current behavioral state while preserving separation between behavior and visual design. MenuPositioner also supports the GPUI traits implemented in its source, such as standard styling or child composition. |
#MenuPopup
Contains the floating interactive content.
use base_gpui::menu::MenuPopup;
MenuPopup::new()
.id("example-id")
.keep_mounted(true)
.style_with_state(|/* callback arguments */| { /* handle change */ });
#Builders
| Builder | Signature & description |
|---|---|
.new | pub fn new() -> SelfCreates a MenuPopup with its default configuration. |
.id | pub fn id(mut self, id: impl Into<ElementId>) -> Self
Sets the stable GPUI element identity. Use a unique value when multiple instances can appear in the same view. |
.child | pub fn child(mut self, child: impl Into<MenuPopupChild<P>>) -> Self
Adds one typed child to this part. |
.child_any | pub fn child_any(mut self, child: impl IntoElement) -> Self
Adds one arbitrary renderable child to this part. |
.keep_mounted | pub fn keep_mounted(mut self, keep_mounted: bool) -> Self
Keeps the part mounted when inactive or closed so child state can be preserved. |
.style_with_state | pub fn style_with_state(mut self, style: impl Fn(MenuPopupStyleState, Div) -> Div + 'static,) -> Self
Styles the part from its current behavioral state while preserving separation between behavior and visual design. MenuPopup also supports the GPUI traits implemented in its source, such as standard styling or child composition. |
#MenuArrow
Optional arrow that visually points toward the overlay anchor.
use base_gpui::menu::MenuArrow;
MenuArrow::new()
.style_with_state(|/* callback arguments */| { /* handle change */ });
#Builders
| Builder | Signature & description |
|---|---|
.new | pub fn new() -> SelfCreates a MenuArrow with its default configuration. |
.style_with_state | pub fn style_with_state(mut self, style: impl Fn(MenuArrowStyleState, Div) -> Div + 'static,) -> Self
Styles the part from its current behavioral state while preserving separation between behavior and visual design. MenuArrow also supports the GPUI traits implemented in its source, such as standard styling or child composition. |
#MenuBackdrop
Covers content behind a modal overlay and handles outside interaction.
use base_gpui::menu::MenuBackdrop;
MenuBackdrop::new()
.keep_mounted(true)
.style_with_state(|/* callback arguments */| { /* handle change */ });
#Builders
| Builder | Signature & description |
|---|---|
.new | pub fn new() -> SelfCreates a MenuBackdrop with its default configuration. |
.keep_mounted | pub fn keep_mounted(mut self, keep_mounted: bool) -> Self
Keeps the part mounted when inactive or closed so child state can be preserved. |
.style_with_state | pub fn style_with_state(mut self, style: impl Fn(MenuBackdropStyleState, Div) -> Div + 'static,) -> Self
Styles the part from its current behavioral state while preserving separation between behavior and visual design. MenuBackdrop also supports the GPUI traits implemented in its source, such as standard styling or child composition. |
#MenuCheckboxItem
Represents one interactive item in the component's collection.
use base_gpui::menu::MenuCheckboxItem;
MenuCheckboxItem::new()
.id("example-id")
.label("label")
.disabled(true)
.close_on_click(true)
.checked(true)
.default_checked(true)
.on_checked_change(|/* callback arguments */| { /* handle change */ })
.style_with_state(|/* callback arguments */| { /* handle change */ });
#Builders
| Builder | Signature & description |
|---|---|
.new | pub fn new() -> SelfCreates a MenuCheckboxItem with its default configuration. |
.id | pub fn id(mut self, id: impl Into<ElementId>) -> Self
Sets the stable GPUI element identity. Use a unique value when multiple instances can appear in the same view. |
.child | pub fn child(mut self, child: impl Into<MenuCheckboxItemChild<P>>) -> Self
Adds one typed child to this part. |
.child_any | pub fn child_any(mut self, child: impl IntoElement) -> Self
Adds one arbitrary renderable child to this part. |
.label | pub fn label(mut self, label: impl Into<SharedString>) -> Self
Sets the label configuration for this part. |
.disabled | pub fn disabled(mut self, disabled: bool) -> Self
When true, prevents user interaction with this part. |
.close_on_click | pub fn close_on_click(mut self, close_on_click: bool) -> Self
Controls whether close on click behavior is enabled. |
.checked | pub fn checked(mut self, checked: bool) -> Self
Sets the checked configuration for this part. |
.default_checked | pub fn default_checked(mut self, default_checked: bool) -> Self
Sets the initial checked for uncontrolled state. |
.on_checked_change | pub fn on_checked_change(mut self, on_checked_change: impl Fn(bool, &mut MenuItemChangeDetails, &mut Window, &mut App) + 'static,) -> Self
Registers a callback invoked when checked change occurs. |
.style_with_state | pub fn style_with_state(mut self, style: impl Fn(MenuCheckboxItemStyleState, Div) -> Div + 'static,) -> Self
Styles the part from its current behavioral state while preserving separation between behavior and visual design. MenuCheckboxItem also supports the GPUI traits implemented in its source, such as standard styling or child composition. |
#MenuCheckboxItemIndicator
Visual indicator for an item's selected or checked state.
use base_gpui::menu::MenuCheckboxItemIndicator;
MenuCheckboxItemIndicator::new()
.keep_mounted(true)
.with_item_facts(true, true, true)
.style_with_state(|/* callback arguments */| { /* handle change */ });
#Builders
| Builder | Signature & description |
|---|---|
.new | pub fn new() -> SelfCreates a MenuCheckboxItemIndicator with its default configuration. |
.keep_mounted | pub fn keep_mounted(mut self, keep_mounted: bool) -> Self
Keeps the part mounted when inactive or closed so child state can be preserved. |
.with_item_facts | pub fn with_item_facts(mut self, checked: bool, highlighted: bool, disabled: bool) -> Self
Sets the with item facts configuration for this part. |
.style_with_state | pub fn style_with_state(mut self, style: impl Fn(MenuCheckboxItemIndicatorStyleState, Div) -> Div + 'static,) -> Self
Styles the part from its current behavioral state while preserving separation between behavior and visual design. MenuCheckboxItemIndicator also supports the GPUI traits implemented in its source, such as standard styling or child composition. |
#MenuGroup
Groups related child parts and coordinates their shared behavior.
use base_gpui::menu::MenuGroup;
MenuGroup::new()
.id("example-id")
.aria_label("label")
.style_with_state(|/* callback arguments */| { /* handle change */ });
#Builders
| Builder | Signature & description |
|---|---|
.new | pub fn new() -> SelfCreates a MenuGroup with its default configuration. |
.id | pub fn id(mut self, id: impl Into<ElementId>) -> Self
Sets the stable GPUI element identity. Use a unique value when multiple instances can appear in the same view. |
.aria_label | pub fn aria_label(mut self, label: impl Into<SharedString>) -> Self
Accessible group label. Defaults to the label registered by a |
.child | pub fn child(mut self, child: impl Into<MenuGroupChild<P>>) -> Self
Adds one typed child to this part. |
.child_any | pub fn child_any(mut self, child: impl IntoElement) -> Self
Adds one arbitrary renderable child to this part. |
.style_with_state | pub fn style_with_state(mut self, style: impl Fn(MenuGroupStyleState, Div) -> Div + 'static,) -> Self
Styles the part from its current behavioral state while preserving separation between behavior and visual design. MenuGroup also supports the GPUI traits implemented in its source, such as standard styling or child composition. |
#MenuGroupLabel
Provides a visible label and associated accessibility semantics.
use base_gpui::menu::MenuGroupLabel;
MenuGroupLabel::new()
.label("label")
.label_value()
.style_with_state(|/* callback arguments */| { /* handle change */ });
#Builders
| Builder | Signature & description |
|---|---|
.new | pub fn new() -> SelfCreates a MenuGroupLabel with its default configuration. |
.label | pub fn label(mut self, label: impl Into<SharedString>) -> Self
Sets the label configuration for this part. |
.label_value | pub fn label_value(&self) -> Option<SharedString>Registered label string, read by the parent group's wiring to source its |
.style_with_state | pub fn style_with_state(mut self, style: impl Fn(MenuGroupLabelStyleState, Div) -> Div + 'static,) -> Self
Styles the part from its current behavioral state while preserving separation between behavior and visual design. MenuGroupLabel also supports the GPUI traits implemented in its source, such as standard styling or child composition. |
#MenuItem
Represents one interactive item in the component's collection.
use base_gpui::menu::MenuItem;
MenuItem::new()
.id("example-id")
.label("label")
.disabled(true)
.close_on_click(true)
.on_click(|/* callback arguments */| { /* handle change */ })
.style_with_state(|/* callback arguments */| { /* handle change */ });
#Builders
| Builder | Signature & description |
|---|---|
.new | pub fn new() -> SelfCreates a MenuItem with its default configuration. |
.id | pub fn id(mut self, id: impl Into<ElementId>) -> Self
Sets the stable GPUI element identity. Use a unique value when multiple instances can appear in the same view. |
.label | pub fn label(mut self, label: impl Into<SharedString>) -> Self
Sets the label configuration for this part. |
.disabled | pub fn disabled(mut self, disabled: bool) -> Self
When true, prevents user interaction with this part. |
.close_on_click | pub fn close_on_click(mut self, close_on_click: bool) -> Self
Controls whether close on click behavior is enabled. |
.on_click | pub fn on_click(mut self, on_click: impl Fn(&mut Window, &mut App) + 'static) -> Self
Registers a callback invoked when click occurs. |
.style_with_state | pub fn style_with_state(mut self, style: impl Fn(MenuItemStyleState, Div) -> Div + 'static,) -> Self
Styles the part from its current behavioral state while preserving separation between behavior and visual design. MenuItem also supports the GPUI traits implemented in its source, such as standard styling or child composition. |
#MenuLinkItem
Represents one interactive item in the component's collection.
use base_gpui::menu::MenuLinkItem;
MenuLinkItem::new()
.id("example-id")
.label("label")
.close_on_click(true)
.on_activate(|/* callback arguments */| { /* handle change */ })
.style_with_state(|/* callback arguments */| { /* handle change */ });
#Builders
| Builder | Signature & description |
|---|---|
.new | pub fn new() -> SelfCreates a MenuLinkItem with its default configuration. |
.id | pub fn id(mut self, id: impl Into<ElementId>) -> Self
Sets the stable GPUI element identity. Use a unique value when multiple instances can appear in the same view. |
.label | pub fn label(mut self, label: impl Into<SharedString>) -> Self
Sets the label configuration for this part. |
.close_on_click | pub fn close_on_click(mut self, close_on_click: bool) -> Self
Controls whether close on click behavior is enabled. |
.on_activate | pub fn on_activate(mut self, on_activate: impl Fn(&mut Window, &mut App) + 'static) -> Self
Registers a callback invoked when activate occurs. |
.style_with_state | pub fn style_with_state(mut self, style: impl Fn(MenuLinkItemStyleState, Div) -> Div + 'static,) -> Self
Styles the part from its current behavioral state while preserving separation between behavior and visual design. MenuLinkItem also supports the GPUI traits implemented in its source, such as standard styling or child composition. |
#MenuRadioGroup
Groups related child parts and coordinates their shared behavior.
use base_gpui::menu::MenuRadioGroup;
MenuRadioGroup::new()
.id("example-id")
.aria_label("label")
.value(None)
.default_value(None)
.disabled(true)
.on_value_change(|/* callback arguments */| { /* handle change */ })
.style_with_state(|/* callback arguments */| { /* handle change */ });
#Builders
| Builder | Signature & description |
|---|---|
.new | pub fn new() -> SelfCreates a MenuRadioGroup with its default configuration. |
.id | pub fn id(mut self, id: impl Into<ElementId>) -> Self
Sets the stable GPUI element identity. Use a unique value when multiple instances can appear in the same view. |
.aria_label | pub fn aria_label(mut self, label: impl Into<SharedString>) -> Self
Accessible group label. Defaults to the label registered by a |
.child | pub fn child(mut self, child: impl Into<MenuRadioGroupChild<P, V>>) -> Self
Adds one typed child to this part. |
.child_any | pub fn child_any(mut self, child: impl IntoElement) -> Self
Adds one arbitrary renderable child to this part. |
.value | pub fn value(mut self, value: Option<V>) -> Self
Sets the current controlled value or the value represented by this part, depending on the part's role. |
.default_value | pub fn default_value(mut self, default_value: Option<V>) -> Self
Sets the initial value for uncontrolled state. Later user changes are retained by the component. |
.disabled | pub fn disabled(mut self, disabled: bool) -> Self
When true, prevents user interaction with this part. |
.on_value_change | pub fn on_value_change(mut self, on_value_change: impl Fn(V, &mut crate::menu::MenuItemChangeDetails, &mut Window, &mut App) + 'static,) -> Self
Registers a callback invoked when value change occurs. |
.style_with_state | pub fn style_with_state(mut self, style: impl Fn(MenuRadioGroupStyleState, Div) -> Div + 'static,) -> Self
Styles the part from its current behavioral state while preserving separation between behavior and visual design. MenuRadioGroup also supports the GPUI traits implemented in its source, such as standard styling or child composition. |
#MenuRadioItem
Represents one interactive item in the component's collection.
use base_gpui::menu::MenuRadioItem;
MenuRadioItem::new()
.prepare_for_group(0, true, None, None)
.wired_index()
.item_value()
.id("example-id")
.value(/* value: V */)
.label("label")
.disabled(true)
.close_on_click(true)
.style_with_state(|/* callback arguments */| { /* handle change */ });
#Builders
| Builder | Signature & description |
|---|---|
.new | pub fn new() -> SelfCreates a MenuRadioItem with its default configuration. |
.prepare_for_group | pub fn prepare_for_group(mut self, group_index: usize, group_disabled: bool, group_value: Option<Option<V>>, on_value_change: Option<MenuValueChangeHandler<V>>,) -> Self
Called by |
.wired_index | pub fn wired_index(&self) -> Option<usize>Sets the wired index configuration for this part. |
.item_value | pub fn item_value(&self) -> Option<&V>Sets the item value configuration for this part. |
.id | pub fn id(mut self, id: impl Into<ElementId>) -> Self
Sets the stable GPUI element identity. Use a unique value when multiple instances can appear in the same view. |
.child | pub fn child(mut self, child: impl Into<MenuRadioItemChild<P, V>>) -> Self
Adds one typed child to this part. |
.child_any | pub fn child_any(mut self, child: impl IntoElement) -> Self
Adds one arbitrary renderable child to this part. |
.value | pub fn value(mut self, value: V) -> Self
Sets the current controlled value or the value represented by this part, depending on the part's role. |
.label | pub fn label(mut self, label: impl Into<SharedString>) -> Self
Sets the label configuration for this part. |
.disabled | pub fn disabled(mut self, disabled: bool) -> Self
When true, prevents user interaction with this part. |
.close_on_click | pub fn close_on_click(mut self, close_on_click: bool) -> Self
Controls whether close on click behavior is enabled. |
.style_with_state | pub fn style_with_state(mut self, style: impl Fn(MenuRadioItemStyleState, Div) -> Div + 'static,) -> Self
Styles the part from its current behavioral state while preserving separation between behavior and visual design. MenuRadioItem also supports the GPUI traits implemented in its source, such as standard styling or child composition. |
#MenuRadioItemIndicator
Visual indicator for an item's selected or checked state.
use base_gpui::menu::MenuRadioItemIndicator;
MenuRadioItemIndicator::new()
.keep_mounted(true)
.with_item_facts(true, true, true)
.style_with_state(|/* callback arguments */| { /* handle change */ });
#Builders
| Builder | Signature & description |
|---|---|
.new | pub fn new() -> SelfCreates a MenuRadioItemIndicator with its default configuration. |
.keep_mounted | pub fn keep_mounted(mut self, keep_mounted: bool) -> Self
Keeps the part mounted when inactive or closed so child state can be preserved. |
.with_item_facts | pub fn with_item_facts(mut self, checked: bool, highlighted: bool, disabled: bool) -> Self
Sets the with item facts configuration for this part. |
.style_with_state | pub fn style_with_state(mut self, style: impl Fn(MenuRadioItemIndicatorStyleState, Div) -> Div + 'static,) -> Self
Styles the part from its current behavioral state while preserving separation between behavior and visual design. MenuRadioItemIndicator also supports the GPUI traits implemented in its source, such as standard styling or child composition. |
#MenuSeparator
Visual separator between neighboring items or groups.
use base_gpui::menu::MenuSeparator;
MenuSeparator::new()
.orientation(/* orientation: SeparatorOrientation */)
.style_with_state(|/* callback arguments */| { /* handle change */ });
#Builders
| Builder | Signature & description |
|---|---|
.new | pub fn new() -> SelfCreates a MenuSeparator with its default configuration. |
.orientation | pub fn orientation(mut self, orientation: SeparatorOrientation) -> Self
Sets the component's horizontal or vertical orientation and corresponding keyboard behavior. |
.style_with_state | pub fn style_with_state(mut self, style: impl Fn(SeparatorStyleState, gpui::Div) -> gpui::Div + 'static,) -> Self
Styles the part from its current behavioral state while preserving separation between behavior and visual design. MenuSeparator also supports the GPUI traits implemented in its source, such as standard styling or child composition. |
#Accessibility
Keyboard interaction and accessibility semantics are implemented by the component, independently of visual styling. Known limitations caused by missing GPUI accessibility primitives are documented in the module source and are not silently approximated.
The menu family sets Role::Button/Role::MenuItem on triggers, Role::Menu on popups, Role::MenuItem{,CheckBox,Radio} on items, and Role::Group on (radio) groups. Backdrop, arrow, indicators, group label, portal, positioner, and the structural roots carry no role and stay out of the accessibility tree (mirroring Base UI's role="presentation" / aria-hidden). Gaps in the pinned gpui revision, omitted rather than faked (blocked on upstream builders): - aria-haspopup="menu" / aria-controls on triggers and submenu triggers: aria_expanded plus the popup's Role::Menu stand in. - aria-labelledby: replaced by literal-string .aria_label(...) sourced from the registered group-label metadata. - disabled/aria-disabled: disabled parts are inert (withheld tab stops, activation no-ops) but the disabled state is not announced.
#Stability
Base GPUI is pre-1.0. Builder names and state types may evolve as GPUI and this port mature.