material-web/menu/sub-menu-item.ts
2023-02-02 15:34:35 -08:00

72 lines
2.2 KiB
TypeScript

/**
* @license
* Copyright 2023 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import {customElement} from 'lit/decorators.js';
import {styles as listItemStyles} from '../list/lib/listitem/list-item-styles.css.js';
import {styles as privateProps} from './lib/menuitem/menu-item-private-styles.css.js';
import {styles} from './lib/menuitem/menu-item-styles.css.js';
import {SubMenuItem} from './lib/submenuitem/sub-menu-item.js';
export {ListItem} from '../list/lib/listitem/list-item.js';
export {CloseMenuEvent, DeactivateItemsEvent, MenuItem} from './lib/shared.js';
declare global {
interface HTMLElementTagNameMap {
'md-sub-menu-item': MdSubMenuItem;
}
}
/**
* @summary Menus display a list of choices on a temporary surface.
*
* @description
* Menu items are the selectable choices within the menu. Menu items must
* implement the `MenuItem` interface and also have the `md-menu-item`
* attribute. Additionally menu items are list items so they must also have the
* `md-list-item` attribute.
*
* Menu items can control a menu by selectively firing the `close-menu` and
* `deselect-items` events.
*
* This menu item will open a sub-menu that is slotted in the `submenu` slot.
* Additionally, the containing menu must either have `has-overflow` or `fixed`
* set to `true` in order to display the containing menu properly.
*
* @example
* ```html
* <div style="position:relative;">
* <button
* class="anchor"
* ${ref(anchorRef)}
* @click=${() => this.menuRef.value.show()}>
* Click to open menu
* </button>
* <!--
* `has-overflow` is required when using a submenu which overflows the
* menu's contents
* -->
* <md-menu has-overflow ${ref(menuRef)} ${(el) => el.anchor =
* anchorRef.value}> <md-menu-item header="This is a header"></md-menu-item>
* <md-sub-menu-item header="this is a submenu item">
* <md-menu slot="submenu">
* <md-menu-item
* header="This is an item inside a submenu"></md-menu-item>
* </md-menu>
* </md-sub-menu>
* </md-menu>
* </div>
* ```
*
* @final
* @suppress {visibility}
*/
@customElement('md-sub-menu-item')
export class MdSubMenuItem extends SubMenuItem {
static override styles = [privateProps, listItemStyles, styles];
}