Skip to main content

menu_provider

Function menu_provider 

Source
pub fn menu_provider() -> MenuProviderBuilder
Expand description

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 changes
  • window_anchor — observed trigger coordinates, including ancestor transforms; takes precedence over anchor
  • placement — how the menu aligns relative to its anchor
  • grouped — render separate menu_group surfaces on a transparent panel
  • color_style — standard or vibrant colors, inherited by groups and items
  • offset — x/y distance away from the anchor on the expansion axis, and a shift on the other axis
  • modifier — extra layout modifiers for the menu container
  • max_height — optional maximum menu height before scrolling
  • shape — optional fixed panel shape; default corners respond to hover and keyboard focus
  • elevation — menu elevation level
  • container_color — background color of the menu panel
  • scrim_color — background color behind the menu
  • close_on_background — whether outside clicks dismiss the menu
  • close_on_escape — whether Escape dismisses the menu
  • on_dismiss — optional callback before dismissal
  • is_open — whether the menu is currently visible
  • controller — optional external controller for open state and anchor
  • focus_restorer_fallback — optional fallback focus target on dismiss
  • main_content — optional content rendered behind the menu
  • menu_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(|| {});
    });