mirror of
https://github.com/material-components/material-web.git
synced 2024-10-27 06:04:44 +03:00
b85b57fa79
Fixes #4817 We need to communicate between components when an event has been handled (e.g. keyboard navigation or clicking). This CL focuses on listening to `defaultPrevented` in order to communicate that something was handled. We also have to patch ripple on submenu to make sure that the ripple isn't triggered. PiperOrigin-RevId: 561748634
76 lines
2.2 KiB
TypeScript
76 lines
2.2 KiB
TypeScript
/**
|
|
* @license
|
|
* Copyright 2022 Google LLC
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
import {customElement} from 'lit/decorators.js';
|
|
|
|
import {styles as forcedColors} from './internal/forced-colors-styles.css.js';
|
|
import {Menu} from './internal/menu.js';
|
|
import {styles} from './internal/menu-styles.css.js';
|
|
|
|
export {ListItem} from '../list/internal/listitem/list-item.js';
|
|
export {Corner, DefaultFocusState} from './internal/menu.js';
|
|
export {CloseMenuEvent, MenuItem} from './internal/shared.js';
|
|
|
|
declare global {
|
|
interface HTMLElementTagNameMap {
|
|
'md-menu': MdMenu;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @summary Menus display a list of choices on a temporary surface.
|
|
*
|
|
* @description
|
|
* Menus appear when users interact with a button, action, or other control.
|
|
*
|
|
* They can be opened from a variety of elements, most commonly icon buttons,
|
|
* buttons, and text fields.
|
|
*
|
|
* md-menu listens for the `close-menu` and `deselect-items` events.
|
|
*
|
|
* - `close-menu` closes the menu when dispatched from a child element.
|
|
* - `deselect-items` deselects all of its immediate menu-item children.
|
|
*
|
|
* @example
|
|
* ```html
|
|
* <div style="position:relative;">
|
|
* <!--
|
|
* The menu ref in this example can be achieved by any method such as the
|
|
* preferred `@query` decorator in Lit or a ref in React.
|
|
* -->
|
|
* <button
|
|
* id="anchor"
|
|
* @click=${() => this.menuRef.value.show()}>
|
|
* Click to open menu
|
|
* </button>
|
|
* <!--
|
|
* `has-overflow` is required when using a submenu which overflows the
|
|
* menu's contents.
|
|
*
|
|
* Additionally, `anchor` ingests an idref which do not pass through shadow
|
|
* roots. You can also set `.anchorElement` to an element reference if
|
|
* necessary.
|
|
* -->
|
|
* <md-menu anchor="anchor" has-overflow ${ref(menuRef)}>
|
|
* <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-item>
|
|
* </md-menu>
|
|
* </div>
|
|
* ```
|
|
*
|
|
* @final
|
|
* @suppress {visibility}
|
|
*/
|
|
@customElement('md-menu')
|
|
export class MdMenu extends Menu {
|
|
static override styles = [styles, forcedColors];
|
|
}
|