UNPKG

@playcanvas/pcui

Version:

User interface component library for the web

71 lines (70 loc) 2.3 kB
import { Container, ContainerArgs } from '../Container'; import { Element, IFocusable } from '../Element'; import { MenuItem, MenuItemArgs } from '../MenuItem'; /** * The arguments for the {@link Menu} constructor. */ interface MenuArgs extends ContainerArgs { /** * An array of {@link MenuItemArgs}. If these are passed then new MenuItems will be created * and appended to the menu. */ items?: MenuItemArgs[]; /** * Sets whether this {@link Menu} is hidden. Defaults to `true`. */ hidden?: boolean; /** * Sets the tabIndex of the {@link Menu}. Defaults to 1. */ tabIndex?: number; } /** * A Menu is a list of {@link MenuItem}s which can contain child MenuItems. Useful to show context * menus and nested menus. Note that a Menu must be appended to the root Element and then * positioned accordingly. */ declare class Menu extends Container implements IFocusable { protected _containerMenuItems: Container; /** * Creates a new Menu. * * @param args - The arguments. */ constructor(args?: Readonly<MenuArgs>); destroy(): void; protected _onAppendChild(element: Element): void; protected _onRemoveChild(element: Element): void; protected _onClickMenu: (evt: MouseEvent) => void; protected _onFocus: (evt: FocusEvent) => void; protected _onBlur: (evt: FocusEvent) => void; protected _filterMenuItems(item: MenuItem): void; protected _onShowMenu(): void; protected _onKeyDown: (evt: KeyboardEvent) => void; protected _limitSubmenuAtScreenEdges(item: MenuItem): void; focus(): void; blur(): void; /** * Positions the top-left corner of the menu at the specified coordinates. * * @param x - The x coordinate. * @param y - The y coordinate. * @example * ```ts * // open a context menu at the mouse position * window.addEventListener('contextmenu', (event) => { * event.stopPropagation(); * event.preventDefault(); * * menu.hidden = false; * menu.position(event.clientX, event.clientY); * }); * ``` */ position(x: number, y: number): void; /** * Remove all the current menu items from the menu. */ clear(): void; } export { Menu, MenuArgs };