mapbox-gl-contextmenu - v1.6.0
    Preparing search index...

    Class ContextMenuSubmenu

    A context menu item that displays a submenu when hovered or clicked.

    Submenus extend regular menu items and can contain their own menu items, shown in a child menu. They display a chevron icon to indicate that child items are available. Submenus open on hover (with a delay) or on click, and can be navigated using keyboard controls.

    const directionsSubmenu = new ContextMenuSubmenu({
    label: "Get directions",
    icon: "fa-solid fa-route"
    });

    const toHere = new ContextMenuItem({
    label: "Directions to here",
    icon: "fa-solid fa-arrow-right-to-arc"
    });
    toHere.on("click", ({ lngLat }) => {
    // Handle click
    });

    directionsSubmenu.addItem(toHere);
    menu.addItem(directionsSubmenu);

    Hierarchy (View Summary)

    Index

    Constructors

    • Creates a new submenu item.

      Parameters

      • options: ContextMenuSubmenuOptions

        Configuration options for the submenu item.

        Configuration options for creating a context menu submenu. Extends ContextMenuItemOptions with submenu-specific timing options.

        • OptionalbuttonClassName?: string

          Custom CSS class name for the menu item's <button> element.

        • OptionalclassName?: string

          Custom CSS class name for the menu item's <li> element.

        • Optionaldisabled?: boolean

          Whether the menu item is disabled. Defaults to false.

        • Optionalend?: Content

          Content to display after the label.

        • OptionalhideDelay?: number

          Delay in milliseconds before hiding the submenu when mouse leaves. Defaults to 200.

        • label: string

          The text label to display.

        • OptionalshowDelay?: number

          Delay in milliseconds before showing the submenu on hover. Defaults to 300.

        • Optionalstart?: Content

          Content to display before the label (e.g., an icon element).

      Returns ContextMenuSubmenu

    Accessors

    Methods

    • Adds a menu item to the submenu.

      Parameters

      • item: MenuItem

        The menu item to add. Can be a ContextMenuItem or ContextMenuSeparator.

      Returns this

      The submenu instance for method chaining.

    • Fires an event, calling all registered handlers for the event type.

      Type Parameters

      • K extends keyof ContextMenuItemEvents

      Parameters

      • type: K

        The event type to fire.

      • event: ContextMenuItemEvents[K]

        The event data to pass to the handlers.

      Returns this

      The instance for method chaining.

    • Inserts a menu item into the submenu at the specified index.

      Parameters

      • index: number

        The index at which to insert the item. If the index is out of bounds, the item will be added at the end.

      • item: MenuItem

        The menu item to insert. Can be a ContextMenuItem or ContextMenuSeparator.

      Returns this

      The submenu instance for method chaining.

    • Checks whether there are any registered handlers for the specified event type.

      Type Parameters

      • K extends keyof ContextMenuItemEvents

      Parameters

      • type: K

        The event type to check.

      Returns boolean

      true if there are registered handlers for the event type, false otherwise.

    • Unregisters an event handler for the specified event type.

      Type Parameters

      • K extends keyof ContextMenuItemEvents

      Parameters

      • type: K

        The event type to stop listening for.

      • handler: EventHandler<ContextMenuItemEvents[K]>

        The function to remove from the event handlers.

      Returns this

      The instance for method chaining.

    • Registers an event handler for the specified event type.

      Type Parameters

      • K extends keyof ContextMenuItemEvents

      Parameters

      • type: K

        The event type to listen for.

      • handler: EventHandler<ContextMenuItemEvents[K]>

        The function to call when the event is fired.

      Returns this

      The instance for method chaining.