Menu
可完全组合的菜单,支持子菜单、分组、链接、复选项和单选项。
正在加载交互演示…
let menu = PopoverMenu::new("actions", &state);
menu.root().child(menu.trigger().child("Actions"))#导入
从 quickgui 导入 PopoverMenu。
use quickgui::*;#用法
let menu = PopoverMenu::new("actions", &state);
menu.root().child(menu.trigger().child("Actions"))#结构
PopoverMenu::rootPopoverMenu::triggerPopoverMenu::portalPopoverMenu::backdropPopoverMenu::positionerPopoverMenu::popupPopoverMenu::arrowPopoverMenu::itemPopoverMenu::link_itemPopoverMenu::submenu_rootPopoverMenu::submenu_triggerPopoverMenu::groupPopoverMenu::group_labelPopoverMenu::radio_groupPopoverMenu::radio_itemPopoverMenu::radio_item_indicatorPopoverMenu::checkbox_itemPopoverMenu::checkbox_item_indicatorPopoverMenu::separator
#API 参考
展开条目查看说明和完整签名。短横线表示声明中未记录默认值。
PopoverMenu
查看源码pub fn new(items: impl IntoIterator<Item = PopoverMenuItem>) -> Result<Self, PopoverMenuError>itemspub fn items(&self) -> &[PopoverMenuItem]—
active_indexpub const fn active_index(&self) -> Option<usize>—
active_itempub fn active_item(&self) -> Option<&PopoverMenuItem>—
loops_focuspub const fn loops_focus(&self) -> bool—
loop_focuspub const fn loop_focus(mut self, enabled: bool) -> Self—
orientation_valuepub const fn orientation_value(&self) -> MenuOrientation—
The axis this menu's roving highlight moves along, Base UI's Root `orientation`.
pub const fn orientation_value(&self) -> MenuOrientation查看源码orientationpub const fn orientation(mut self, orientation: MenuOrientation) -> Self—
Move the roving highlight along the other axis, Base UI's Root `orientation`. A horizontal menu installs [`POPOVER_MENU_HORIZONTAL_KEY_CONTEXT`] instead of [`POPOVER_MENU_KEY_CONTEXT`], so Left and Right move between top-level triggers and Down opens the highlighted submenu. Nothing else about the model changes.
pub const fn orientation(mut self, orientation: MenuOrientation) -> Self查看源码set_orientationpub const fn set_orientation(&mut self, orientation: MenuOrientation) -> bool—
Replace the orientation in place, reporting whether it changed.
pub const fn set_orientation(&mut self, orientation: MenuOrientation) -> bool查看源码radio_valuepub fn radio_value(&self, group: impl Into<ElementId>) -> Option<ElementId>—
The item currently checked in one radio group, Base UI's `Menu.RadioGroup` `value`.
pub fn radio_value(&self, group: impl Into<ElementId>) -> Option<ElementId>查看源码set_radio_valuepub fn set_radio_value( &mut self, group: impl Into<ElementId>, value: impl Into<ElementId>, ) -> bool—
Check exactly one item in a radio group, Base UI's `Menu.RadioGroup` `onValueChange`. Every other item in the group is unchecked in the same update, so a group can never retain two checked values. Returns whether anything changed; an item ID that is not a radio item in `group` changes nothing.
pub fn set_radio_value( &mut self, group: impl Into<ElementId>, value: impl Into<ElementId>, ) -> bool查看源码set_itemspub fn set_items( &mut self, items: impl IntoIterator<Item = PopoverMenuItem>, ) -> Result<bool, PopoverMenuError>—
Atomically replace the menu contents while preserving the highlighted stable ID.
pub fn set_items( &mut self, items: impl IntoIterator<Item = PopoverMenuItem>, ) -> Result<bool, PopoverMenuError>查看源码highlightpub fn highlight(&mut self, index: usize) -> bool—
unhighlightpub fn unhighlight(&mut self, index: usize) -> bool—
Drop the highlight from `index` when the pointer leaves it, returning whether it changed. A native menu shows no highlighted row once the pointer has left the surface, so a row the pointer lit up goes dark when it leaves; a highlight the keyboard moved elsewhere in the meantime is left alone.
pub fn unhighlight(&mut self, index: usize) -> bool查看源码select_previouspub fn select_previous(&mut self) -> bool—
select_nextpub fn select_next(&mut self) -> bool—
select_firstpub fn select_first(&mut self) -> bool—
select_lastpub fn select_last(&mut self) -> bool—
typeaheadpub fn typeahead(&mut self, value: &str, now: Instant) -> bool—
Update bounded typeahead state and highlight the next prefix match. `now` is supplied by the caller so deterministic tests do not depend on wall-clock sleeps. The return value reports whether the highlighted item changed.
pub fn typeahead(&mut self, value: &str, now: Instant) -> bool查看源码activate_activepub fn activate_active(&mut self) -> Option<PopoverMenuActivation>—
Configures activate active for this part.
pub fn activate_active(&mut self) -> Option<PopoverMenuActivation>查看源码activatepub fn activate(&mut self, index: usize) -> Option<PopoverMenuActivation>—
Configures activate for this part.
pub fn activate(&mut self, index: usize) -> Option<PopoverMenuActivation>查看源码item_statepub fn item_state(&self, index: usize) -> Option<PopoverMenuItemState>—
Configures item state for this part.
pub fn item_state(&self, index: usize) -> Option<PopoverMenuItemState>查看源码item_element_idpub fn item_element_id( &self, menu_id: impl Into<ElementId>, index: usize, ) -> Option<ElementId>—
Resolve the retained element identity for an interactive item or structural group label. Interactive identity follows the application's stable item ID. A group label has no command identity, so its accessibility-only identity is derived from the menu root and bounded structural index. Separators intentionally remain anonymous.
pub fn item_element_id( &self, menu_id: impl Into<ElementId>, index: usize, ) -> Option<ElementId>查看源码item_render_statepub fn item_render_state(&self, index: usize, submenu_open: bool) -> Option<MenuItemPartState>—
The Base UI-named render snapshot for one row. Returns `None` for an index outside the retained model. `submenu_open` reports whether this row's submenu is currently mounted; it is ignored for rows that have none.
pub fn item_render_state(&self, index: usize, submenu_open: bool) -> Option<MenuItemPartState>查看源码PopoverMenu::root_with
查看源码pub fn root_with(&self, id: impl Into<ElementId>, root: Element) -> ElementDecorate a caller-owned menu root with focus, keyboard, drag-region, and accessibility semantics without adding any appearance.
PopoverMenu::root
查看源码pub fn root(&self, id: impl Into<ElementId>) -> ElementCreate the unstyled root part. Use [`Self::root_with`] to supply an existing element.
PopoverMenu::item_with
查看源码pub fn item_with( &self, menu_id: impl Into<ElementId>, index: usize, item_root: Element, ) -> Option<Element>Decorate one caller-owned row with its exact menu-item semantics and stable derived ID.
PopoverMenu::item
查看源码pub fn item(&self, menu_id: impl Into<ElementId>, index: usize) -> Option<Element>Create the unstyled item part. Use [`Self::item_with`] to supply an existing element.
PopoverMenu::group_with
查看源码pub fn group_with(group: Element) -> ElementDecorate an application-composed wrapper around a related item group.
PopoverMenu::group
查看源码pub fn group() -> ElementCreate the unstyled group part. Use [`Self::group_with`] to supply an existing element.
PopoverMenu::labeled_group_with
查看源码pub fn labeled_group_with( &self, menu_id: impl Into<ElementId>, label_index: usize, group: Element, ) -> Option<Element>Decorate a caller-composed item group and name it from one mounted group-label row. Returns `None` when `label_index` is not a group label. The caller owns visual nesting and layout; this helper adds only the native group role and mounted `labelled-by` relationship.
PopoverMenu::labeled_group
查看源码pub fn labeled_group( &self, menu_id: impl Into<ElementId>, label_index: usize, ) -> Option<Element>Create the unstyled labeled group part. Use [`Self::labeled_group_with`] to supply an existing element.
PopoverMenu::checkbox_item_with
查看源码pub fn checkbox_item_with( &self, menu_id: impl Into<ElementId>, index: usize, item_root: Element, ) -> Option<Element>Decorate a checkbox row, Base UI's `Menu.CheckboxItem`. This is the kind-checked Base UI-named alias of [`Self::item_with`]: it returns `None` when `index` is not a checkbox row, so a composition that renders parts by name cannot silently mount the wrong semantics.
PopoverMenu::checkbox_item
查看源码pub fn checkbox_item(&self, menu_id: impl Into<ElementId>, index: usize) -> Option<Element>Create the unstyled checkbox item part. Use [`Self::checkbox_item_with`] to supply an existing element.
PopoverMenu::radio_item_with
查看源码pub fn radio_item_with( &self, menu_id: impl Into<ElementId>, index: usize, item_root: Element, ) -> Option<Element>Decorate a radio row, Base UI's `Menu.RadioItem`.
PopoverMenu::radio_item
查看源码pub fn radio_item(&self, menu_id: impl Into<ElementId>, index: usize) -> Option<Element>Create the unstyled radio item part. Use [`Self::radio_item_with`] to supply an existing element.
PopoverMenu::link_item_with
查看源码pub fn link_item_with( &self, menu_id: impl Into<ElementId>, index: usize, item_root: Element, ) -> Option<Element>Decorate a link row, Base UI's `Menu.LinkItem`.
PopoverMenu::link_item
查看源码pub fn link_item(&self, menu_id: impl Into<ElementId>, index: usize) -> Option<Element>Create the unstyled link item part. Use [`Self::link_item_with`] to supply an existing element.
PopoverMenu::submenu_trigger_with
查看源码pub fn submenu_trigger_with( &self, menu_id: impl Into<ElementId>, index: usize, open: bool, item_root: Element, ) -> Option<Element>Decorate a submenu row, Base UI's `Menu.SubmenuTrigger`. The row already declares `has-popup` and `menuitem`; `open` adds the expanded state that Base UI publishes as `data-popup-open` while the child level is mounted.
PopoverMenu::submenu_trigger
查看源码pub fn submenu_trigger( &self, menu_id: impl Into<ElementId>, index: usize, open: bool, ) -> Option<Element>Create the unstyled submenu trigger part. Use [`Self::submenu_trigger_with`] to supply an existing element.
PopoverMenu::separator_with
查看源码pub fn separator_with( &self, menu_id: impl Into<ElementId>, index: usize, item_root: Element, ) -> Option<Element>Decorate a separator row, Base UI's `Menu.Separator`.
PopoverMenu::separator
查看源码pub fn separator(&self, menu_id: impl Into<ElementId>, index: usize) -> Option<Element>Create the unstyled separator part. Use [`Self::separator_with`] to supply an existing element.
PopoverMenu::group_label_with
查看源码pub fn group_label_with( &self, menu_id: impl Into<ElementId>, index: usize, item_root: Element, ) -> Option<Element>Decorate a group-label row, Base UI's `Menu.GroupLabel`.
PopoverMenu::group_label
查看源码pub fn group_label(&self, menu_id: impl Into<ElementId>, index: usize) -> Option<Element>Create the unstyled group label part. Use [`Self::group_label_with`] to supply an existing element.
PopoverMenu::radio_group_with
查看源码pub fn radio_group_with(group: Element) -> ElementDecorate a caller-composed radio group, Base UI's `Menu.RadioGroup`. The group carries the native radio-group role so assistive technology reports "one of three" for its items. Membership itself stays in the model: every row built with [`PopoverMenuItem::radio`] names the group it belongs to, and [`Self::set_radio_value`] keeps exactly one of them checked.
PopoverMenu::radio_group
查看源码pub fn radio_group() -> ElementCreate the unstyled radio group part. Use [`Self::radio_group_with`] to supply an existing element.
PopoverMenu::labeled_radio_group_with
查看源码pub fn labeled_radio_group_with( &self, menu_id: impl Into<ElementId>, label_index: usize, group: Element, ) -> Option<Element>Decorate a caller-composed radio group and name it from one mounted group-label row. Returns `None` when `label_index` is not a group label.
PopoverMenu::labeled_radio_group
查看源码pub fn labeled_radio_group( &self, menu_id: impl Into<ElementId>, label_index: usize, ) -> Option<Element>Create the unstyled labeled radio group part. Use [`Self::labeled_radio_group_with`] to supply an existing element.
PopoverMenu::checkbox_item_indicator_with
查看源码pub fn checkbox_item_indicator_with(indicator: Element) -> ElementDecorate a caller-owned checkbox indicator, Base UI's `Menu.CheckboxItemIndicator`. The indicator is decoration: the row it sits in already carries the checked state, so mounting a second announcement would make assistive technology read the value twice. Mount it only while the row is checked, exactly as Base UI does.
PopoverMenu::checkbox_item_indicator
查看源码pub fn checkbox_item_indicator() -> ElementCreate the unstyled checkbox item indicator part. Use [`Self::checkbox_item_indicator_with`] to supply an existing element.
PopoverMenu::radio_item_indicator_with
查看源码pub fn radio_item_indicator_with(indicator: Element) -> ElementDecorate a caller-owned radio indicator, Base UI's `Menu.RadioItemIndicator`.
PopoverMenu::radio_item_indicator
查看源码pub fn radio_item_indicator() -> ElementCreate the unstyled radio item indicator part. Use [`Self::radio_item_indicator_with`] to supply an existing element.
PopoverMenu::element
查看源码pub fn element<V, Render, Dismiss>( &self, cx: &mut ViewContext<'_, V>, id: impl Into<ElementId>, access: fn(&mut V) -> &mut PopoverMenu, root: Element, render_item: Render, dismiss: Dismiss, ) -> Element where V: 'static, Render: Fn(&PopoverMenuItem, PopoverMenuItemState) -> Element, Dismiss: Fn(&mut V, &mut EventContext) + Clone + 'static,Build the complete unstyled interaction layer for one menu level. `render_item` owns all row geometry, colors, indicators, icons, and typography. Commands dispatch through the popover owner's ordinary typed-action path before `dismiss` runs.
PopoverMenu::element_with_submenus
查看源码pub fn element_with_submenus<V, Render, Dismiss, OpenSubmenu>( &self, cx: &mut ViewContext<'_, V>, id: impl Into<ElementId>, access: fn(&mut V) -> &mut PopoverMenu, root: Element, render_item: Render, dismiss: Dismiss, open_submenu: OpenSubmenu, ) -> Element where V: 'static, Render: Fn(&PopoverMenuItem, PopoverMenuItemState) -> Element, Dismiss: Fn(&mut V, &mut EventContext) + Clone + 'static, OpenSubmenu: Fn(&mut V, ElementId, PopoverMenu, &mut EventContext) + Clone + 'static,Build the complete unstyled interaction layer and expose submenu activation to the owner.
PopoverMenu::element_with_submenus_and_hover
查看源码pub fn element_with_submenus_and_hover<V, Render, Dismiss, OpenSubmenu, HoverItem>( &self, cx: &mut ViewContext<'_, V>, id: impl Into<ElementId>, access: fn(&mut V) -> &mut PopoverMenu, root: Element, render_item: Render, dismiss: Dismiss, open_submenu: OpenSubmenu, hover_item: HoverItem, ) -> Element where V: 'static, Render: Fn(&PopoverMenuItem, PopoverMenuItemState) -> Element, Dismiss: Fn(&mut V, &mut EventContext) + Clone + 'static, OpenSubmenu: Fn(&mut V, ElementId, PopoverMenu, &mut EventContext) + Clone + 'static, HoverItem: Fn(&mut V, usize, bool, &mut EventContext) + Clone + 'static,Build the complete unstyled interaction layer with owner-controlled hover behavior. This is the native-overflow adapter hook for delayed submenu opening and menu-aim safe corridors. `hover_item` receives entry and exit transitions for enabled interactive rows; it owns highlighting and any delayed work. The ordinary [`Self::element_with_submenus`] method preserves immediate-highlight behavior without allocating a timer.
