import { LitElement, html } from 'lit'; import { customElement, property, query } from 'lit/decorators.js'; import { classMap } from 'lit/directives/class-map.js'; import styles from './menu-item.styles'; import '~/components/icon/icon'; import { watch } from '~/internal/watch'; /** * @since 2.0 * @status stable * * @dependency sl-icon * * @slot - The menu item's label. * @slot prefix - Used to prepend an icon or similar element to the menu item. * @slot suffix - Used to append an icon or similar element to the menu item. * * @csspart base - The component's base wrapper. * @csspart checked-icon - The container that wraps the checked icon. * @csspart prefix - The prefix container. * @csspart label - The menu item label. * @csspart suffix - The suffix container. */ @customElement('sl-menu-item') export default class SlMenuItem extends LitElement { static styles = styles; @query('.menu-item') menuItem: HTMLElement; /** Draws the item in a checked state. */ @property({ type: Boolean, reflect: true }) checked = false; /** A unique value to store in the menu item. This can be used as a way to identify menu items when selected. */ @property() value = ''; /** Draws the menu item in a disabled state. */ @property({ type: Boolean, reflect: true }) disabled = false; firstUpdated() { this.setAttribute('role', 'menuitem'); } @watch('checked') handleCheckedChange() { this.setAttribute('aria-checked', this.checked ? 'true' : 'false'); } @watch('disabled') handleDisabledChange() { this.setAttribute('aria-disabled', this.disabled ? 'true' : 'false'); } render() { return html`
`; } } declare global { interface HTMLElementTagNameMap { 'sl-menu-item': SlMenuItem; } }