@m3e/menu 1.0.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +315 -0
- package/cem.config.mjs +16 -0
- package/demo/index.html +112 -0
- package/dist/css-custom-data.json +362 -0
- package/dist/custom-elements.json +1590 -0
- package/dist/html-custom-data.json +106 -0
- package/dist/index.js +1274 -0
- package/dist/index.js.map +1 -0
- package/dist/index.min.js +276 -0
- package/dist/index.min.js.map +1 -0
- package/dist/src/MenuElement.d.ts +143 -0
- package/dist/src/MenuElement.d.ts.map +1 -0
- package/dist/src/MenuItemCheckboxElement.d.ts +76 -0
- package/dist/src/MenuItemCheckboxElement.d.ts.map +1 -0
- package/dist/src/MenuItemElement.d.ts +113 -0
- package/dist/src/MenuItemElement.d.ts.map +1 -0
- package/dist/src/MenuItemElementBase.d.ts +21 -0
- package/dist/src/MenuItemElementBase.d.ts.map +1 -0
- package/dist/src/MenuItemGroupElement.d.ts +28 -0
- package/dist/src/MenuItemGroupElement.d.ts.map +1 -0
- package/dist/src/MenuItemRadioElement.d.ts +77 -0
- package/dist/src/MenuItemRadioElement.d.ts.map +1 -0
- package/dist/src/MenuPosition.d.ts +5 -0
- package/dist/src/MenuPosition.d.ts.map +1 -0
- package/dist/src/MenuTriggerElement.d.ts +86 -0
- package/dist/src/MenuTriggerElement.d.ts.map +1 -0
- package/dist/src/index.d.ts +8 -0
- package/dist/src/index.d.ts.map +1 -0
- package/eslint.config.mjs +13 -0
- package/package.json +48 -0
- package/rollup.config.js +32 -0
- package/src/MenuElement.ts +449 -0
- package/src/MenuItemCheckboxElement.ts +178 -0
- package/src/MenuItemElement.ts +210 -0
- package/src/MenuItemElementBase.ts +158 -0
- package/src/MenuItemGroupElement.ts +37 -0
- package/src/MenuItemRadioElement.ts +169 -0
- package/src/MenuPosition.ts +5 -0
- package/src/MenuTriggerElement.ts +154 -0
- package/src/index.ts +7 -0
- package/tsconfig.json +9 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,1274 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license MIT
|
|
3
|
+
* Copyright (c) 2025 matraic
|
|
4
|
+
* See LICENSE file in the project root for full license text.
|
|
5
|
+
*/
|
|
6
|
+
import { LitElement, nothing, html, css, unsafeCSS } from 'lit';
|
|
7
|
+
import { KeyboardClick, Focusable, AttachInternals, Disabled, isLinkButtonMixin, renderPseudoLink, DesignToken, HtmlFor, Role, LinkButton, HoverController, hasAssignedNodes, ScrollController, Checked } from '@m3e/core';
|
|
8
|
+
import { addAriaReferencedId, removeAriaReferencedId, RovingTabIndexManager } from '@m3e/core/a11y';
|
|
9
|
+
import { positionAnchor } from '@m3e/core/anchoring';
|
|
10
|
+
|
|
11
|
+
/******************************************************************************
|
|
12
|
+
Copyright (c) Microsoft Corporation.
|
|
13
|
+
|
|
14
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
15
|
+
purpose with or without fee is hereby granted.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
18
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
19
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
20
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
21
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
22
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
23
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
24
|
+
***************************************************************************** */
|
|
25
|
+
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
function __decorate(decorators, target, key, desc) {
|
|
29
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
30
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
31
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
32
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function __classPrivateFieldGet(receiver, state, kind, f) {
|
|
36
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
37
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
38
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function __classPrivateFieldSet(receiver, state, value, kind, f) {
|
|
42
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
43
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
44
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
45
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
49
|
+
var e = new Error(message);
|
|
50
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* @license
|
|
55
|
+
* Copyright 2017 Google LLC
|
|
56
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
57
|
+
*/
|
|
58
|
+
const t$1=t=>(e,o)=>{ void 0!==o?o.addInitializer((()=>{customElements.define(t,e);})):customElements.define(t,e);};
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* @license
|
|
62
|
+
* Copyright 2019 Google LLC
|
|
63
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
64
|
+
*/
|
|
65
|
+
const t=globalThis,e$3=t.ShadowRoot&&(void 0===t.ShadyCSS||t.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,s=Symbol(),o$2=new WeakMap;let n$2 = class n{constructor(t,e,o){if(this._$cssResult$=true,o!==s)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=t,this.t=e;}get styleSheet(){let t=this.o;const s=this.t;if(e$3&&void 0===t){const e=void 0!==s&&1===s.length;e&&(t=o$2.get(s)),void 0===t&&((this.o=t=new CSSStyleSheet).replaceSync(this.cssText),e&&o$2.set(s,t));}return t}toString(){return this.cssText}};const r$3=t=>new n$2("string"==typeof t?t:t+"",void 0,s),S=(s,o)=>{if(e$3)s.adoptedStyleSheets=o.map((t=>t instanceof CSSStyleSheet?t:t.styleSheet));else for(const e of o){const o=document.createElement("style"),n=t.litNonce;void 0!==n&&o.setAttribute("nonce",n),o.textContent=e.cssText,s.appendChild(o);}},c$1=e$3?t=>t:t=>t instanceof CSSStyleSheet?(t=>{let e="";for(const s of t.cssRules)e+=s.cssText;return r$3(e)})(t):t;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* @license
|
|
69
|
+
* Copyright 2017 Google LLC
|
|
70
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
71
|
+
*/const{is:i,defineProperty:e$2,getOwnPropertyDescriptor:h,getOwnPropertyNames:r$2,getOwnPropertySymbols:o$1,getPrototypeOf:n$1}=Object,a=globalThis,c=a.trustedTypes,l=c?c.emptyScript:"",p=a.reactiveElementPolyfillSupport,d=(t,s)=>t,u={toAttribute(t,s){switch(s){case Boolean:t=t?l:null;break;case Object:case Array:t=null==t?t:JSON.stringify(t);}return t},fromAttribute(t,s){let i=t;switch(s){case Boolean:i=null!==t;break;case Number:i=null===t?null:Number(t);break;case Object:case Array:try{i=JSON.parse(t);}catch(t){i=null;}}return i}},f=(t,s)=>!i(t,s),b={attribute:true,type:String,converter:u,reflect:false,useDefault:false,hasChanged:f};Symbol.metadata??=Symbol("metadata"),a.litPropertyMetadata??=new WeakMap;class y extends HTMLElement{static addInitializer(t){this._$Ei(),(this.l??=[]).push(t);}static get observedAttributes(){return this.finalize(),this._$Eh&&[...this._$Eh.keys()]}static createProperty(t,s=b){if(s.state&&(s.attribute=false),this._$Ei(),this.prototype.hasOwnProperty(t)&&((s=Object.create(s)).wrapped=true),this.elementProperties.set(t,s),!s.noAccessor){const i=Symbol(),h=this.getPropertyDescriptor(t,i,s);void 0!==h&&e$2(this.prototype,t,h);}}static getPropertyDescriptor(t,s,i){const{get:e,set:r}=h(this.prototype,t)??{get(){return this[s]},set(t){this[s]=t;}};return {get:e,set(s){const h=e?.call(this);r?.call(this,s),this.requestUpdate(t,h,i);},configurable:true,enumerable:true}}static getPropertyOptions(t){return this.elementProperties.get(t)??b}static _$Ei(){if(this.hasOwnProperty(d("elementProperties")))return;const t=n$1(this);t.finalize(),void 0!==t.l&&(this.l=[...t.l]),this.elementProperties=new Map(t.elementProperties);}static finalize(){if(this.hasOwnProperty(d("finalized")))return;if(this.finalized=true,this._$Ei(),this.hasOwnProperty(d("properties"))){const t=this.properties,s=[...r$2(t),...o$1(t)];for(const i of s)this.createProperty(i,t[i]);}const t=this[Symbol.metadata];if(null!==t){const s=litPropertyMetadata.get(t);if(void 0!==s)for(const[t,i]of s)this.elementProperties.set(t,i);}this._$Eh=new Map;for(const[t,s]of this.elementProperties){const i=this._$Eu(t,s);void 0!==i&&this._$Eh.set(i,t);}this.elementStyles=this.finalizeStyles(this.styles);}static finalizeStyles(s){const i=[];if(Array.isArray(s)){const e=new Set(s.flat(1/0).reverse());for(const s of e)i.unshift(c$1(s));}else void 0!==s&&i.push(c$1(s));return i}static _$Eu(t,s){const i=s.attribute;return false===i?void 0:"string"==typeof i?i:"string"==typeof t?t.toLowerCase():void 0}constructor(){super(),this._$Ep=void 0,this.isUpdatePending=false,this.hasUpdated=false,this._$Em=null,this._$Ev();}_$Ev(){this._$ES=new Promise((t=>this.enableUpdating=t)),this._$AL=new Map,this._$E_(),this.requestUpdate(),this.constructor.l?.forEach((t=>t(this)));}addController(t){(this._$EO??=new Set).add(t),void 0!==this.renderRoot&&this.isConnected&&t.hostConnected?.();}removeController(t){this._$EO?.delete(t);}_$E_(){const t=new Map,s=this.constructor.elementProperties;for(const i of s.keys())this.hasOwnProperty(i)&&(t.set(i,this[i]),delete this[i]);t.size>0&&(this._$Ep=t);}createRenderRoot(){const t=this.shadowRoot??this.attachShadow(this.constructor.shadowRootOptions);return S(t,this.constructor.elementStyles),t}connectedCallback(){this.renderRoot??=this.createRenderRoot(),this.enableUpdating(true),this._$EO?.forEach((t=>t.hostConnected?.()));}enableUpdating(t){}disconnectedCallback(){this._$EO?.forEach((t=>t.hostDisconnected?.()));}attributeChangedCallback(t,s,i){this._$AK(t,i);}_$ET(t,s){const i=this.constructor.elementProperties.get(t),e=this.constructor._$Eu(t,i);if(void 0!==e&&true===i.reflect){const h=(void 0!==i.converter?.toAttribute?i.converter:u).toAttribute(s,i.type);this._$Em=t,null==h?this.removeAttribute(e):this.setAttribute(e,h),this._$Em=null;}}_$AK(t,s){const i=this.constructor,e=i._$Eh.get(t);if(void 0!==e&&this._$Em!==e){const t=i.getPropertyOptions(e),h="function"==typeof t.converter?{fromAttribute:t.converter}:void 0!==t.converter?.fromAttribute?t.converter:u;this._$Em=e;const r=h.fromAttribute(s,t.type);this[e]=r??this._$Ej?.get(e)??r,this._$Em=null;}}requestUpdate(t,s,i){if(void 0!==t){const e=this.constructor,h=this[t];if(i??=e.getPropertyOptions(t),!((i.hasChanged??f)(h,s)||i.useDefault&&i.reflect&&h===this._$Ej?.get(t)&&!this.hasAttribute(e._$Eu(t,i))))return;this.C(t,s,i);} false===this.isUpdatePending&&(this._$ES=this._$EP());}C(t,s,{useDefault:i,reflect:e,wrapped:h},r){i&&!(this._$Ej??=new Map).has(t)&&(this._$Ej.set(t,r??s??this[t]),true!==h||void 0!==r)||(this._$AL.has(t)||(this.hasUpdated||i||(s=void 0),this._$AL.set(t,s)),true===e&&this._$Em!==t&&(this._$Eq??=new Set).add(t));}async _$EP(){this.isUpdatePending=true;try{await this._$ES;}catch(t){Promise.reject(t);}const t=this.scheduleUpdate();return null!=t&&await t,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){if(!this.isUpdatePending)return;if(!this.hasUpdated){if(this.renderRoot??=this.createRenderRoot(),this._$Ep){for(const[t,s]of this._$Ep)this[t]=s;this._$Ep=void 0;}const t=this.constructor.elementProperties;if(t.size>0)for(const[s,i]of t){const{wrapped:t}=i,e=this[s];true!==t||this._$AL.has(s)||void 0===e||this.C(s,void 0,i,e);}}let t=false;const s=this._$AL;try{t=this.shouldUpdate(s),t?(this.willUpdate(s),this._$EO?.forEach((t=>t.hostUpdate?.())),this.update(s)):this._$EM();}catch(s){throw t=false,this._$EM(),s}t&&this._$AE(s);}willUpdate(t){}_$AE(t){this._$EO?.forEach((t=>t.hostUpdated?.())),this.hasUpdated||(this.hasUpdated=true,this.firstUpdated(t)),this.updated(t);}_$EM(){this._$AL=new Map,this.isUpdatePending=false;}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$ES}shouldUpdate(t){return true}update(t){this._$Eq&&=this._$Eq.forEach((t=>this._$ET(t,this[t]))),this._$EM();}updated(t){}firstUpdated(t){}}y.elementStyles=[],y.shadowRootOptions={mode:"open"},y[d("elementProperties")]=new Map,y[d("finalized")]=new Map,p?.({ReactiveElement:y}),(a.reactiveElementVersions??=[]).push("2.1.1");
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* @license
|
|
75
|
+
* Copyright 2017 Google LLC
|
|
76
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
77
|
+
*/const o={attribute:true,type:String,converter:u,reflect:false,hasChanged:f},r$1=(t=o,e,r)=>{const{kind:n,metadata:i}=r;let s=globalThis.litPropertyMetadata.get(i);if(void 0===s&&globalThis.litPropertyMetadata.set(i,s=new Map),"setter"===n&&((t=Object.create(t)).wrapped=true),s.set(r.name,t),"accessor"===n){const{name:o}=r;return {set(r){const n=e.get.call(this);e.set.call(this,r),this.requestUpdate(o,n,t);},init(e){return void 0!==e&&this.C(o,void 0,t,e),e}}}if("setter"===n){const{name:o}=r;return function(r){const n=this[o];e.call(this,r),this.requestUpdate(o,n,t);}}throw Error("Unsupported decorator location: "+n)};function n(t){return (e,o)=>"object"==typeof o?r$1(t,e,o):((t,e,o)=>{const r=e.hasOwnProperty(o);return e.constructor.createProperty(o,t),r?Object.getOwnPropertyDescriptor(e,o):void 0})(t,e,o)}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* @license
|
|
81
|
+
* Copyright 2017 Google LLC
|
|
82
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
83
|
+
*/function r(r){return n({...r,state:true,attribute:false})}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* @license
|
|
87
|
+
* Copyright 2017 Google LLC
|
|
88
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
89
|
+
*/
|
|
90
|
+
const e$1=(e,t,c)=>(c.configurable=true,c.enumerable=true,Reflect.decorate&&"object"!=typeof t&&Object.defineProperty(e,t,c),c);
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* @license
|
|
94
|
+
* Copyright 2017 Google LLC
|
|
95
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
96
|
+
*/function e(e,r){return (n,s,i)=>{const o=t=>t.renderRoot?.querySelector(e)??null;return e$1(n,s,{get(){return o(this)}})}}
|
|
97
|
+
|
|
98
|
+
/** A base implementation for an item of a menu. This class must be inherited. */
|
|
99
|
+
class MenuItemElementBase extends KeyboardClick(Focusable(AttachInternals(Disabled(LitElement), true))) {
|
|
100
|
+
/** The menu to which this item belongs. */
|
|
101
|
+
get menu() {
|
|
102
|
+
return this.closest("m3e-menu");
|
|
103
|
+
}
|
|
104
|
+
/** @inheritdoc */
|
|
105
|
+
firstUpdated(_changedProperties) {
|
|
106
|
+
super.firstUpdated(_changedProperties);
|
|
107
|
+
[this._focusRing, this._stateLayer, this._ripple].forEach((x) => x?.attach(this));
|
|
108
|
+
}
|
|
109
|
+
/** @inheritdoc */
|
|
110
|
+
render() {
|
|
111
|
+
return html `<div class="base">
|
|
112
|
+
<m3e-state-layer class="state-layer" ?disabled="${this.disabled}"></m3e-state-layer>
|
|
113
|
+
<m3e-focus-ring class="focus-ring" inward ?disabled="${this.disabled}"></m3e-focus-ring>
|
|
114
|
+
<m3e-ripple class="ripple" ?disabled="${this.disabled}"></m3e-ripple>
|
|
115
|
+
<div class="touch" aria-hidden="true"></div>
|
|
116
|
+
${isLinkButtonMixin(this) ? this[renderPseudoLink]() : nothing}
|
|
117
|
+
<div class="wrapper">${this._renderContent()}</div>
|
|
118
|
+
</div>`;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/** The styles of the element. */
|
|
122
|
+
MenuItemElementBase.styles = css `
|
|
123
|
+
:host {
|
|
124
|
+
display: inline-block;
|
|
125
|
+
outline: none;
|
|
126
|
+
user-select: none;
|
|
127
|
+
flex: none;
|
|
128
|
+
height: var(--m3e-menu-item-container-height, 3rem);
|
|
129
|
+
}
|
|
130
|
+
:host(:not(:focus-visible)) .base {
|
|
131
|
+
--m3e-state-layer-focus-opacity: 0;
|
|
132
|
+
}
|
|
133
|
+
:host(:not(:disabled):not([aria-expanded="true"])) .base {
|
|
134
|
+
color: var(--m3e-menu-item-color, ${DesignToken.color.onSurface});
|
|
135
|
+
}
|
|
136
|
+
:host(:not([aria-expanded="true"])) .base {
|
|
137
|
+
--m3e-state-layer-hover-color: var(--m3e-menu-item-container-hover-color, ${DesignToken.color.onSurface});
|
|
138
|
+
--m3e-state-layer-focus-color: var(--m3e-menu-item-container-focus-color, ${DesignToken.color.onSurface});
|
|
139
|
+
--m3e-ripple-color: var(--m3e-menu-item-ripple-color, ${DesignToken.color.onSurface});
|
|
140
|
+
}
|
|
141
|
+
:host(:not(:disabled)[checked]) .base,
|
|
142
|
+
:host(:not(:disabled)[aria-expanded="true"]) .base {
|
|
143
|
+
color: var(--m3e-menu-selected-color, ${DesignToken.color.onSecondaryContainer});
|
|
144
|
+
background-color: var(--m3e-menu-selected-container-color, ${DesignToken.color.secondaryContainer});
|
|
145
|
+
}
|
|
146
|
+
:host([checked]) .base,
|
|
147
|
+
:host([aria-expanded="true"]) .base {
|
|
148
|
+
--m3e-state-layer-hover-color: var(
|
|
149
|
+
--m3e-menu-item-selected-container-hover-color,
|
|
150
|
+
${DesignToken.color.onSecondaryContainer}
|
|
151
|
+
);
|
|
152
|
+
--m3e-state-layer-focus-color: var(
|
|
153
|
+
--m3e-menu-item-selected-container-focus-color,
|
|
154
|
+
${DesignToken.color.onSecondaryContainer}
|
|
155
|
+
);
|
|
156
|
+
--m3e-ripple-color: var(--m3e-menu-item-selected-ripple-color, ${DesignToken.color.onSecondaryContainer});
|
|
157
|
+
}
|
|
158
|
+
:host(:not(:disabled)) {
|
|
159
|
+
cursor: pointer;
|
|
160
|
+
}
|
|
161
|
+
:host(:disabled) .base {
|
|
162
|
+
color: color-mix(
|
|
163
|
+
in srgb,
|
|
164
|
+
var(--m3e-menu-item-disabled-color, ${DesignToken.color.onSurface}) var(--m3e-menu-item-disabled-opacity, 38%),
|
|
165
|
+
transparent
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
.base {
|
|
169
|
+
box-sizing: border-box;
|
|
170
|
+
vertical-align: middle;
|
|
171
|
+
display: inline-flex;
|
|
172
|
+
align-items: center;
|
|
173
|
+
position: relative;
|
|
174
|
+
width: 100%;
|
|
175
|
+
height: 100%;
|
|
176
|
+
}
|
|
177
|
+
.touch {
|
|
178
|
+
position: absolute;
|
|
179
|
+
height: 3rem;
|
|
180
|
+
left: 0;
|
|
181
|
+
right: 0;
|
|
182
|
+
}
|
|
183
|
+
.wrapper {
|
|
184
|
+
display: inline-flex;
|
|
185
|
+
align-items: center;
|
|
186
|
+
column-gap: var(--m3e-menu-item-icon-label-space, 0.75rem);
|
|
187
|
+
padding-inline-start: var(--m3e-menu-item-padding-start, 0.75rem);
|
|
188
|
+
padding-inline-end: var(--m3e-menu-item-padding-end, 0.75rem);
|
|
189
|
+
font-size: var(--m3e-menu-item-label-text-font-size, ${DesignToken.typescale.standard.label.large.fontSize});
|
|
190
|
+
font-weight: var(
|
|
191
|
+
--m3e-menu-item-label-text-font-weight,
|
|
192
|
+
${DesignToken.typescale.standard.label.large.fontWeight}
|
|
193
|
+
);
|
|
194
|
+
line-height: var(
|
|
195
|
+
--m3e-menu-item-label-text-line-height,
|
|
196
|
+
${DesignToken.typescale.standard.label.large.lineHeight}
|
|
197
|
+
);
|
|
198
|
+
letter-spacing: var(--m3e-menu-item-label-text-tracking, ${DesignToken.typescale.standard.label.large.tracking});
|
|
199
|
+
}
|
|
200
|
+
.focus-ring {
|
|
201
|
+
border-radius: var(--m3e-menu-item-focus-ring-shape, ${DesignToken.shape.corner.medium});
|
|
202
|
+
}
|
|
203
|
+
.content {
|
|
204
|
+
flex: 1 1 auto;
|
|
205
|
+
overflow: hidden;
|
|
206
|
+
text-overflow: ellipsis;
|
|
207
|
+
white-space: nowrap;
|
|
208
|
+
}
|
|
209
|
+
::slotted([slot="icon"]),
|
|
210
|
+
::slotted([slot="trailing-icon"]),
|
|
211
|
+
.trailing-icon {
|
|
212
|
+
flex: none;
|
|
213
|
+
width: 1em;
|
|
214
|
+
font-size: var(--m3e-menu-item-icon-size, 1.5rem) !important;
|
|
215
|
+
}
|
|
216
|
+
@media (forced-colors: active) {
|
|
217
|
+
.base {
|
|
218
|
+
background-color: Menu;
|
|
219
|
+
color: MenuText;
|
|
220
|
+
}
|
|
221
|
+
:host(:disabled) .base {
|
|
222
|
+
color: GrayText;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
`;
|
|
226
|
+
__decorate([
|
|
227
|
+
e(".focus-ring")
|
|
228
|
+
], MenuItemElementBase.prototype, "_focusRing", void 0);
|
|
229
|
+
__decorate([
|
|
230
|
+
e(".state-layer")
|
|
231
|
+
], MenuItemElementBase.prototype, "_stateLayer", void 0);
|
|
232
|
+
__decorate([
|
|
233
|
+
e(".ripple")
|
|
234
|
+
], MenuItemElementBase.prototype, "_ripple", void 0);
|
|
235
|
+
|
|
236
|
+
var _M3eMenuTriggerElement_instances, _M3eMenuTriggerElement_clickHandler, _M3eMenuTriggerElement_handleClick;
|
|
237
|
+
/**
|
|
238
|
+
* @summary
|
|
239
|
+
* An element, nested within a clickable element, used to open a menu.
|
|
240
|
+
*
|
|
241
|
+
* @description
|
|
242
|
+
* The `m3e-menu-trigger` component is used to open a menu when nested within a clickable element
|
|
243
|
+
* such as a button or menu item. It anchors the menu to its invoker, enabling contextual flows and
|
|
244
|
+
* nested hierarchies.
|
|
245
|
+
*
|
|
246
|
+
* @example
|
|
247
|
+
* The following example illustrates a basic menu. The `m3e-menu-trigger` is used to trigger a `m3e-menu` specified
|
|
248
|
+
* by the `for` attribute when its parenting element is activated.
|
|
249
|
+
* ```html
|
|
250
|
+
* <m3e-button>
|
|
251
|
+
* <m3e-menu-trigger for="menu1">Basic menu</m3e-menu-trigger>
|
|
252
|
+
* </m3e-button>
|
|
253
|
+
* <m3e-menu id="menu1">
|
|
254
|
+
* <m3e-menu-item>Apple</m3e-menu-item>
|
|
255
|
+
* <m3e-menu-item>Apricot</m3e-menu-item>
|
|
256
|
+
* <m3e-menu-item>Avocado</m3e-menu-item>
|
|
257
|
+
* <m3e-menu-item>Green Apple</m3e-menu-item>
|
|
258
|
+
* <m3e-menu-item>Green Grapes</m3e-menu-item>
|
|
259
|
+
* <m3e-menu-item>Olive</m3e-menu-item>
|
|
260
|
+
* <m3e-menu-item>Orange</m3e-menu-item>
|
|
261
|
+
* </m3e-menu>
|
|
262
|
+
* ```
|
|
263
|
+
*
|
|
264
|
+
* @example
|
|
265
|
+
* The next example illustrates nested menus. Submenus are triggered by placing a `m3e-menu-trigger` inside a `m3e-menu-item`.
|
|
266
|
+
* ```html
|
|
267
|
+
* <m3e-button>
|
|
268
|
+
* <m3e-menu-trigger for="menu2">Nested menus</m3e-menu-trigger>
|
|
269
|
+
* </m3e-button>
|
|
270
|
+
* <m3e-menu id="menu2">
|
|
271
|
+
* <m3e-menu-item>
|
|
272
|
+
* <m3e-menu-trigger for="menu3">Fruits with A</m3e-menu-trigger>
|
|
273
|
+
* </m3e-menu-item>
|
|
274
|
+
* <m3e-menu-item>Grapes</m3e-menu-item>
|
|
275
|
+
* <m3e-menu-item>Olive</m3e-menu-item>
|
|
276
|
+
* <m3e-menu-item>Orange</m3e-menu-item>
|
|
277
|
+
* </m3e-menu>
|
|
278
|
+
* <m3e-menu id="menu3">
|
|
279
|
+
* <m3e-menu-item>Apricot</m3e-menu-item>
|
|
280
|
+
* <m3e-menu-item>Avocado</m3e-menu-item>
|
|
281
|
+
* <m3e-menu-item>
|
|
282
|
+
* <m3e-menu-trigger for="menu4">Apples</m3e-menu-trigger>
|
|
283
|
+
* </m3e-menu-item>
|
|
284
|
+
* </m3e-menu>
|
|
285
|
+
* <m3e-menu id="menu4">
|
|
286
|
+
* <m3e-menu-item>Fuji</m3e-menu-item>
|
|
287
|
+
* <m3e-menu-item>Granny Smith</m3e-menu-item>
|
|
288
|
+
* <m3e-menu-item>Red Delicious</m3e-menu-item>
|
|
289
|
+
* </m3e-menu>
|
|
290
|
+
* ```
|
|
291
|
+
*
|
|
292
|
+
* @tag m3e-menu-trigger
|
|
293
|
+
*
|
|
294
|
+
* @slot - Renders the contents of the trigger.
|
|
295
|
+
*/
|
|
296
|
+
let M3eMenuTriggerElement = class M3eMenuTriggerElement extends HtmlFor(Role(LitElement, "none")) {
|
|
297
|
+
constructor() {
|
|
298
|
+
super(...arguments);
|
|
299
|
+
_M3eMenuTriggerElement_instances.add(this);
|
|
300
|
+
/** @private */ _M3eMenuTriggerElement_clickHandler.set(this, async (e) => __classPrivateFieldGet(this, _M3eMenuTriggerElement_instances, "m", _M3eMenuTriggerElement_handleClick).call(this, e));
|
|
301
|
+
}
|
|
302
|
+
/** The menu triggered by the element. */
|
|
303
|
+
get menu() {
|
|
304
|
+
return this.control?.tagName === "M3E-MENU" ? this.control : null;
|
|
305
|
+
}
|
|
306
|
+
/** @inheritdoc */
|
|
307
|
+
connectedCallback() {
|
|
308
|
+
super.connectedCallback();
|
|
309
|
+
this.parentElement?.addEventListener("click", __classPrivateFieldGet(this, _M3eMenuTriggerElement_clickHandler, "f"));
|
|
310
|
+
}
|
|
311
|
+
/** @inheritdoc */
|
|
312
|
+
disconnectedCallback() {
|
|
313
|
+
super.disconnectedCallback();
|
|
314
|
+
this.parentElement?.removeEventListener("click", __classPrivateFieldGet(this, _M3eMenuTriggerElement_clickHandler, "f"));
|
|
315
|
+
}
|
|
316
|
+
/** @inheritdoc */
|
|
317
|
+
attach(control) {
|
|
318
|
+
super.attach(control);
|
|
319
|
+
const menu = this.menu;
|
|
320
|
+
if (menu) {
|
|
321
|
+
if (this.parentElement) {
|
|
322
|
+
this.parentElement.ariaHasPopup = "menu";
|
|
323
|
+
this.parentElement.ariaExpanded = "false";
|
|
324
|
+
if (menu.id) {
|
|
325
|
+
addAriaReferencedId(this.parentElement, "aria-controls", menu.id);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
if (this.closest("m3e-menu")) {
|
|
329
|
+
menu.submenu = true;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
/** @inheritdoc */
|
|
334
|
+
detach() {
|
|
335
|
+
if (this.parentElement) {
|
|
336
|
+
this.parentElement.ariaHasPopup = null;
|
|
337
|
+
this.parentElement.ariaExpanded = null;
|
|
338
|
+
const menu = this.menu;
|
|
339
|
+
if (menu?.id) {
|
|
340
|
+
removeAriaReferencedId(this.parentElement, "aria-controls", menu.id);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
super.detach();
|
|
344
|
+
}
|
|
345
|
+
/** @inheritdoc */
|
|
346
|
+
render() {
|
|
347
|
+
return html `<slot></slot>`;
|
|
348
|
+
}
|
|
349
|
+
};
|
|
350
|
+
_M3eMenuTriggerElement_clickHandler = new WeakMap();
|
|
351
|
+
_M3eMenuTriggerElement_instances = new WeakSet();
|
|
352
|
+
_M3eMenuTriggerElement_handleClick = function _M3eMenuTriggerElement_handleClick(e) {
|
|
353
|
+
if (!e.defaultPrevented && this.parentElement) {
|
|
354
|
+
if (this.parentElement.tagName === "M3E-MENU-ITEM") {
|
|
355
|
+
this.menu?.show(this.parentElement);
|
|
356
|
+
}
|
|
357
|
+
else {
|
|
358
|
+
this.menu?.toggle(this.parentElement);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
};
|
|
362
|
+
/** The styles of the element. */
|
|
363
|
+
M3eMenuTriggerElement.styles = css `
|
|
364
|
+
:host {
|
|
365
|
+
display: contents;
|
|
366
|
+
}
|
|
367
|
+
::slotted(.material-icons) {
|
|
368
|
+
font-size: inherit !important;
|
|
369
|
+
}
|
|
370
|
+
`;
|
|
371
|
+
M3eMenuTriggerElement = __decorate([
|
|
372
|
+
t$1("m3e-menu-trigger")
|
|
373
|
+
], M3eMenuTriggerElement);
|
|
374
|
+
|
|
375
|
+
var _M3eMenuItemElement_instances, _M3eMenuItemElement_clickHandler, _M3eMenuItemElement_keyDownHandler, _M3eMenuItemElement_mouseEnterHandler, _M3eMenuItemElement_submenuTrigger, _M3eMenuItemElement_defaultSlotChangeHandler, _M3eMenuItemElement_iconSlotChangeHandler, _M3eMenuItemElement_trailingIconSlotChangeHandler, _M3eMenuItemElement_handleClick, _M3eMenuItemElement_handleKeyDown, _M3eMenuItemElement_handleMouseEnter;
|
|
376
|
+
var M3eMenuItemElement_1;
|
|
377
|
+
/**
|
|
378
|
+
* @summary
|
|
379
|
+
* An item of a menu.
|
|
380
|
+
*
|
|
381
|
+
* @description
|
|
382
|
+
* The `m3e-menu-item` component represents a single actionable item within a menu, supporting standard
|
|
383
|
+
* click behavior, optional link semantics, and flexible icon placement for navigation, commands, or
|
|
384
|
+
* contextual actions. It behaves as a button or link depending on its attributes, and can trigger a submenu
|
|
385
|
+
* when a nested `m3e-menu-trigger` is present—enabling hierarchical flows.
|
|
386
|
+
*
|
|
387
|
+
* @example
|
|
388
|
+
* The following example illustrates a basic menu. The `m3e-menu-trigger` is used to trigger a `m3e-menu` specified
|
|
389
|
+
* by the `for` attribute when its parenting element is activated.
|
|
390
|
+
* ```html
|
|
391
|
+
* <m3e-button>
|
|
392
|
+
* <m3e-menu-trigger for="menu1">Basic menu</m3e-menu-trigger>
|
|
393
|
+
* </m3e-button>
|
|
394
|
+
* <m3e-menu id="menu1">
|
|
395
|
+
* <m3e-menu-item>Apple</m3e-menu-item>
|
|
396
|
+
* <m3e-menu-item>Apricot</m3e-menu-item>
|
|
397
|
+
* <m3e-menu-item>Avocado</m3e-menu-item>
|
|
398
|
+
* <m3e-menu-item>Green Apple</m3e-menu-item>
|
|
399
|
+
* <m3e-menu-item>Green Grapes</m3e-menu-item>
|
|
400
|
+
* <m3e-menu-item>Olive</m3e-menu-item>
|
|
401
|
+
* <m3e-menu-item>Orange</m3e-menu-item>
|
|
402
|
+
* </m3e-menu>
|
|
403
|
+
* ```
|
|
404
|
+
*
|
|
405
|
+
* @example
|
|
406
|
+
* The next example illustrates nested menus. Submenus are triggered by placing a `m3e-menu-trigger` inside a `m3e-menu-item`.
|
|
407
|
+
* ```html
|
|
408
|
+
* <m3e-button>
|
|
409
|
+
* <m3e-menu-trigger for="menu2">Nested menus</m3e-menu-trigger>
|
|
410
|
+
* </m3e-button>
|
|
411
|
+
* <m3e-menu id="menu2">
|
|
412
|
+
* <m3e-menu-item>
|
|
413
|
+
* <m3e-menu-trigger for="menu3">Fruits with A</m3e-menu-trigger>
|
|
414
|
+
* </m3e-menu-item>
|
|
415
|
+
* <m3e-menu-item>Grapes</m3e-menu-item>
|
|
416
|
+
* <m3e-menu-item>Olive</m3e-menu-item>
|
|
417
|
+
* <m3e-menu-item>Orange</m3e-menu-item>
|
|
418
|
+
* </m3e-menu>
|
|
419
|
+
* <m3e-menu id="menu3">
|
|
420
|
+
* <m3e-menu-item>Apricot</m3e-menu-item>
|
|
421
|
+
* <m3e-menu-item>Avocado</m3e-menu-item>
|
|
422
|
+
* <m3e-menu-item>
|
|
423
|
+
* <m3e-menu-trigger for="menu4">Apples</m3e-menu-trigger>
|
|
424
|
+
* </m3e-menu-item>
|
|
425
|
+
* </m3e-menu>
|
|
426
|
+
* <m3e-menu id="menu4">
|
|
427
|
+
* <m3e-menu-item>Fuji</m3e-menu-item>
|
|
428
|
+
* <m3e-menu-item>Granny Smith</m3e-menu-item>
|
|
429
|
+
* <m3e-menu-item>Red Delicious</m3e-menu-item>
|
|
430
|
+
* </m3e-menu>
|
|
431
|
+
* ```
|
|
432
|
+
*
|
|
433
|
+
* @tag m3e-menu-item
|
|
434
|
+
*
|
|
435
|
+
* @slot - Renders the label of the item.
|
|
436
|
+
* @slot icon - Renders an icon before the items's label.
|
|
437
|
+
* @slot trailing-icon - Renders an icon after the item's label.
|
|
438
|
+
*
|
|
439
|
+
* @attr disabled - Whether the element is disabled.
|
|
440
|
+
* @attr download - Whether the `target` of the link button will be downloaded, optionally specifying the new name of the file.
|
|
441
|
+
* @attr href - The URL to which the link button points.
|
|
442
|
+
* @attr rel - The relationship between the `target` of the link button and the document.
|
|
443
|
+
* @attr target - The target of the link button.
|
|
444
|
+
*
|
|
445
|
+
* @cssprop --m3e-menu-item-container-height - Height of the menu item container.
|
|
446
|
+
* @cssprop --m3e-menu-item-color - Text color for unselected, enabled menu items.
|
|
447
|
+
* @cssprop --m3e-menu-item-container-hover-color - State layer hover color for unselected items.
|
|
448
|
+
* @cssprop --m3e-menu-item-container-focus-color - State layer focus color for unselected items.
|
|
449
|
+
* @cssprop --m3e-menu-item-ripple-color - Ripple color for unselected items.
|
|
450
|
+
* @cssprop --m3e-menu-selected-color - Text color for selected or expanded items.
|
|
451
|
+
* @cssprop --m3e-menu-selected-container-color - Background color for selected or expanded items.
|
|
452
|
+
* @cssprop --m3e-menu-item-selected-container-hover-color - State layer hover color for selected items.
|
|
453
|
+
* @cssprop --m3e-menu-item-selected-container-focus-color - State layer focus color for selected items.
|
|
454
|
+
* @cssprop --m3e-menu-item-selected-ripple-color - Ripple color for selected items.
|
|
455
|
+
* @cssprop --m3e-menu-item-disabled-color - Base color for disabled items.
|
|
456
|
+
* @cssprop --m3e-menu-item-disabled-opacity - Opacity percentage for disabled item color mix.
|
|
457
|
+
* @cssprop --m3e-menu-item-icon-label-space - Horizontal gap between icon and content.
|
|
458
|
+
* @cssprop --m3e-menu-item-padding-start - Start padding for the item wrapper.
|
|
459
|
+
* @cssprop --m3e-menu-item-padding-end - End padding for the item wrapper.
|
|
460
|
+
* @cssprop --m3e-menu-item-label-text-font-size - Font size for menu item text.
|
|
461
|
+
* @cssprop --m3e-menu-item-label-text-font-weight - Font weight for menu item text.
|
|
462
|
+
* @cssprop --m3e-menu-item-label-text-line-height - Line height for menu item text.
|
|
463
|
+
* @cssprop --m3e-menu-item-label-text-tracking - Letter spacing for menu item text.
|
|
464
|
+
* @cssprop --m3e-menu-item-focus-ring-shape - Border radius for the focus ring.
|
|
465
|
+
* @cssprop --m3e-menu-item-icon-size - Font size for leading and trailing icons.
|
|
466
|
+
*/
|
|
467
|
+
let M3eMenuItemElement = M3eMenuItemElement_1 = class M3eMenuItemElement extends LinkButton(Role(MenuItemElementBase, "menuitem")) {
|
|
468
|
+
constructor() {
|
|
469
|
+
super();
|
|
470
|
+
_M3eMenuItemElement_instances.add(this);
|
|
471
|
+
/** @private */ _M3eMenuItemElement_clickHandler.set(this, (e) => __classPrivateFieldGet(this, _M3eMenuItemElement_instances, "m", _M3eMenuItemElement_handleClick).call(this, e));
|
|
472
|
+
/** @private */ _M3eMenuItemElement_keyDownHandler.set(this, (e) => __classPrivateFieldGet(this, _M3eMenuItemElement_instances, "m", _M3eMenuItemElement_handleKeyDown).call(this, e));
|
|
473
|
+
/** @private */ _M3eMenuItemElement_mouseEnterHandler.set(this, () => __classPrivateFieldGet(this, _M3eMenuItemElement_instances, "m", _M3eMenuItemElement_handleMouseEnter).call(this));
|
|
474
|
+
/** @private */ this._hasSubmenu = false;
|
|
475
|
+
/** @private */ _M3eMenuItemElement_submenuTrigger.set(this, void 0);
|
|
476
|
+
new HoverController(this, {
|
|
477
|
+
startDelay: 500,
|
|
478
|
+
endDelay: 500,
|
|
479
|
+
callback: (hovering) => {
|
|
480
|
+
if (hovering && !this.disabled && __classPrivateFieldGet(this, _M3eMenuItemElement_submenuTrigger, "f")) {
|
|
481
|
+
__classPrivateFieldGet(this, _M3eMenuItemElement_submenuTrigger, "f").menu?.show(this);
|
|
482
|
+
}
|
|
483
|
+
},
|
|
484
|
+
});
|
|
485
|
+
}
|
|
486
|
+
/** The submenu triggered by the item. */
|
|
487
|
+
get submenu() {
|
|
488
|
+
return __classPrivateFieldGet(this, _M3eMenuItemElement_submenuTrigger, "f")?.menu ?? null;
|
|
489
|
+
}
|
|
490
|
+
/** @inheritdoc */
|
|
491
|
+
connectedCallback() {
|
|
492
|
+
super.connectedCallback();
|
|
493
|
+
this.addEventListener("click", __classPrivateFieldGet(this, _M3eMenuItemElement_clickHandler, "f"));
|
|
494
|
+
this.addEventListener("keydown", __classPrivateFieldGet(this, _M3eMenuItemElement_keyDownHandler, "f"));
|
|
495
|
+
this.addEventListener("mouseenter", __classPrivateFieldGet(this, _M3eMenuItemElement_mouseEnterHandler, "f"));
|
|
496
|
+
}
|
|
497
|
+
/** @inheritdoc */
|
|
498
|
+
disconnectedCallback() {
|
|
499
|
+
super.disconnectedCallback();
|
|
500
|
+
this.removeEventListener("click", __classPrivateFieldGet(this, _M3eMenuItemElement_clickHandler, "f"));
|
|
501
|
+
this.removeEventListener("keydown", __classPrivateFieldGet(this, _M3eMenuItemElement_keyDownHandler, "f"));
|
|
502
|
+
this.removeEventListener("mouseenter", __classPrivateFieldGet(this, _M3eMenuItemElement_mouseEnterHandler, "f"));
|
|
503
|
+
}
|
|
504
|
+
/** @internal @inheritdoc */
|
|
505
|
+
_renderContent() {
|
|
506
|
+
return html `<slot name="icon" aria-hidden="true" @slotchange="${__classPrivateFieldGet(this, _M3eMenuItemElement_instances, "m", _M3eMenuItemElement_iconSlotChangeHandler)}"></slot>
|
|
507
|
+
<span class="content"><slot @slotchange="${__classPrivateFieldGet(this, _M3eMenuItemElement_instances, "m", _M3eMenuItemElement_defaultSlotChangeHandler)}"></slot></span>
|
|
508
|
+
${this._hasSubmenu
|
|
509
|
+
? html `<svg class="trailing-icon" aria-hidden="true" viewBox="0 -960 960 960" fill="currentColor">
|
|
510
|
+
<path d="M400-280v-400l200 200-200 200Z" />
|
|
511
|
+
</svg>`
|
|
512
|
+
: html `<slot name="trailing-icon" aria-hidden="true" @slotchange="${__classPrivateFieldGet(this, _M3eMenuItemElement_instances, "m", _M3eMenuItemElement_trailingIconSlotChangeHandler)}">
|
|
513
|
+
</slot>`}`;
|
|
514
|
+
}
|
|
515
|
+
};
|
|
516
|
+
_M3eMenuItemElement_clickHandler = new WeakMap();
|
|
517
|
+
_M3eMenuItemElement_keyDownHandler = new WeakMap();
|
|
518
|
+
_M3eMenuItemElement_mouseEnterHandler = new WeakMap();
|
|
519
|
+
_M3eMenuItemElement_submenuTrigger = new WeakMap();
|
|
520
|
+
_M3eMenuItemElement_instances = new WeakSet();
|
|
521
|
+
_M3eMenuItemElement_defaultSlotChangeHandler = function _M3eMenuItemElement_defaultSlotChangeHandler(e) {
|
|
522
|
+
__classPrivateFieldSet(this, _M3eMenuItemElement_submenuTrigger, e.target
|
|
523
|
+
.assignedElements({ flatten: true })
|
|
524
|
+
.find((x) => x instanceof M3eMenuTriggerElement), "f");
|
|
525
|
+
this._hasSubmenu = __classPrivateFieldGet(this, _M3eMenuItemElement_submenuTrigger, "f") !== undefined;
|
|
526
|
+
};
|
|
527
|
+
_M3eMenuItemElement_iconSlotChangeHandler = function _M3eMenuItemElement_iconSlotChangeHandler(e) {
|
|
528
|
+
this.classList.toggle("-with-icon", hasAssignedNodes(e.target));
|
|
529
|
+
};
|
|
530
|
+
_M3eMenuItemElement_trailingIconSlotChangeHandler = function _M3eMenuItemElement_trailingIconSlotChangeHandler(e) {
|
|
531
|
+
this.classList.toggle("-with-trailing-icon", hasAssignedNodes(e.target));
|
|
532
|
+
};
|
|
533
|
+
_M3eMenuItemElement_handleClick = function _M3eMenuItemElement_handleClick(e) {
|
|
534
|
+
if (!e.defaultPrevented && !this._hasSubmenu) {
|
|
535
|
+
this.menu?.hideAll(true);
|
|
536
|
+
}
|
|
537
|
+
};
|
|
538
|
+
_M3eMenuItemElement_handleKeyDown = function _M3eMenuItemElement_handleKeyDown(e) {
|
|
539
|
+
if (e.defaultPrevented || this.disabled)
|
|
540
|
+
return;
|
|
541
|
+
switch (e.key) {
|
|
542
|
+
case "Right":
|
|
543
|
+
case "ArrowRight":
|
|
544
|
+
e.preventDefault();
|
|
545
|
+
this.submenu?.show(this);
|
|
546
|
+
break;
|
|
547
|
+
}
|
|
548
|
+
};
|
|
549
|
+
_M3eMenuItemElement_handleMouseEnter = function _M3eMenuItemElement_handleMouseEnter() {
|
|
550
|
+
this.menu?.items.forEach((item) => {
|
|
551
|
+
if (item instanceof M3eMenuItemElement_1 && item !== this && item.submenu?.isOpen) {
|
|
552
|
+
item.submenu.hide();
|
|
553
|
+
}
|
|
554
|
+
});
|
|
555
|
+
};
|
|
556
|
+
__decorate([
|
|
557
|
+
r()
|
|
558
|
+
], M3eMenuItemElement.prototype, "_hasSubmenu", void 0);
|
|
559
|
+
M3eMenuItemElement = M3eMenuItemElement_1 = __decorate([
|
|
560
|
+
t$1("m3e-menu-item")
|
|
561
|
+
], M3eMenuItemElement);
|
|
562
|
+
|
|
563
|
+
var _M3eMenuElement_instances, _M3eMenuElement_trigger, _M3eMenuElement_anchorCleanup, _M3eMenuElement_listManager, _M3eMenuElement_keyDownHandler, _M3eMenuElement_documentClickHandler, _M3eMenuElement_scrollController, _M3eMenuElement_toggleHandler, _M3eMenuElement_handleSlotChange, _M3eMenuElement_handleKeyDown, _M3eMenuElement_handleDocumentClick, _M3eMenuElement_getAbsolutePosition;
|
|
564
|
+
var M3eMenuElement_1;
|
|
565
|
+
/**
|
|
566
|
+
* @summary
|
|
567
|
+
* Presents a list of choices on a temporary surface.
|
|
568
|
+
*
|
|
569
|
+
* @description
|
|
570
|
+
* The `m3e-menu` component presents a list of choices on a temporary surface, typically anchored to a trigger element.
|
|
571
|
+
* It supports dynamic positioning via `position-x` and `position-y` attributes, and renders its contents through the default slot.
|
|
572
|
+
*
|
|
573
|
+
* @example
|
|
574
|
+
* The following example illustrates a basic menu. The `m3e-menu-trigger` is used to trigger a `m3e-menu` specified
|
|
575
|
+
* by the `for` attribute when its parenting element is activated.
|
|
576
|
+
* ```html
|
|
577
|
+
* <m3e-button>
|
|
578
|
+
* <m3e-menu-trigger for="menu1">Basic menu</m3e-menu-trigger>
|
|
579
|
+
* </m3e-button>
|
|
580
|
+
* <m3e-menu id="menu1">
|
|
581
|
+
* <m3e-menu-item>Apple</m3e-menu-item>
|
|
582
|
+
* <m3e-menu-item>Apricot</m3e-menu-item>
|
|
583
|
+
* <m3e-menu-item>Avocado</m3e-menu-item>
|
|
584
|
+
* <m3e-menu-item>Green Apple</m3e-menu-item>
|
|
585
|
+
* <m3e-menu-item>Green Grapes</m3e-menu-item>
|
|
586
|
+
* <m3e-menu-item>Olive</m3e-menu-item>
|
|
587
|
+
* <m3e-menu-item>Orange</m3e-menu-item>
|
|
588
|
+
* </m3e-menu>
|
|
589
|
+
* ```
|
|
590
|
+
*
|
|
591
|
+
* @example
|
|
592
|
+
* The next example illustrates nested menus. Submenus are triggered by placing a `m3e-menu-trigger` inside a `m3e-menu-item`.
|
|
593
|
+
* ```html
|
|
594
|
+
* <m3e-button>
|
|
595
|
+
* <m3e-menu-trigger for="menu2">Nested menus</m3e-menu-trigger>
|
|
596
|
+
* </m3e-button>
|
|
597
|
+
* <m3e-menu id="menu2">
|
|
598
|
+
* <m3e-menu-item>
|
|
599
|
+
* <m3e-menu-trigger for="menu3">Fruits with A</m3e-menu-trigger>
|
|
600
|
+
* </m3e-menu-item>
|
|
601
|
+
* <m3e-menu-item>Grapes</m3e-menu-item>
|
|
602
|
+
* <m3e-menu-item>Olive</m3e-menu-item>
|
|
603
|
+
* <m3e-menu-item>Orange</m3e-menu-item>
|
|
604
|
+
* </m3e-menu>
|
|
605
|
+
* <m3e-menu id="menu3">
|
|
606
|
+
* <m3e-menu-item>Apricot</m3e-menu-item>
|
|
607
|
+
* <m3e-menu-item>Avocado</m3e-menu-item>
|
|
608
|
+
* <m3e-menu-item>
|
|
609
|
+
* <m3e-menu-trigger for="menu4">Apples</m3e-menu-trigger>
|
|
610
|
+
* </m3e-menu-item>
|
|
611
|
+
* </m3e-menu>
|
|
612
|
+
* <m3e-menu id="menu4">
|
|
613
|
+
* <m3e-menu-item>Fuji</m3e-menu-item>
|
|
614
|
+
* <m3e-menu-item>Granny Smith</m3e-menu-item>
|
|
615
|
+
* <m3e-menu-item>Red Delicious</m3e-menu-item>
|
|
616
|
+
* </m3e-menu>
|
|
617
|
+
* ```
|
|
618
|
+
*
|
|
619
|
+
* @tag m3e-menu
|
|
620
|
+
*
|
|
621
|
+
* @slot - Renders the contents of the menu.
|
|
622
|
+
*
|
|
623
|
+
* @attr position-x - The position of the menu, on the x-axis.
|
|
624
|
+
* @attr position-y - The position of the menu, on the y-axis.
|
|
625
|
+
*
|
|
626
|
+
* @fires beforetoggle - Dispatched before the toggle state changes.
|
|
627
|
+
* @fires toggle - Dispatched after the toggle state has changed.
|
|
628
|
+
*
|
|
629
|
+
* @cssprop --m3e-menu-container-shape - Controls the corner radius of the menu container.
|
|
630
|
+
* @cssprop --m3e-menu-container-min-width - Minimum width of the menu container.
|
|
631
|
+
* @cssprop --m3e-menu-container-max-width - Maximum width of the menu container.
|
|
632
|
+
* @cssprop --m3e-menu-container-max-height - Maximum height of the menu container.
|
|
633
|
+
* @cssprop --m3e-menu-container-padding-block - Vertical padding inside the menu container.
|
|
634
|
+
* @cssprop --m3e-menu-container-color - Background color of the menu container.
|
|
635
|
+
* @cssprop --m3e-menu-container-elevation - Box shadow elevation of the menu container.
|
|
636
|
+
* @cssprop --m3e-menu-divider-spacing - Vertical spacing around slotted `m3e-divider` elements.
|
|
637
|
+
*/
|
|
638
|
+
let M3eMenuElement = M3eMenuElement_1 = class M3eMenuElement extends Role(LitElement, "menu") {
|
|
639
|
+
constructor() {
|
|
640
|
+
super(...arguments);
|
|
641
|
+
_M3eMenuElement_instances.add(this);
|
|
642
|
+
/** @private */ _M3eMenuElement_trigger.set(this, void 0);
|
|
643
|
+
/** @private */ _M3eMenuElement_anchorCleanup.set(this, void 0);
|
|
644
|
+
/** @private */ _M3eMenuElement_listManager.set(this, new RovingTabIndexManager()
|
|
645
|
+
.withWrap()
|
|
646
|
+
.withHomeAndEnd()
|
|
647
|
+
.withVerticalOrientation());
|
|
648
|
+
/** @private */ _M3eMenuElement_keyDownHandler.set(this, (e) => __classPrivateFieldGet(this, _M3eMenuElement_instances, "m", _M3eMenuElement_handleKeyDown).call(this, e));
|
|
649
|
+
/** @private */ _M3eMenuElement_documentClickHandler.set(this, (e) => __classPrivateFieldGet(this, _M3eMenuElement_instances, "m", _M3eMenuElement_handleDocumentClick).call(this, e));
|
|
650
|
+
/** @private */ _M3eMenuElement_scrollController.set(this, new ScrollController(this, {
|
|
651
|
+
target: null,
|
|
652
|
+
callback: (target) => target instanceof M3eMenuElement_1
|
|
653
|
+
? target.items.filter((x) => x instanceof M3eMenuItemElement).forEach((x) => x.submenu?.hide())
|
|
654
|
+
: this.hideAll(),
|
|
655
|
+
}));
|
|
656
|
+
/** @private */ _M3eMenuElement_toggleHandler.set(this, (e) => {
|
|
657
|
+
if (e.newState === "closed") {
|
|
658
|
+
__classPrivateFieldGet(this, _M3eMenuElement_anchorCleanup, "f")?.call(this);
|
|
659
|
+
__classPrivateFieldSet(this, _M3eMenuElement_anchorCleanup, undefined, "f");
|
|
660
|
+
}
|
|
661
|
+
else {
|
|
662
|
+
setTimeout(() => {
|
|
663
|
+
__classPrivateFieldGet(this, _M3eMenuElement_listManager, "f").setActiveItem(__classPrivateFieldGet(this, _M3eMenuElement_listManager, "f").items.find((x) => !x.disabled));
|
|
664
|
+
}, 40);
|
|
665
|
+
}
|
|
666
|
+
});
|
|
667
|
+
/**
|
|
668
|
+
* The position of the menu, on the x-axis.
|
|
669
|
+
* @default "after"
|
|
670
|
+
*/
|
|
671
|
+
this.positionX = "after";
|
|
672
|
+
/**
|
|
673
|
+
* The position of the menu, on the y-axis.
|
|
674
|
+
* @default "below"
|
|
675
|
+
*/
|
|
676
|
+
this.positionY = "below";
|
|
677
|
+
/** A value indicating whether the menu is a submenu. */
|
|
678
|
+
this.submenu = false;
|
|
679
|
+
}
|
|
680
|
+
/** The items of the menu. */
|
|
681
|
+
get items() {
|
|
682
|
+
return __classPrivateFieldGet(this, _M3eMenuElement_listManager, "f").items;
|
|
683
|
+
}
|
|
684
|
+
/** A value indicating whether the menu is open. */
|
|
685
|
+
get isOpen() {
|
|
686
|
+
return __classPrivateFieldGet(this, _M3eMenuElement_trigger, "f") !== undefined;
|
|
687
|
+
}
|
|
688
|
+
/** @inheritdoc */
|
|
689
|
+
connectedCallback() {
|
|
690
|
+
super.connectedCallback();
|
|
691
|
+
this.tabIndex = -1;
|
|
692
|
+
this.setAttribute("popover", "manual");
|
|
693
|
+
this.addEventListener("keydown", __classPrivateFieldGet(this, _M3eMenuElement_keyDownHandler, "f"));
|
|
694
|
+
this.addEventListener("toggle", __classPrivateFieldGet(this, _M3eMenuElement_toggleHandler, "f"));
|
|
695
|
+
document.addEventListener("click", __classPrivateFieldGet(this, _M3eMenuElement_documentClickHandler, "f"));
|
|
696
|
+
}
|
|
697
|
+
/** @inheritdoc */
|
|
698
|
+
disconnectedCallback() {
|
|
699
|
+
super.disconnectedCallback();
|
|
700
|
+
this.removeEventListener("keydown", __classPrivateFieldGet(this, _M3eMenuElement_keyDownHandler, "f"));
|
|
701
|
+
this.removeEventListener("toggle", __classPrivateFieldGet(this, _M3eMenuElement_toggleHandler, "f"));
|
|
702
|
+
document.removeEventListener("click", __classPrivateFieldGet(this, _M3eMenuElement_documentClickHandler, "f"));
|
|
703
|
+
}
|
|
704
|
+
/**
|
|
705
|
+
* Opens the menu.
|
|
706
|
+
* @param {HTMLElement} trigger The element that triggered the menu.
|
|
707
|
+
* @returns {Promise<void>} A `Promise` that resolves when the menu is opened.
|
|
708
|
+
*/
|
|
709
|
+
async show(trigger) {
|
|
710
|
+
if (__classPrivateFieldGet(this, _M3eMenuElement_trigger, "f") && __classPrivateFieldGet(this, _M3eMenuElement_trigger, "f") !== trigger) {
|
|
711
|
+
this.hide();
|
|
712
|
+
}
|
|
713
|
+
__classPrivateFieldSet(this, _M3eMenuElement_anchorCleanup, await positionAnchor(this, trigger, {
|
|
714
|
+
position: this.submenu
|
|
715
|
+
? this.positionX === "before"
|
|
716
|
+
? "left-start"
|
|
717
|
+
: "right-start"
|
|
718
|
+
: this.positionY === "above"
|
|
719
|
+
? this.positionX === "before"
|
|
720
|
+
? "top-end"
|
|
721
|
+
: "top-start"
|
|
722
|
+
: this.positionX === "before"
|
|
723
|
+
? "bottom-end"
|
|
724
|
+
: "bottom-start",
|
|
725
|
+
inline: true,
|
|
726
|
+
flip: true,
|
|
727
|
+
shift: true,
|
|
728
|
+
offset: !this.submenu ? 4 : undefined,
|
|
729
|
+
}, (x, y, position) => {
|
|
730
|
+
if (!this.submenu) {
|
|
731
|
+
this.classList.toggle("-top", position.includes("top"));
|
|
732
|
+
this.classList.toggle("-bottom", position.includes("bottom"));
|
|
733
|
+
}
|
|
734
|
+
else if (__classPrivateFieldGet(this, _M3eMenuElement_trigger, "f")) {
|
|
735
|
+
const top = __classPrivateFieldGet(this, _M3eMenuElement_instances, "m", _M3eMenuElement_getAbsolutePosition).call(this, __classPrivateFieldGet(this, _M3eMenuElement_trigger, "f")).y;
|
|
736
|
+
this.classList.toggle("-shift-down", false);
|
|
737
|
+
this.classList.toggle("-shift-up", false);
|
|
738
|
+
this.classList.toggle(Math.round(y) === Math.round(top) ? "-shift-down" : "-shift-up", true);
|
|
739
|
+
}
|
|
740
|
+
this.style.left = `${x}px`;
|
|
741
|
+
this.style.top = `${y}px`;
|
|
742
|
+
}), "f");
|
|
743
|
+
this.showPopover();
|
|
744
|
+
__classPrivateFieldSet(this, _M3eMenuElement_trigger, trigger, "f");
|
|
745
|
+
__classPrivateFieldGet(this, _M3eMenuElement_trigger, "f").ariaExpanded = "true";
|
|
746
|
+
__classPrivateFieldGet(this, _M3eMenuElement_scrollController, "f").observe(__classPrivateFieldGet(this, _M3eMenuElement_trigger, "f"));
|
|
747
|
+
}
|
|
748
|
+
/**
|
|
749
|
+
* Hides the menu.
|
|
750
|
+
* @param {boolean} [restoreFocus=false] A value indicating whether to restore focus to the menu's trigger.
|
|
751
|
+
*/
|
|
752
|
+
hide(restoreFocus = false) {
|
|
753
|
+
for (const item of __classPrivateFieldGet(this, _M3eMenuElement_listManager, "f").items) {
|
|
754
|
+
const submenu = item.submenu;
|
|
755
|
+
if (submenu && submenu.isOpen) {
|
|
756
|
+
submenu.hide();
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
this.hidePopover();
|
|
760
|
+
if (__classPrivateFieldGet(this, _M3eMenuElement_trigger, "f")) {
|
|
761
|
+
__classPrivateFieldGet(this, _M3eMenuElement_trigger, "f").ariaExpanded = "false";
|
|
762
|
+
if (restoreFocus) {
|
|
763
|
+
__classPrivateFieldGet(this, _M3eMenuElement_trigger, "f").focus();
|
|
764
|
+
}
|
|
765
|
+
__classPrivateFieldGet(this, _M3eMenuElement_scrollController, "f").unobserve(__classPrivateFieldGet(this, _M3eMenuElement_trigger, "f"));
|
|
766
|
+
__classPrivateFieldSet(this, _M3eMenuElement_trigger, undefined, "f");
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
/**
|
|
770
|
+
* Closes this menu and any parenting menus.
|
|
771
|
+
* @param {boolean} [restoreFocus=false] A value indicating whether to restore focus to the menu's trigger.
|
|
772
|
+
*/
|
|
773
|
+
hideAll(restoreFocus = false) {
|
|
774
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
775
|
+
let menu = this;
|
|
776
|
+
while (__classPrivateFieldGet(menu, _M3eMenuElement_trigger, "f")) {
|
|
777
|
+
const parent = __classPrivateFieldGet(menu, _M3eMenuElement_trigger, "f").closest("m3e-menu");
|
|
778
|
+
if (!parent) {
|
|
779
|
+
break;
|
|
780
|
+
}
|
|
781
|
+
menu = parent;
|
|
782
|
+
}
|
|
783
|
+
menu.hide(restoreFocus);
|
|
784
|
+
}
|
|
785
|
+
/**
|
|
786
|
+
* Toggles the menu.
|
|
787
|
+
* @param {HTMLElement} trigger The element that triggered the menu.
|
|
788
|
+
* @returns {Promise<void>} A `Promise` that resolves when the menu is opened or closed.
|
|
789
|
+
*/
|
|
790
|
+
async toggle(trigger) {
|
|
791
|
+
if (__classPrivateFieldGet(this, _M3eMenuElement_trigger, "f")) {
|
|
792
|
+
this.hide();
|
|
793
|
+
}
|
|
794
|
+
else {
|
|
795
|
+
await this.show(trigger);
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
/** @inheritdoc */
|
|
799
|
+
render() {
|
|
800
|
+
return html `<slot @slotchange="${__classPrivateFieldGet(this, _M3eMenuElement_instances, "m", _M3eMenuElement_handleSlotChange)}"></slot>`;
|
|
801
|
+
}
|
|
802
|
+
};
|
|
803
|
+
_M3eMenuElement_trigger = new WeakMap();
|
|
804
|
+
_M3eMenuElement_anchorCleanup = new WeakMap();
|
|
805
|
+
_M3eMenuElement_listManager = new WeakMap();
|
|
806
|
+
_M3eMenuElement_keyDownHandler = new WeakMap();
|
|
807
|
+
_M3eMenuElement_documentClickHandler = new WeakMap();
|
|
808
|
+
_M3eMenuElement_scrollController = new WeakMap();
|
|
809
|
+
_M3eMenuElement_toggleHandler = new WeakMap();
|
|
810
|
+
_M3eMenuElement_instances = new WeakSet();
|
|
811
|
+
_M3eMenuElement_handleSlotChange = function _M3eMenuElement_handleSlotChange() {
|
|
812
|
+
const { added } = __classPrivateFieldGet(this, _M3eMenuElement_listManager, "f").setItems([
|
|
813
|
+
...this.querySelectorAll("m3e-menu-item,m3e-menu-item-checkbox,m3e-menu-item-radio"),
|
|
814
|
+
].filter((x) => x.closest("m3e-menu") === this));
|
|
815
|
+
if (!__classPrivateFieldGet(this, _M3eMenuElement_listManager, "f").activeItem) {
|
|
816
|
+
__classPrivateFieldGet(this, _M3eMenuElement_listManager, "f").updateActiveItem(added.find((x) => !x.disabled));
|
|
817
|
+
}
|
|
818
|
+
};
|
|
819
|
+
_M3eMenuElement_handleKeyDown = function _M3eMenuElement_handleKeyDown(e) {
|
|
820
|
+
switch (e.key) {
|
|
821
|
+
case "Left":
|
|
822
|
+
case "ArrowLeft":
|
|
823
|
+
e.preventDefault();
|
|
824
|
+
this.hide(true);
|
|
825
|
+
break;
|
|
826
|
+
case "Tab":
|
|
827
|
+
this.hideAll();
|
|
828
|
+
break;
|
|
829
|
+
case "Escape":
|
|
830
|
+
if (!e.shiftKey && !e.ctrlKey) {
|
|
831
|
+
this.hide(true);
|
|
832
|
+
}
|
|
833
|
+
break;
|
|
834
|
+
default:
|
|
835
|
+
__classPrivateFieldGet(this, _M3eMenuElement_listManager, "f").onKeyDown(e);
|
|
836
|
+
break;
|
|
837
|
+
}
|
|
838
|
+
};
|
|
839
|
+
_M3eMenuElement_handleDocumentClick = function _M3eMenuElement_handleDocumentClick(e) {
|
|
840
|
+
if (!this.submenu && !e.composedPath().some((x) => x instanceof M3eMenuElement_1 || x === __classPrivateFieldGet(this, _M3eMenuElement_trigger, "f"))) {
|
|
841
|
+
this.hide();
|
|
842
|
+
}
|
|
843
|
+
};
|
|
844
|
+
_M3eMenuElement_getAbsolutePosition = function _M3eMenuElement_getAbsolutePosition(element) {
|
|
845
|
+
let x = 0, y = 0;
|
|
846
|
+
for (let current = element; current; current = current.offsetParent instanceof HTMLElement ? current.offsetParent : null) {
|
|
847
|
+
x += current.offsetLeft - current.scrollLeft + current.clientLeft;
|
|
848
|
+
y += current.offsetTop - current.scrollTop + current.clientTop;
|
|
849
|
+
}
|
|
850
|
+
return { x, y };
|
|
851
|
+
};
|
|
852
|
+
/** The styles of the element. */
|
|
853
|
+
M3eMenuElement.styles = css `
|
|
854
|
+
:host {
|
|
855
|
+
position: absolute;
|
|
856
|
+
flex-direction: column;
|
|
857
|
+
padding: unset;
|
|
858
|
+
margin: unset;
|
|
859
|
+
border: unset;
|
|
860
|
+
overflow-y: auto;
|
|
861
|
+
scrollbar-width: ${DesignToken.scrollbar.thinWidth};
|
|
862
|
+
scrollbar-color: ${DesignToken.scrollbar.color};
|
|
863
|
+
border-radius: var(--m3e-menu-container-shape, ${DesignToken.shape.corner.extraSmall});
|
|
864
|
+
min-width: var(--m3e-menu-container-min-width, 7rem);
|
|
865
|
+
max-width: var(--m3e-menu-container-max-width, 17.5rem);
|
|
866
|
+
max-height: var(--m3e-menu-container-max-height, 17.5rem);
|
|
867
|
+
padding-block: var(--m3e-menu-container-padding-block, 0.5rem);
|
|
868
|
+
background-color: var(--m3e-menu-container-color, ${DesignToken.color.surfaceContainer});
|
|
869
|
+
box-shadow: var(--m3e-menu-container-elevation, ${DesignToken.elevation.level3});
|
|
870
|
+
opacity: 0;
|
|
871
|
+
display: none;
|
|
872
|
+
transition: ${unsafeCSS(`opacity ${DesignToken.motion.duration.short2} ${DesignToken.motion.easing.standard},
|
|
873
|
+
transform ${DesignToken.motion.duration.short2} ${DesignToken.motion.easing.standard},
|
|
874
|
+
overlay ${DesignToken.motion.duration.short2} ${DesignToken.motion.easing.standard} allow-discrete,
|
|
875
|
+
display ${DesignToken.motion.duration.short2} ${DesignToken.motion.easing.standard} allow-discrete`)};
|
|
876
|
+
}
|
|
877
|
+
:host(:not([submenu])) {
|
|
878
|
+
transform: scaleY(0.8);
|
|
879
|
+
}
|
|
880
|
+
:host(:not([submenu]):popover-open) {
|
|
881
|
+
transform: scaleY(1);
|
|
882
|
+
}
|
|
883
|
+
:host::backdrop {
|
|
884
|
+
background-color: transparent;
|
|
885
|
+
}
|
|
886
|
+
:host(:popover-open) {
|
|
887
|
+
display: inline-flex;
|
|
888
|
+
opacity: 1;
|
|
889
|
+
}
|
|
890
|
+
:host(.-bottom) {
|
|
891
|
+
transform-origin: top;
|
|
892
|
+
}
|
|
893
|
+
:host(.-top) {
|
|
894
|
+
transform-origin: bottom;
|
|
895
|
+
}
|
|
896
|
+
:host(.-shift-down) {
|
|
897
|
+
margin-top: calc(0px - var(--m3e-menu-container-padding-block, 0.5rem));
|
|
898
|
+
}
|
|
899
|
+
:host(.-shift-up) {
|
|
900
|
+
margin-top: var(--m3e-menu-container-padding-block, 0.5rem);
|
|
901
|
+
}
|
|
902
|
+
::slotted(m3e-divider) {
|
|
903
|
+
margin-block: var(--m3e-menu-divider-spacing, 0.5rem);
|
|
904
|
+
}
|
|
905
|
+
@starting-style {
|
|
906
|
+
:host(:popover-open) {
|
|
907
|
+
opacity: 0;
|
|
908
|
+
}
|
|
909
|
+
:host(:not([submenu]):popover-open) {
|
|
910
|
+
transform: scaleY(0.8);
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
@media (prefers-reduced-motion) {
|
|
914
|
+
:host {
|
|
915
|
+
transition: none;
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
@media (forced-colors: active) {
|
|
919
|
+
:host {
|
|
920
|
+
background-color: Menu;
|
|
921
|
+
color: MenuText;
|
|
922
|
+
border: 1px solid CanvasText;
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
`;
|
|
926
|
+
__decorate([
|
|
927
|
+
n({ attribute: "position-x" })
|
|
928
|
+
], M3eMenuElement.prototype, "positionX", void 0);
|
|
929
|
+
__decorate([
|
|
930
|
+
n({ attribute: "position-y" })
|
|
931
|
+
], M3eMenuElement.prototype, "positionY", void 0);
|
|
932
|
+
__decorate([
|
|
933
|
+
n({ type: Boolean, reflect: true })
|
|
934
|
+
], M3eMenuElement.prototype, "submenu", void 0);
|
|
935
|
+
M3eMenuElement = M3eMenuElement_1 = __decorate([
|
|
936
|
+
t$1("m3e-menu")
|
|
937
|
+
], M3eMenuElement);
|
|
938
|
+
|
|
939
|
+
var _M3eMenuItemCheckboxElement_instances, _M3eMenuItemCheckboxElement_clickHandler, _M3eMenuItemCheckboxElement_keyDownHandler, _M3eMenuItemCheckboxElement_keyUpHandler, _M3eMenuItemCheckboxElement_mouseEnterHandler, _M3eMenuItemCheckboxElement_spacePressed, _M3eMenuItemCheckboxElement_handleIconSlotChange, _M3eMenuItemCheckboxElement_handleTrailingIconSlotChange, _M3eMenuItemCheckboxElement_handleClick, _M3eMenuItemCheckboxElement_handleKeyDown, _M3eMenuItemCheckboxElement_handleKeyUp, _M3eMenuItemCheckboxElement_handleMouseEnter;
|
|
940
|
+
/**
|
|
941
|
+
* @summary
|
|
942
|
+
* An item of a menu which supports a checkable state.
|
|
943
|
+
*
|
|
944
|
+
* @description
|
|
945
|
+
* The `m3e-menu-item-checkbox` component represents a menu item that supports an independent checkable state.
|
|
946
|
+
* It allows users to toggle options on or off without affecting other items in the menu, making it ideal for
|
|
947
|
+
* multi-select scenarios such as filters, visibility toggles, or feature flags. This component encodes a persistent
|
|
948
|
+
* selection contract and can coexist with other checkbox or radio items within the same menu.
|
|
949
|
+
*
|
|
950
|
+
* @example
|
|
951
|
+
* The following example illustrates use of the `m3e-menu-item-checkbox` to present multiple independent checkable
|
|
952
|
+
* items in a menu.
|
|
953
|
+
* ```html
|
|
954
|
+
* <m3e-button>
|
|
955
|
+
* <m3e-menu-trigger for="menu">Format</m3e-menu-trigger>
|
|
956
|
+
* </m3e-button>
|
|
957
|
+
* <m3e-menu id="menu">
|
|
958
|
+
* <m3e-menu-item-checkbox>Bold</m3e-menu-item-checkbox>
|
|
959
|
+
* <m3e-menu-item-checkbox>Italic</m3e-menu-item-checkbox>
|
|
960
|
+
* <m3e-menu-item-checkbox>Underline</m3e-menu-item-checkbox>
|
|
961
|
+
* </m3e-menu>
|
|
962
|
+
* ```
|
|
963
|
+
*
|
|
964
|
+
* @tag m3e-menu-item-checkbox
|
|
965
|
+
*
|
|
966
|
+
* @slot - Renders the label of the item.
|
|
967
|
+
* @slot icon - Renders an icon before the items's label.
|
|
968
|
+
* @slot trailing-icon - Renders an icon after the item's label.
|
|
969
|
+
*
|
|
970
|
+
* @attr disabled - Whether the element is disabled.
|
|
971
|
+
* @attr checked - Whether the element is checked.
|
|
972
|
+
*
|
|
973
|
+
* @cssprop --m3e-menu-item-container-height - Height of the menu item container.
|
|
974
|
+
* @cssprop --m3e-menu-item-color - Text color for unselected, enabled menu items.
|
|
975
|
+
* @cssprop --m3e-menu-item-container-hover-color - State layer hover color for unselected items.
|
|
976
|
+
* @cssprop --m3e-menu-item-container-focus-color - State layer focus color for unselected items.
|
|
977
|
+
* @cssprop --m3e-menu-item-ripple-color - Ripple color for unselected items.
|
|
978
|
+
* @cssprop --m3e-menu-selected-color - Text color for selected or expanded items.
|
|
979
|
+
* @cssprop --m3e-menu-selected-container-color - Background color for selected or expanded items.
|
|
980
|
+
* @cssprop --m3e-menu-item-selected-container-hover-color - State layer hover color for selected items.
|
|
981
|
+
* @cssprop --m3e-menu-item-selected-container-focus-color - State layer focus color for selected items.
|
|
982
|
+
* @cssprop --m3e-menu-item-selected-ripple-color - Ripple color for selected items.
|
|
983
|
+
* @cssprop --m3e-menu-item-disabled-color - Base color for disabled items.
|
|
984
|
+
* @cssprop --m3e-menu-item-disabled-opacity - Opacity percentage for disabled item color mix.
|
|
985
|
+
* @cssprop --m3e-menu-item-icon-label-space - Horizontal gap between icon and content.
|
|
986
|
+
* @cssprop --m3e-menu-item-padding-start - Start padding for the item wrapper.
|
|
987
|
+
* @cssprop --m3e-menu-item-padding-end - End padding for the item wrapper.
|
|
988
|
+
* @cssprop --m3e-menu-item-label-text-font-size - Font size for menu item text.
|
|
989
|
+
* @cssprop --m3e-menu-item-label-text-font-weight - Font weight for menu item text.
|
|
990
|
+
* @cssprop --m3e-menu-item-label-text-line-height - Line height for menu item text.
|
|
991
|
+
* @cssprop --m3e-menu-item-label-text-tracking - Letter spacing for menu item text.
|
|
992
|
+
* @cssprop --m3e-menu-item-focus-ring-shape - Border radius for the focus ring.
|
|
993
|
+
* @cssprop --m3e-menu-item-icon-size - Font size for leading and trailing icons.
|
|
994
|
+
*/
|
|
995
|
+
let M3eMenuItemCheckboxElement = class M3eMenuItemCheckboxElement extends Checked(Role(MenuItemElementBase, "menuitemcheckbox")) {
|
|
996
|
+
constructor() {
|
|
997
|
+
super(...arguments);
|
|
998
|
+
_M3eMenuItemCheckboxElement_instances.add(this);
|
|
999
|
+
/** @internal */ _M3eMenuItemCheckboxElement_clickHandler.set(this, (e) => __classPrivateFieldGet(this, _M3eMenuItemCheckboxElement_instances, "m", _M3eMenuItemCheckboxElement_handleClick).call(this, e));
|
|
1000
|
+
/** @internal */ _M3eMenuItemCheckboxElement_keyDownHandler.set(this, (e) => __classPrivateFieldGet(this, _M3eMenuItemCheckboxElement_instances, "m", _M3eMenuItemCheckboxElement_handleKeyDown).call(this, e));
|
|
1001
|
+
/** @internal */ _M3eMenuItemCheckboxElement_keyUpHandler.set(this, () => __classPrivateFieldGet(this, _M3eMenuItemCheckboxElement_instances, "m", _M3eMenuItemCheckboxElement_handleKeyUp).call(this));
|
|
1002
|
+
/** @internal */ _M3eMenuItemCheckboxElement_mouseEnterHandler.set(this, () => __classPrivateFieldGet(this, _M3eMenuItemCheckboxElement_instances, "m", _M3eMenuItemCheckboxElement_handleMouseEnter).call(this));
|
|
1003
|
+
/** @internal */ _M3eMenuItemCheckboxElement_spacePressed.set(this, false);
|
|
1004
|
+
}
|
|
1005
|
+
/** @inheritdoc */
|
|
1006
|
+
connectedCallback() {
|
|
1007
|
+
super.connectedCallback();
|
|
1008
|
+
this.addEventListener("click", __classPrivateFieldGet(this, _M3eMenuItemCheckboxElement_clickHandler, "f"));
|
|
1009
|
+
this.addEventListener("keydown", __classPrivateFieldGet(this, _M3eMenuItemCheckboxElement_keyDownHandler, "f"));
|
|
1010
|
+
this.addEventListener("keyup", __classPrivateFieldGet(this, _M3eMenuItemCheckboxElement_keyUpHandler, "f"));
|
|
1011
|
+
this.addEventListener("mouseenter", __classPrivateFieldGet(this, _M3eMenuItemCheckboxElement_mouseEnterHandler, "f"));
|
|
1012
|
+
}
|
|
1013
|
+
/** @inheritdoc */
|
|
1014
|
+
disconnectedCallback() {
|
|
1015
|
+
super.disconnectedCallback();
|
|
1016
|
+
this.removeEventListener("click", __classPrivateFieldGet(this, _M3eMenuItemCheckboxElement_clickHandler, "f"));
|
|
1017
|
+
this.removeEventListener("keydown", __classPrivateFieldGet(this, _M3eMenuItemCheckboxElement_keyDownHandler, "f"));
|
|
1018
|
+
this.removeEventListener("keyup", __classPrivateFieldGet(this, _M3eMenuItemCheckboxElement_keyUpHandler, "f"));
|
|
1019
|
+
this.removeEventListener("mouseenter", __classPrivateFieldGet(this, _M3eMenuItemCheckboxElement_mouseEnterHandler, "f"));
|
|
1020
|
+
}
|
|
1021
|
+
/** @internal @inheritdoc */
|
|
1022
|
+
_renderContent() {
|
|
1023
|
+
return html ` <div class="icon">
|
|
1024
|
+
<svg class="check" viewBox="0 -960 960 960" aria-hidden="true">
|
|
1025
|
+
<path fill="currentColor" d="M382-240 154-468l57-57 171 171 367-367 57 57-424 424Z" />
|
|
1026
|
+
</svg>
|
|
1027
|
+
<slot name="icon" @slotchange="${__classPrivateFieldGet(this, _M3eMenuItemCheckboxElement_instances, "m", _M3eMenuItemCheckboxElement_handleIconSlotChange)}"></slot>
|
|
1028
|
+
</div>
|
|
1029
|
+
<slot></slot>
|
|
1030
|
+
<slot name="trailing-icon" aria-hidden="true" @slotchange="${__classPrivateFieldGet(this, _M3eMenuItemCheckboxElement_instances, "m", _M3eMenuItemCheckboxElement_handleTrailingIconSlotChange)}"></slot>`;
|
|
1031
|
+
}
|
|
1032
|
+
};
|
|
1033
|
+
_M3eMenuItemCheckboxElement_clickHandler = new WeakMap();
|
|
1034
|
+
_M3eMenuItemCheckboxElement_keyDownHandler = new WeakMap();
|
|
1035
|
+
_M3eMenuItemCheckboxElement_keyUpHandler = new WeakMap();
|
|
1036
|
+
_M3eMenuItemCheckboxElement_mouseEnterHandler = new WeakMap();
|
|
1037
|
+
_M3eMenuItemCheckboxElement_spacePressed = new WeakMap();
|
|
1038
|
+
_M3eMenuItemCheckboxElement_instances = new WeakSet();
|
|
1039
|
+
_M3eMenuItemCheckboxElement_handleIconSlotChange = function _M3eMenuItemCheckboxElement_handleIconSlotChange(e) {
|
|
1040
|
+
this.classList.toggle("-with-icon", hasAssignedNodes(e.target));
|
|
1041
|
+
};
|
|
1042
|
+
_M3eMenuItemCheckboxElement_handleTrailingIconSlotChange = function _M3eMenuItemCheckboxElement_handleTrailingIconSlotChange(e) {
|
|
1043
|
+
this.classList.toggle("-with-trailing-icon", hasAssignedNodes(e.target));
|
|
1044
|
+
};
|
|
1045
|
+
_M3eMenuItemCheckboxElement_handleClick = function _M3eMenuItemCheckboxElement_handleClick(e) {
|
|
1046
|
+
if (!e.defaultPrevented) {
|
|
1047
|
+
this.checked = !this.checked;
|
|
1048
|
+
this.performUpdate();
|
|
1049
|
+
if (!__classPrivateFieldGet(this, _M3eMenuItemCheckboxElement_spacePressed, "f")) {
|
|
1050
|
+
this.menu?.hideAll(true);
|
|
1051
|
+
}
|
|
1052
|
+
}
|
|
1053
|
+
};
|
|
1054
|
+
_M3eMenuItemCheckboxElement_handleKeyDown = function _M3eMenuItemCheckboxElement_handleKeyDown(e) {
|
|
1055
|
+
__classPrivateFieldSet(this, _M3eMenuItemCheckboxElement_spacePressed, e.key === " ", "f");
|
|
1056
|
+
};
|
|
1057
|
+
_M3eMenuItemCheckboxElement_handleKeyUp = function _M3eMenuItemCheckboxElement_handleKeyUp() {
|
|
1058
|
+
__classPrivateFieldSet(this, _M3eMenuItemCheckboxElement_spacePressed, false, "f");
|
|
1059
|
+
};
|
|
1060
|
+
_M3eMenuItemCheckboxElement_handleMouseEnter = function _M3eMenuItemCheckboxElement_handleMouseEnter() {
|
|
1061
|
+
this.menu?.items.forEach((item) => {
|
|
1062
|
+
if (item instanceof M3eMenuItemElement && item.submenu?.isOpen) {
|
|
1063
|
+
item.submenu.hide();
|
|
1064
|
+
}
|
|
1065
|
+
});
|
|
1066
|
+
};
|
|
1067
|
+
/** The styles of the element. */
|
|
1068
|
+
M3eMenuItemCheckboxElement.styles = [
|
|
1069
|
+
MenuItemElementBase.styles,
|
|
1070
|
+
css `
|
|
1071
|
+
.icon {
|
|
1072
|
+
display: flex;
|
|
1073
|
+
align-items: center;
|
|
1074
|
+
justify-content: center;
|
|
1075
|
+
}
|
|
1076
|
+
:host(:not(.-with-icon)) .icon {
|
|
1077
|
+
margin-inline-start: calc(0px - var(--m3e-menu-item-icon-label-space, 0.75rem));
|
|
1078
|
+
}
|
|
1079
|
+
.check {
|
|
1080
|
+
width: 1em;
|
|
1081
|
+
font-size: var(--m3e-menu-item-icon-size, 1.5rem) !important;
|
|
1082
|
+
}
|
|
1083
|
+
:host(:not([checked])) .check {
|
|
1084
|
+
display: none;
|
|
1085
|
+
}
|
|
1086
|
+
:host([checked]) .icon {
|
|
1087
|
+
margin-inline-start: 0;
|
|
1088
|
+
}
|
|
1089
|
+
:host([checked]) ::slotted([slot="icon"]) {
|
|
1090
|
+
display: none !important;
|
|
1091
|
+
}
|
|
1092
|
+
`,
|
|
1093
|
+
];
|
|
1094
|
+
M3eMenuItemCheckboxElement = __decorate([
|
|
1095
|
+
t$1("m3e-menu-item-checkbox")
|
|
1096
|
+
], M3eMenuItemCheckboxElement);
|
|
1097
|
+
|
|
1098
|
+
/**
|
|
1099
|
+
* @summary
|
|
1100
|
+
* Groups related items (such a radios) in a menu.
|
|
1101
|
+
*
|
|
1102
|
+
* @description
|
|
1103
|
+
* The `m3e-menu-item-group` component groups related items within a menu, establishing a shared
|
|
1104
|
+
* context for interaction and selection. It enables separation of concerns—such as organizing radio
|
|
1105
|
+
* items into mutually exclusive sets.
|
|
1106
|
+
*
|
|
1107
|
+
* @tag m3e-menu-item-group
|
|
1108
|
+
*
|
|
1109
|
+
* @slot - Renders the contents of the group.
|
|
1110
|
+
*/
|
|
1111
|
+
let M3eMenuItemGroupElement = class M3eMenuItemGroupElement extends Role(LitElement, "group") {
|
|
1112
|
+
/** @inheritdoc */
|
|
1113
|
+
render() {
|
|
1114
|
+
return html `<slot></slot>`;
|
|
1115
|
+
}
|
|
1116
|
+
};
|
|
1117
|
+
/** The styles of the element. */
|
|
1118
|
+
M3eMenuItemGroupElement.styles = css `
|
|
1119
|
+
:host {
|
|
1120
|
+
display: contents;
|
|
1121
|
+
}
|
|
1122
|
+
`;
|
|
1123
|
+
M3eMenuItemGroupElement = __decorate([
|
|
1124
|
+
t$1("m3e-menu-item-group")
|
|
1125
|
+
], M3eMenuItemGroupElement);
|
|
1126
|
+
|
|
1127
|
+
var _M3eMenuItemRadioElement_instances, _M3eMenuItemRadioElement_clickHandler, _M3eMenuItemRadioElement_keyDownHandler, _M3eMenuItemRadioElement_keyUpHandler, _M3eMenuItemRadioElement_mouseEnterHandler, _M3eMenuItemRadioElement_spacePressed, _M3eMenuItemRadioElement_handleIconSlotChange, _M3eMenuItemRadioElement_handleTrailingIconSlotChange, _M3eMenuItemRadioElement_handleClick, _M3eMenuItemRadioElement_handleKeyDown, _M3eMenuItemRadioElement_handleKeyUp, _M3eMenuItemRadioElement_handleMouseEnter;
|
|
1128
|
+
/**
|
|
1129
|
+
* @summary
|
|
1130
|
+
* An item of a menu which supports a mutually exclusive checkable state.
|
|
1131
|
+
*
|
|
1132
|
+
* @description
|
|
1133
|
+
* The `m3e-menu-item-radio` component represents a selectable menu item that participates in a mutually exclusive group.
|
|
1134
|
+
* It reflects a singular choice within a shared context—such as sort order, theme selection, or view mode—and updates
|
|
1135
|
+
* group state when selected. This component can be nested within an `m3e-menu-item-group`, allowing multiple exclusive
|
|
1136
|
+
* groups to coexist within a single menu.
|
|
1137
|
+
*
|
|
1138
|
+
* @example
|
|
1139
|
+
* The following example illustrates use of the `m3e-menu-item-radio` in a `m3e-menu` to allow a user to select a sort order.
|
|
1140
|
+
* The `m3e-menu-trigger` is used to trigger a `m3e-menu` specified by the `for` attribute when its parenting element is activated.
|
|
1141
|
+
* ```html
|
|
1142
|
+
* <m3e-button>
|
|
1143
|
+
* <m3e-menu-trigger for="menu">Sort order</m3e-menu-trigger>
|
|
1144
|
+
* </m3e-button>
|
|
1145
|
+
* <m3e-menu id="menu">
|
|
1146
|
+
* <m3e-menu-item-radio>Ascending</m3e-menu-item-radio>
|
|
1147
|
+
* <m3e-menu-item-radio>Descending</m3e-menu-item-radio>
|
|
1148
|
+
* </m3e-menu>
|
|
1149
|
+
* ```
|
|
1150
|
+
*
|
|
1151
|
+
* @tag m3e-menu-item-radio
|
|
1152
|
+
*
|
|
1153
|
+
* @slot - Renders the label of the item.
|
|
1154
|
+
* @slot icon - Renders an icon before the items's label.
|
|
1155
|
+
* @slot trailing-icon - Renders an icon after the item's label.
|
|
1156
|
+
*
|
|
1157
|
+
* @attr disabled - Whether the element is disabled.
|
|
1158
|
+
* @attr checked - Whether the element is checked.
|
|
1159
|
+
*
|
|
1160
|
+
* @cssprop --m3e-menu-item-container-height - Height of the menu item container.
|
|
1161
|
+
* @cssprop --m3e-menu-item-color - Text color for unselected, enabled menu items.
|
|
1162
|
+
* @cssprop --m3e-menu-item-container-hover-color - State layer hover color for unselected items.
|
|
1163
|
+
* @cssprop --m3e-menu-item-container-focus-color - State layer focus color for unselected items.
|
|
1164
|
+
* @cssprop --m3e-menu-item-ripple-color - Ripple color for unselected items.
|
|
1165
|
+
* @cssprop --m3e-menu-selected-color - Text color for selected or expanded items.
|
|
1166
|
+
* @cssprop --m3e-menu-selected-container-color - Background color for selected or expanded items.
|
|
1167
|
+
* @cssprop --m3e-menu-item-selected-container-hover-color - State layer hover color for selected items.
|
|
1168
|
+
* @cssprop --m3e-menu-item-selected-container-focus-color - State layer focus color for selected items.
|
|
1169
|
+
* @cssprop --m3e-menu-item-selected-ripple-color - Ripple color for selected items.
|
|
1170
|
+
* @cssprop --m3e-menu-item-disabled-color - Base color for disabled items.
|
|
1171
|
+
* @cssprop --m3e-menu-item-disabled-opacity - Opacity percentage for disabled item color mix.
|
|
1172
|
+
* @cssprop --m3e-menu-item-icon-label-space - Horizontal gap between icon and content.
|
|
1173
|
+
* @cssprop --m3e-menu-item-padding-start - Start padding for the item wrapper.
|
|
1174
|
+
* @cssprop --m3e-menu-item-padding-end - End padding for the item wrapper.
|
|
1175
|
+
* @cssprop --m3e-menu-item-label-text-font-size - Font size for menu item text.
|
|
1176
|
+
* @cssprop --m3e-menu-item-label-text-font-weight - Font weight for menu item text.
|
|
1177
|
+
* @cssprop --m3e-menu-item-label-text-line-height - Line height for menu item text.
|
|
1178
|
+
* @cssprop --m3e-menu-item-label-text-tracking - Letter spacing for menu item text.
|
|
1179
|
+
* @cssprop --m3e-menu-item-focus-ring-shape - Border radius for the focus ring.
|
|
1180
|
+
* @cssprop --m3e-menu-item-icon-size - Font size for leading and trailing icons.
|
|
1181
|
+
*/
|
|
1182
|
+
let M3eMenuItemRadioElement = class M3eMenuItemRadioElement extends Checked(Role(MenuItemElementBase, "menuitemradio")) {
|
|
1183
|
+
constructor() {
|
|
1184
|
+
super(...arguments);
|
|
1185
|
+
_M3eMenuItemRadioElement_instances.add(this);
|
|
1186
|
+
/** @private */ _M3eMenuItemRadioElement_clickHandler.set(this, (e) => __classPrivateFieldGet(this, _M3eMenuItemRadioElement_instances, "m", _M3eMenuItemRadioElement_handleClick).call(this, e));
|
|
1187
|
+
/** @private */ _M3eMenuItemRadioElement_keyDownHandler.set(this, (e) => __classPrivateFieldGet(this, _M3eMenuItemRadioElement_instances, "m", _M3eMenuItemRadioElement_handleKeyDown).call(this, e));
|
|
1188
|
+
/** @private */ _M3eMenuItemRadioElement_keyUpHandler.set(this, () => __classPrivateFieldGet(this, _M3eMenuItemRadioElement_instances, "m", _M3eMenuItemRadioElement_handleKeyUp).call(this));
|
|
1189
|
+
/** @private */ _M3eMenuItemRadioElement_mouseEnterHandler.set(this, () => __classPrivateFieldGet(this, _M3eMenuItemRadioElement_instances, "m", _M3eMenuItemRadioElement_handleMouseEnter).call(this));
|
|
1190
|
+
/** @private */ _M3eMenuItemRadioElement_spacePressed.set(this, false);
|
|
1191
|
+
}
|
|
1192
|
+
/** @inheritdoc */
|
|
1193
|
+
connectedCallback() {
|
|
1194
|
+
super.connectedCallback();
|
|
1195
|
+
this.addEventListener("click", __classPrivateFieldGet(this, _M3eMenuItemRadioElement_clickHandler, "f"));
|
|
1196
|
+
this.addEventListener("keydown", __classPrivateFieldGet(this, _M3eMenuItemRadioElement_keyDownHandler, "f"));
|
|
1197
|
+
this.addEventListener("keyup", __classPrivateFieldGet(this, _M3eMenuItemRadioElement_keyUpHandler, "f"));
|
|
1198
|
+
this.addEventListener("mouseenter", __classPrivateFieldGet(this, _M3eMenuItemRadioElement_mouseEnterHandler, "f"));
|
|
1199
|
+
}
|
|
1200
|
+
/** @inheritdoc */
|
|
1201
|
+
disconnectedCallback() {
|
|
1202
|
+
super.disconnectedCallback();
|
|
1203
|
+
this.removeEventListener("click", __classPrivateFieldGet(this, _M3eMenuItemRadioElement_clickHandler, "f"));
|
|
1204
|
+
this.removeEventListener("keydown", __classPrivateFieldGet(this, _M3eMenuItemRadioElement_keyDownHandler, "f"));
|
|
1205
|
+
this.removeEventListener("keyup", __classPrivateFieldGet(this, _M3eMenuItemRadioElement_keyUpHandler, "f"));
|
|
1206
|
+
this.removeEventListener("mouseenter", __classPrivateFieldGet(this, _M3eMenuItemRadioElement_mouseEnterHandler, "f"));
|
|
1207
|
+
}
|
|
1208
|
+
/** @inheritdoc */
|
|
1209
|
+
update(changedProperties) {
|
|
1210
|
+
super.update(changedProperties);
|
|
1211
|
+
if (changedProperties.has("checked") && this.checked) {
|
|
1212
|
+
(this.closest("[role='group']") ?? this.closest("m3e-menu"))
|
|
1213
|
+
?.querySelectorAll("m3e-menu-item-radio")
|
|
1214
|
+
.forEach((x) => {
|
|
1215
|
+
if (x !== this && x.checked) {
|
|
1216
|
+
x.checked = false;
|
|
1217
|
+
}
|
|
1218
|
+
});
|
|
1219
|
+
}
|
|
1220
|
+
}
|
|
1221
|
+
/** @internal @inheritdoc */
|
|
1222
|
+
_renderContent() {
|
|
1223
|
+
return html ` <div class="icon">
|
|
1224
|
+
<svg class="check" viewBox="0 -960 960 960" aria-hidden="true">
|
|
1225
|
+
<path fill="currentColor" d="M382-240 154-468l57-57 171 171 367-367 57 57-424 424Z" />
|
|
1226
|
+
</svg>
|
|
1227
|
+
<slot name="icon" @slotchange="${__classPrivateFieldGet(this, _M3eMenuItemRadioElement_instances, "m", _M3eMenuItemRadioElement_handleIconSlotChange)}"></slot>
|
|
1228
|
+
</div>
|
|
1229
|
+
<slot></slot>
|
|
1230
|
+
<slot name="trailing-icon" aria-hidden="true" @slotchange="${__classPrivateFieldGet(this, _M3eMenuItemRadioElement_instances, "m", _M3eMenuItemRadioElement_handleTrailingIconSlotChange)}"></slot>`;
|
|
1231
|
+
}
|
|
1232
|
+
};
|
|
1233
|
+
_M3eMenuItemRadioElement_clickHandler = new WeakMap();
|
|
1234
|
+
_M3eMenuItemRadioElement_keyDownHandler = new WeakMap();
|
|
1235
|
+
_M3eMenuItemRadioElement_keyUpHandler = new WeakMap();
|
|
1236
|
+
_M3eMenuItemRadioElement_mouseEnterHandler = new WeakMap();
|
|
1237
|
+
_M3eMenuItemRadioElement_spacePressed = new WeakMap();
|
|
1238
|
+
_M3eMenuItemRadioElement_instances = new WeakSet();
|
|
1239
|
+
_M3eMenuItemRadioElement_handleIconSlotChange = function _M3eMenuItemRadioElement_handleIconSlotChange(e) {
|
|
1240
|
+
this.classList.toggle("-with-icon", hasAssignedNodes(e.target));
|
|
1241
|
+
};
|
|
1242
|
+
_M3eMenuItemRadioElement_handleTrailingIconSlotChange = function _M3eMenuItemRadioElement_handleTrailingIconSlotChange(e) {
|
|
1243
|
+
this.classList.toggle("-with-trailing-icon", hasAssignedNodes(e.target));
|
|
1244
|
+
};
|
|
1245
|
+
_M3eMenuItemRadioElement_handleClick = function _M3eMenuItemRadioElement_handleClick(e) {
|
|
1246
|
+
if (!e.defaultPrevented) {
|
|
1247
|
+
this.checked = true;
|
|
1248
|
+
this.performUpdate();
|
|
1249
|
+
if (!__classPrivateFieldGet(this, _M3eMenuItemRadioElement_spacePressed, "f")) {
|
|
1250
|
+
this.menu?.hideAll(true);
|
|
1251
|
+
}
|
|
1252
|
+
}
|
|
1253
|
+
};
|
|
1254
|
+
_M3eMenuItemRadioElement_handleKeyDown = function _M3eMenuItemRadioElement_handleKeyDown(e) {
|
|
1255
|
+
__classPrivateFieldSet(this, _M3eMenuItemRadioElement_spacePressed, e.key === " ", "f");
|
|
1256
|
+
};
|
|
1257
|
+
_M3eMenuItemRadioElement_handleKeyUp = function _M3eMenuItemRadioElement_handleKeyUp() {
|
|
1258
|
+
__classPrivateFieldSet(this, _M3eMenuItemRadioElement_spacePressed, false, "f");
|
|
1259
|
+
};
|
|
1260
|
+
_M3eMenuItemRadioElement_handleMouseEnter = function _M3eMenuItemRadioElement_handleMouseEnter() {
|
|
1261
|
+
this.menu?.items.forEach((item) => {
|
|
1262
|
+
if (item instanceof M3eMenuItemElement && item.submenu?.isOpen) {
|
|
1263
|
+
item.submenu.hide();
|
|
1264
|
+
}
|
|
1265
|
+
});
|
|
1266
|
+
};
|
|
1267
|
+
/** The styles of the element. */
|
|
1268
|
+
M3eMenuItemRadioElement.styles = M3eMenuItemCheckboxElement.styles;
|
|
1269
|
+
M3eMenuItemRadioElement = __decorate([
|
|
1270
|
+
t$1("m3e-menu-item-radio")
|
|
1271
|
+
], M3eMenuItemRadioElement);
|
|
1272
|
+
|
|
1273
|
+
export { M3eMenuElement, M3eMenuItemCheckboxElement, M3eMenuItemElement, M3eMenuItemGroupElement, M3eMenuItemRadioElement, M3eMenuTriggerElement };
|
|
1274
|
+
//# sourceMappingURL=index.js.map
|