wj-elements 0.1.64 → 0.1.65

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.
@@ -37,6 +37,7 @@ class Dropdown extends WJElement {
37
37
  * @param {Event} e - The event object.
38
38
  */
39
39
  __publicField(this, "toggleCallback", (e) => {
40
+ e.stopPropagation();
40
41
  if (this.classList.contains("active")) {
41
42
  this.onClose(e);
42
43
  } else {
@@ -15,6 +15,40 @@ class MenuItem extends WJElement {
15
15
  constructor() {
16
16
  super();
17
17
  __publicField(this, "className", "MenuItem");
18
+ __publicField(this, "mouseenterHandler", (e) => {
19
+ if (this.collapse || this.variant === "CONTEXT" && this.hasSubmenu) {
20
+ if (this.hasAttribute("manual") || this.variant === "NAV" && this.collapse)
21
+ return;
22
+ this.activateSubmenu(e);
23
+ e.stopPropagation();
24
+ this.showSubmenu();
25
+ }
26
+ });
27
+ __publicField(this, "clickHandler", (e) => {
28
+ switch (this.variant) {
29
+ case "NAV":
30
+ if (!this.collapse && this.hasSubmenu) {
31
+ this.submenuToggle(e);
32
+ this.hideSubmenu();
33
+ e.stopPropagation();
34
+ } else {
35
+ event.dispatchCustomEvent(this, "wje-menu-item:click");
36
+ event.dispatchCustomEvent(this, this.dialog, {
37
+ bubbles: true
38
+ });
39
+ }
40
+ break;
41
+ case "CONTEXT":
42
+ let submenuElements = this.submenu.assignedElements({ flatten: true })[0];
43
+ if (submenuElements == null ? void 0 : submenuElements.hasAttribute("active")) {
44
+ this.shouldHideSubmenu(e);
45
+ } else {
46
+ this.activateSubmenu(e);
47
+ this.showSubmenu(e);
48
+ }
49
+ break;
50
+ }
51
+ });
18
52
  /**
19
53
  * Checks if the submenu should be hidden based on the event.
20
54
  *
@@ -212,29 +246,18 @@ class MenuItem extends WJElement {
212
246
  afterDraw() {
213
247
  this.addEventListener("mousemove", this.dispatchMove);
214
248
  this.addEventListener("wje-popup:reposition", this.dispatchReposition);
215
- event.addListener(this, "mouseenter", null, (e) => {
216
- if (this.collapse || this.variant === "CONTEXT" && this.hasSubmenu) {
217
- if (this.hasAttribute("manual") || this.variant === "NAV" && this.collapse)
218
- return;
219
- this.activateSubmenu(e);
220
- e.stopPropagation();
221
- this.showSubmenu();
222
- }
223
- });
249
+ event.addListener(this, "mouseenter", null, this.mouseenterHandler);
224
250
  event.addListener(this, "mouseleave", null, this.shouldHideSubmenu);
225
251
  event.addListener(this, "focusout", null, this.shouldHideSubmenu);
226
- event.addListener(this, "click", null, (e) => {
227
- if (!this.collapse && this.variant === "NAV" && this.hasSubmenu) {
228
- this.submenuToggle(e);
229
- this.hideSubmenu();
230
- e.stopPropagation();
231
- } else {
232
- event.dispatchCustomEvent(this, "wje-menu-item:click");
233
- event.dispatchCustomEvent(this, this.dialog, {
234
- bubbles: true
235
- });
236
- }
237
- });
252
+ event.addListener(this, "click", null, this.clickHandler);
253
+ }
254
+ afterDisconnect() {
255
+ event.removeListener(this, "mousemove", null, this.dispatchMove);
256
+ event.removeListener(this, "wje-popup:reposition", null, this.dispatchReposition);
257
+ event.removeListener(this, "mouseenter", null, this.mouseenterHandler);
258
+ event.removeListener(this, "mouseleave", null, this.shouldHideSubmenu);
259
+ event.removeListener(this, "focusout", null, this.shouldHideSubmenu);
260
+ event.removeListener(this, "click", null, this.clickHandler);
238
261
  }
239
262
  /**
240
263
  * Creates a tooltip for the MenuItem when it is collapsed.
@@ -261,9 +284,10 @@ class MenuItem extends WJElement {
261
284
  * Shows the submenu of the MenuItem.
262
285
  */
263
286
  showSubmenu() {
287
+ var _a;
264
288
  this.tabIndex = -1;
265
289
  if (this.hasSubmenu) {
266
- this.popup.setAttribute("active", "");
290
+ (_a = this.popup) == null ? void 0 : _a.setAttribute("active", "");
267
291
  this.classList.add("expanded-submenu");
268
292
  this.native.classList.add("expanded-submenu");
269
293
  }
@@ -272,9 +296,10 @@ class MenuItem extends WJElement {
272
296
  * Hides the submenu of the MenuItem.
273
297
  */
274
298
  hideSubmenu() {
299
+ var _a;
275
300
  this.tabIndex = 0;
276
301
  if (this.hasSubmenu) {
277
- this.popup.removeAttribute("active");
302
+ (_a = this.popup) == null ? void 0 : _a.removeAttribute("active");
278
303
  this.classList.remove("expanded-submenu");
279
304
  this.native.classList.remove("expanded-submenu");
280
305
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "wj-elements",
3
3
  "description": "WebJET Elements is a modern set of user interface tools harnessing the power of web components designed to simplify web application development.",
4
- "version": "0.1.64",
4
+ "version": "0.1.65",
5
5
  "homepage": "https://github.com/lencys/wj-elements",
6
6
  "author": "Lukáš Ondrejček <lukas.ondrejcek@gmail.com>",
7
7
  "license": "MIT",