pub fn menu_provider() -> MenuProviderBuilderExpand description
§menu_provider
Provides a Material Design 3 menu overlay anchored to a rectangle.
§Usage
Wrap page content and show contextual or overflow actions aligned to a trigger element.
§Parameters
anchor— current anchor relative to the provider; takes precedence over the controller’s saved anchor and can follow layout changeswindow_anchor— observed trigger coordinates, including ancestor transforms; takes precedence overanchorplacement— how the menu aligns relative to its anchorgrouped— render separatemenu_groupsurfaces on a transparent panelcolor_style— standard or vibrant colors, inherited by groups and itemsoffset— x/y distance away from the anchor on the expansion axis, and a shift on the other axismodifier— extra layout modifiers for the menu containermax_height— optional maximum menu height before scrollingshape— optional fixed panel shape; default corners respond to hover and keyboard focuselevation— menu elevation levelcontainer_color— background color of the menu panelscrim_color— background color behind the menuclose_on_background— whether outside clicks dismiss the menuclose_on_escape— whether Escape dismisses the menuon_dismiss— optional callback before dismissalis_open— whether the menu is currently visiblecontroller— optional external controller for open state and anchorfocus_restorer_fallback— optional fallback focus target on dismissmain_content— optional content rendered behind the menumenu_content— optional menu content slot
§Examples
use tessera_components::{
menus::{MenuAnchor, MenuController, MenuPlacement, menu_item, menu_provider},
text::text,
};
use tessera_ui::{Dp, remember};
let menu = remember(MenuController::new);
menu.with_mut(MenuController::open);
assert!(menu.with(MenuController::is_open));
menu_provider()
.anchor(MenuAnchor::from_dp(
(Dp(16.0), Dp(16.0)),
(Dp(80.0), Dp(40.0)),
))
.placement(MenuPlacement::BelowStart)
.controller(menu)
.main_content(|| {
text("Main content");
})
.menu_content(|menu| {
menu_item().menu(menu).label("Edit").on_click(|| {});
});