@zanichelli/albe-web-components 16.3.1 → 16.3.2

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.
Files changed (74) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/dist/cjs/loader.cjs.js +1 -1
  3. package/dist/cjs/web-components-library.cjs.js +1 -1
  4. package/dist/cjs/z-app-header_12.cjs.entry.js +67 -17
  5. package/dist/cjs/z-app-header_12.cjs.entry.js.map +1 -1
  6. package/dist/cjs/z-menu-section.cjs.entry.js +28 -13
  7. package/dist/cjs/z-menu-section.cjs.entry.js.map +1 -1
  8. package/dist/cjs/z-menu.cjs.entry.js +89 -43
  9. package/dist/cjs/z-menu.cjs.entry.js.map +1 -1
  10. package/dist/collection/components/z-app-header/index.js +55 -13
  11. package/dist/collection/components/z-app-header/index.js.map +1 -1
  12. package/dist/collection/components/z-app-header/index.stories.js +50 -116
  13. package/dist/collection/components/z-app-header/index.stories.js.map +1 -1
  14. package/dist/collection/components/z-app-header/styles.css +34 -25
  15. package/dist/collection/components/z-menu/index.js +93 -42
  16. package/dist/collection/components/z-menu/index.js.map +1 -1
  17. package/dist/collection/components/z-menu/styles.css +40 -52
  18. package/dist/collection/components/z-menu-section/index.js +31 -16
  19. package/dist/collection/components/z-menu-section/index.js.map +1 -1
  20. package/dist/collection/components/z-menu-section/styles.css +8 -0
  21. package/dist/collection/components/z-searchbar/index.js +14 -5
  22. package/dist/collection/components/z-searchbar/index.js.map +1 -1
  23. package/dist/components/index23.js +14 -5
  24. package/dist/components/index23.js.map +1 -1
  25. package/dist/components/z-app-header.js +56 -14
  26. package/dist/components/z-app-header.js.map +1 -1
  27. package/dist/components/z-menu-section.js +30 -15
  28. package/dist/components/z-menu-section.js.map +1 -1
  29. package/dist/components/z-menu.js +89 -44
  30. package/dist/components/z-menu.js.map +1 -1
  31. package/dist/esm/loader.js +1 -1
  32. package/dist/esm/web-components-library.js +1 -1
  33. package/dist/esm/z-app-header_12.entry.js +67 -17
  34. package/dist/esm/z-app-header_12.entry.js.map +1 -1
  35. package/dist/esm/z-menu-section.entry.js +28 -13
  36. package/dist/esm/z-menu-section.entry.js.map +1 -1
  37. package/dist/esm/z-menu.entry.js +89 -43
  38. package/dist/esm/z-menu.entry.js.map +1 -1
  39. package/dist/types/components/z-app-header/index.d.ts +4 -3
  40. package/dist/types/components/z-menu/index.d.ts +9 -1
  41. package/dist/types/components/z-menu-section/index.d.ts +4 -2
  42. package/dist/types/components/z-searchbar/index.d.ts +1 -0
  43. package/dist/web-components-library/p-8e5f1ae0.entry.js +2 -0
  44. package/dist/web-components-library/p-8e5f1ae0.entry.js.map +1 -0
  45. package/dist/web-components-library/p-b6e7866f.entry.js +2 -0
  46. package/dist/web-components-library/p-b6e7866f.entry.js.map +1 -0
  47. package/dist/web-components-library/p-fb0b11cd.entry.js +2 -0
  48. package/dist/web-components-library/p-fb0b11cd.entry.js.map +1 -0
  49. package/dist/web-components-library/web-components-library.esm.js +1 -1
  50. package/dist/web-components-library/web-components-library.esm.js.map +1 -1
  51. package/package.json +1 -1
  52. package/www/build/p-38bf2bfc.js +2 -0
  53. package/www/build/p-8e5f1ae0.entry.js +2 -0
  54. package/www/build/p-8e5f1ae0.entry.js.map +1 -0
  55. package/www/build/p-b6e7866f.entry.js +2 -0
  56. package/www/build/p-b6e7866f.entry.js.map +1 -0
  57. package/www/build/p-fb0b11cd.entry.js +2 -0
  58. package/www/build/p-fb0b11cd.entry.js.map +1 -0
  59. package/www/build/web-components-library.esm.js +1 -1
  60. package/www/build/web-components-library.esm.js.map +1 -1
  61. package/www/index.html +1 -1
  62. package/dist/web-components-library/p-04c39e8a.entry.js +0 -2
  63. package/dist/web-components-library/p-04c39e8a.entry.js.map +0 -1
  64. package/dist/web-components-library/p-0542a3c9.entry.js +0 -2
  65. package/dist/web-components-library/p-0542a3c9.entry.js.map +0 -1
  66. package/dist/web-components-library/p-16d625b3.entry.js +0 -2
  67. package/dist/web-components-library/p-16d625b3.entry.js.map +0 -1
  68. package/www/build/p-04c39e8a.entry.js +0 -2
  69. package/www/build/p-04c39e8a.entry.js.map +0 -1
  70. package/www/build/p-0542a3c9.entry.js +0 -2
  71. package/www/build/p-0542a3c9.entry.js.map +0 -1
  72. package/www/build/p-16d625b3.entry.js +0 -2
  73. package/www/build/p-16d625b3.entry.js.map +0 -1
  74. package/www/build/p-ae5cec65.js +0 -2
@@ -5,7 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  const index$1 = require('./index-96af6326.js');
6
6
  const index = require('./index-bab7a651.js');
7
7
 
8
- const stylesCss = ":host{display:flex;flex-direction:column;align-items:flex-start;justify-content:center;padding:0;font-family:var(--font-family-sans)}:host,::slotted(*),*{box-sizing:border-box}::slotted(a){text-decoration:none}::slotted(*){color:var(--color-default-text);font-family:var(--font-family-sans);font-weight:var(--font-rg)}.label{display:flex;width:100%;align-items:center;padding:var(--space-unit) 0;border:0;border-bottom:var(--border-size-small) solid var(--color-surface03);margin:0;background:transparent;border-radius:0;cursor:pointer;text-align:left}:host(:is([active],[open])) .label,.label:focus:focus-visible,.label:hover{border-color:var(--color-secondary01)}.label:focus:focus-visible{box-shadow:var(--shadow-focus-primary);outline:none}:host(:is([active],[open])) .label ::slotted(*),.label:focus:focus-visible ::slotted(*),.label:hover ::slotted(*){font-weight:var(--font-bd)}::slotted([data-text]){display:inline-flex;flex-direction:column}::slotted([data-text])::after{overflow:hidden;height:0;content:attr(data-text);content:attr(data-text) / \"\";font-weight:var(--font-bd);pointer-events:none;user-select:none;visibility:hidden}@media speech{::slotted([data-text])::after{display:none}}.label ::slotted(*){width:100%;margin:0;font-size:var(--font-size-3);line-height:1.5}.label z-icon{margin-left:calc(var(--space-unit) * 4);fill:var(--color-default-icon)}.items{display:flex;width:100%;flex-direction:column;padding:calc(var(--space-unit) / 2);padding-bottom:calc(var(--space-unit) * 1.5)}::slotted([slot=\"section\"]){display:inline-flex;padding:calc(var(--space-unit) / 2);margin:0;font-size:var(--font-size-1);line-height:1.333;outline:none}::slotted([slot=\"section\"]:last-of-type){border:none}::slotted([slot=\"section\"]:focus:focus-visible){box-shadow:var(--shadow-focus-primary);color:var(--color-secondary01)}::slotted([slot=\"section\"]:hover),::slotted([slot=\"section\"]:focus:focus-visible),::slotted([slot=\"section\"][active]){color:var(--color-secondary01);font-weight:var(--font-bd)}";
8
+ const stylesCss = ":host{display:flex;flex-direction:column;align-items:flex-start;justify-content:center;padding:0;font-family:var(--font-family-sans)}:host,::slotted(*),*{box-sizing:border-box}::slotted(a){text-decoration:none}::slotted(*){color:var(--color-default-text);font-family:var(--font-family-sans);font-weight:var(--font-rg)}.label{display:flex;width:100%;align-items:center;padding:var(--space-unit) 0;border:0;border-bottom:var(--border-size-small) solid var(--color-surface03);margin:0;background:transparent;border-radius:0;cursor:pointer;text-align:left}:host(:last-child:not([open])) .label{border-bottom:none}:host(:is([active],[open])) .label,.label:focus:focus-visible,.label:hover{border-color:var(--color-secondary01)}.label:focus:focus-visible{box-shadow:var(--shadow-focus-primary);outline:none}:host(:is([active],[open])) .label ::slotted(*),.label:focus:focus-visible ::slotted(*),.label:hover ::slotted(*){font-weight:var(--font-bd)}::slotted([data-text]){display:inline-flex;flex-direction:column}::slotted([data-text])::after{overflow:hidden;height:0;content:attr(data-text);content:attr(data-text) / \"\";font-weight:var(--font-bd);pointer-events:none;user-select:none;visibility:hidden}@media speech{::slotted([data-text])::after{display:none}}.label ::slotted(*){width:100%;margin:0;font-size:var(--font-size-3);line-height:1.5}.label z-icon{margin-left:calc(var(--space-unit) * 4);fill:var(--color-default-icon)}.items{display:flex;width:100%;flex-direction:column;padding:calc(var(--space-unit) / 2);padding-bottom:calc(var(--space-unit) * 1.5)}.items[hidden]{display:none}::slotted([slot=\"section\"]){display:inline-flex;padding:calc(var(--space-unit) / 2);margin:0;font-size:var(--font-size-1);line-height:1.333;outline:none}::slotted([slot=\"section\"]:last-of-type){border:none}::slotted([slot=\"section\"]:focus:focus-visible){box-shadow:var(--shadow-focus-primary);color:var(--color-secondary01)}::slotted([slot=\"section\"]:hover),::slotted([slot=\"section\"]:focus:focus-visible),::slotted([slot=\"section\"][active]){color:var(--color-secondary01);font-weight:var(--font-bd)}";
9
9
  const ZMenuSectionStyle0 = stylesCss;
10
10
 
11
11
  const ZMenuSection = class {
@@ -17,15 +17,14 @@ const ZMenuSection = class {
17
17
  return;
18
18
  }
19
19
  this.open = !this.open;
20
- this.setFocus();
21
20
  }
22
21
  setItemsA11yAttrs() {
23
22
  if (!this.hasItems) {
24
23
  return;
25
24
  }
26
- this.items.forEach((item, index) => {
25
+ this.items.forEach((item) => {
27
26
  item.setAttribute("role", "menuitem");
28
- item.setAttribute("tabindex", index === 0 ? "0" : "-1");
27
+ item.tabIndex = -1;
29
28
  });
30
29
  }
31
30
  onItemsChange() {
@@ -41,11 +40,18 @@ const ZMenuSection = class {
41
40
  const labelElement = ev.target.assignedElements()[0];
42
41
  labelElement.dataset.text = labelElement === null || labelElement === void 0 ? void 0 : labelElement.textContent;
43
42
  }
43
+ onLabelClick() {
44
+ this.toggle();
45
+ this.setFocus();
46
+ }
44
47
  onLabelKeydown(ev) {
45
48
  if (ev.key === index.KeyboardCode.ENTER || ev.key === index.KeyboardCode.SPACE) {
46
49
  ev.preventDefault();
47
50
  ev.stopPropagation();
48
51
  this.toggle();
52
+ if (this.open) {
53
+ this.focustFirstItem();
54
+ }
49
55
  }
50
56
  }
51
57
  /**
@@ -61,6 +67,13 @@ const ZMenuSection = class {
61
67
  current.tabIndex = -1;
62
68
  }
63
69
  }
70
+ focustFirstItem() {
71
+ this.moveFocus(this.items[0]);
72
+ }
73
+ /** Focus the last item. */
74
+ async focusLastItem() {
75
+ this.moveFocus(this.items[this.items.length - 1]);
76
+ }
64
77
  /** Set tabindex of the label to 0, then focus it. */
65
78
  async setFocus() {
66
79
  this.htmlTabindex = 0;
@@ -68,15 +81,10 @@ const ZMenuSection = class {
68
81
  this.label.focus();
69
82
  }, 100);
70
83
  }
71
- /** Focus the last item. */
72
- async focusLastItem() {
73
- this.htmlTabindex = 0;
74
- this.moveFocus(this.items[this.items.length - 1]);
75
- }
76
84
  onOpenChange() {
77
85
  if (!this.open) {
78
- this.closed.emit();
79
86
  this.setItemsA11yAttrs();
87
+ this.closed.emit();
80
88
  }
81
89
  else {
82
90
  this.opened.emit();
@@ -94,7 +102,7 @@ const ZMenuSection = class {
94
102
  }
95
103
  ev.preventDefault();
96
104
  ev.stopPropagation();
97
- this.label.focus();
105
+ this.moveFocus(this.label, this.focusableItem);
98
106
  this.open = false;
99
107
  break;
100
108
  case index.KeyboardCode.ARROW_RIGHT:
@@ -104,6 +112,7 @@ const ZMenuSection = class {
104
112
  ev.preventDefault();
105
113
  ev.stopPropagation();
106
114
  this.open = true;
115
+ this.focustFirstItem();
107
116
  break;
108
117
  case index.KeyboardCode.ARROW_DOWN: {
109
118
  if (!this.open) {
@@ -112,7 +121,7 @@ const ZMenuSection = class {
112
121
  if (document.activeElement === this.host) {
113
122
  ev.preventDefault();
114
123
  ev.stopPropagation();
115
- this.moveFocus(this.items[0]);
124
+ this.focustFirstItem();
116
125
  break;
117
126
  }
118
127
  const currentIndex = this.items.indexOf(this.focusableItem);
@@ -122,6 +131,10 @@ const ZMenuSection = class {
122
131
  ev.stopPropagation();
123
132
  this.moveFocus(receiver, this.focusableItem);
124
133
  }
134
+ else {
135
+ this.htmlTabindex = 0;
136
+ this.focusableItem.tabIndex = -1;
137
+ }
125
138
  break;
126
139
  }
127
140
  case index.KeyboardCode.ARROW_UP: {
@@ -137,6 +150,7 @@ const ZMenuSection = class {
137
150
  }
138
151
  else {
139
152
  // since there isn't a previous item to focus, give the focus to the label element
153
+ this.focusableItem.tabIndex = -1;
140
154
  this.setFocus();
141
155
  }
142
156
  break;
@@ -155,6 +169,7 @@ const ZMenuSection = class {
155
169
  this.toggle = this.toggle.bind(this);
156
170
  this.onItemsChange = this.onItemsChange.bind(this);
157
171
  this.onLabelSlotChange = this.onLabelSlotChange.bind(this);
172
+ this.onLabelClick = this.onLabelClick.bind(this);
158
173
  this.onLabelKeydown = this.onLabelKeydown.bind(this);
159
174
  this.onItemsKeydown = this.onItemsKeydown.bind(this);
160
175
  }
@@ -162,7 +177,7 @@ const ZMenuSection = class {
162
177
  this.onItemsChange();
163
178
  }
164
179
  render() {
165
- return (index$1.h(index$1.Host, { key: '387e43b42ac8233f88d329a592bef924ebcf9ee9', open: this.open }, index$1.h("button", { key: 'd6014cdeb9a6ff2b4e95c43db7d2bae2b4d1c811', ref: (el) => (this.label = el), class: "label", "aria-haspopup": `${this.hasItems}`, "aria-expanded": `${!!this.open}`, role: "menuitem", tabindex: this.htmlTabindex, onClick: this.toggle, onKeyDown: this.onLabelKeydown }, index$1.h("slot", { key: 'd0065cf62f83d83df43b5c2413d3e13b23a1bb6a', onSlotchange: this.onLabelSlotChange }), this.hasItems && index$1.h("z-icon", { key: 'e6adc51de79f1fbcb76b025cd6226388ff4d90f0', name: this.open ? "chevron-up" : "chevron-down" })), this.open && (index$1.h("div", { key: '151f31f24ec306ce4cb45b70b8ae5a6023fd063d', class: "items", role: "menu" }, index$1.h("slot", { key: 'd4d67539788121360de0e4dabf51ba22086c1345', name: "section", onSlotchange: this.onItemsChange })))));
180
+ return (index$1.h(index$1.Host, { key: '4d9223bebf25df5eb224a7674c920ebc17470826', open: this.open }, index$1.h("button", { key: '2f75c046ad4519df706283d3b37c2d9feb8734d3', ref: (el) => (this.label = el), class: "label", "aria-haspopup": `${!!this.hasItems}`, "aria-expanded": `${!!this.open}`, role: "menuitem", tabindex: this.htmlTabindex, onClick: this.onLabelClick, onKeyDown: this.onLabelKeydown }, index$1.h("slot", { key: '0a3b20723371deac12792436d977c343c237720b', onSlotchange: this.onLabelSlotChange }), this.hasItems && index$1.h("z-icon", { key: '7fe5e9dc4a9eac28f0f3a381fedbe0ec3e7ca99d', name: this.open ? "chevron-up" : "chevron-down" })), index$1.h("div", { key: '80e167ce90df12c27eddc1e28b6bf6dd3b5d0dd7', class: "items", role: "menu", hidden: !this.open }, index$1.h("slot", { key: 'a0e88a56848abf198ced22e4fc390267aea6114e', name: "section", onSlotchange: this.onItemsChange }))));
166
181
  }
167
182
  get host() { return index$1.getElement(this); }
168
183
  static get watchers() { return {
@@ -1 +1 @@
1
- {"file":"z-menu-section.entry.cjs.js","mappings":";;;;;;;AAAA,MAAM,SAAS,GAAG,k+DAAk+D,CAAC;AACr/D,2BAAe,SAAS;;MCYX,YAAY;IAkCvB,IAAY,aAAa;QACvB,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,EAAC,QAAQ,EAAC,KAAK,QAAQ,KAAK,CAAC,CAAC,CAAC;KACxD;IAEO,MAAM;QACZ,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;YAClB,OAAO;SACR;QAED,IAAI,CAAC,IAAI,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC;QACvB,IAAI,CAAC,QAAQ,EAAE,CAAC;KACjB;IAEO,iBAAiB;QACvB,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;YAClB,OAAO;SACR;QAED,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,KAAK;YAC7B,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;YACtC,IAAI,CAAC,YAAY,CAAC,UAAU,EAAE,KAAK,KAAK,CAAC,GAAG,GAAG,GAAG,IAAI,CAAC,CAAC;SACzD,CAAC,CAAC;KACJ;IAEO,aAAa;QACnB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,kBAAkB,CAAC,CAAkB,CAAC;QACzF,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;QACtC,IAAI,CAAC,iBAAiB,EAAE,CAAC;KAC1B;;;;;IAMO,iBAAiB,CAAC,EAAS;QACjC,MAAM,YAAY,GAAI,EAAE,CAAC,MAA0B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AAC;KACtB;IAED,MAAM;QACJ,QACEC,UAACC,YAAI,qDAAC,IAAI,EAAE,IAAI,CAAC,IAAI,IACnBD,uEACE,GAAG,EAAE,CAAC,EAAE,MAAM,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC,EAC9B,KAAK,EAAC,OAAO,mBACE,GAAG,IAAI,CAAC,QAAQ,EAAE,mBAClB,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,EAC/B,IAAI,EAAC,UAAU,EACf,QAAQ,EAAE,IAAI,CAAC,YAAY,EAC3B,OAAO,EAAE,IAAI,CAAC,MAAM,EACpB,SAAS,EAAE,IAAI,CAAC,cAAc,IAE9BA,qEAAM,YAAY,EAAE,IAAI,CAAC,iBAAiB,GAAI,EAC7C,IAAI,CAAC,QAAQ,IAAIA,uEAAQ,IAAI,EAAE,IAAI,CAAC,IAAI,GAAG,YAAY,GAAG,cAAc,GAAI,CACtE,EACR,IAAI,CAAC,IAAI,KACRA,oEACE,KAAK,EAAC,OAAO,EACb,IAAI,EAAC,MAAM,IAEXA,qEACE,IAAI,EAAC,SAAS,EACd,YAAY,EAAE,IAAI,CAAC,aAAa,GAChC,CACE,CACP,CACI,EACP;KACH;;;;;;;;;;;","names":["KeyboardCode","h","Host"],"sources":["src/components/z-menu-section/styles.css?tag=z-menu-section&encapsulation=shadow","src/components/z-menu-section/index.tsx"],"sourcesContent":[":host {\n display: flex;\n flex-direction: column;\n align-items: flex-start;\n justify-content: center;\n padding: 0;\n font-family: var(--font-family-sans);\n}\n\n:host,\n::slotted(*),\n* {\n box-sizing: border-box;\n}\n\n::slotted(a) {\n text-decoration: none;\n}\n\n::slotted(*) {\n color: var(--color-default-text);\n font-family: var(--font-family-sans);\n font-weight: var(--font-rg);\n}\n\n.label {\n display: flex;\n width: 100%;\n align-items: center;\n padding: var(--space-unit) 0;\n border: 0;\n border-bottom: var(--border-size-small) solid var(--color-surface03);\n margin: 0;\n background: transparent;\n border-radius: 0;\n cursor: pointer;\n text-align: left;\n}\n\n:host(:is([active], [open])) .label,\n.label:focus:focus-visible,\n.label:hover {\n border-color: var(--color-secondary01);\n}\n\n.label:focus:focus-visible {\n box-shadow: var(--shadow-focus-primary);\n outline: none;\n}\n\n:host(:is([active], [open])) .label ::slotted(*),\n.label:focus:focus-visible ::slotted(*),\n.label:hover ::slotted(*) {\n font-weight: var(--font-bd);\n}\n\n::slotted([data-text]) {\n display: inline-flex;\n flex-direction: column;\n}\n\n/* Trick to prevent layout shifts on font-weight changes.\nThe trick is to put an hidden copy of the text already set to bold,\nso the needed space is correctly calculated before any hover/active state changes the\nfont-weight of the real text.\nThe hidden text has an height of 0px so it can expand the width without changing the height\nwhen placed below the real text using `flex-direction: column`. */\n::slotted([data-text])::after {\n overflow: hidden;\n height: 0;\n content: attr(data-text);\n content: attr(data-text) / \"\";\n font-weight: var(--font-bd);\n pointer-events: none;\n user-select: none;\n visibility: hidden;\n}\n\n@media speech {\n ::slotted([data-text])::after {\n display: none;\n }\n}\n\n.label ::slotted(*) {\n width: 100%;\n margin: 0;\n font-size: var(--font-size-3);\n line-height: 1.5;\n}\n\n.label z-icon {\n margin-left: calc(var(--space-unit) * 4);\n fill: var(--color-default-icon);\n}\n\n.items {\n display: flex;\n width: 100%;\n flex-direction: column;\n padding: calc(var(--space-unit) / 2);\n padding-bottom: calc(var(--space-unit) * 1.5);\n}\n\n::slotted([slot=\"section\"]) {\n display: inline-flex;\n padding: calc(var(--space-unit) / 2);\n margin: 0;\n font-size: var(--font-size-1);\n line-height: 1.333;\n outline: none;\n}\n\n::slotted([slot=\"section\"]:last-of-type) {\n border: none;\n}\n\n::slotted([slot=\"section\"]:focus:focus-visible) {\n box-shadow: var(--shadow-focus-primary);\n color: var(--color-secondary01);\n}\n\n::slotted([slot=\"section\"]:hover),\n::slotted([slot=\"section\"]:focus:focus-visible),\n::slotted([slot=\"section\"][active]) {\n color: var(--color-secondary01);\n font-weight: var(--font-bd);\n}\n","import {Component, Element, Event, EventEmitter, Host, Listen, Method, Prop, State, Watch, h} from \"@stencil/core\";\nimport {KeyboardCode} from \"../../beans\";\n\n/**\n * A component to create submenus inside the ZMenu.\n * @slot - Label of the menu section.\n * @slot item - Single entry of the section. Set the same slot name to different items to put many of them. Add the `active` attribute to a slotted item to highlight it.\n */\n@Component({\n tag: \"z-menu-section\",\n styleUrl: \"styles.css\",\n shadow: true,\n})\nexport class ZMenuSection {\n @Element() host: HTMLZMenuSectionElement;\n\n /** Active state */\n @Prop({reflect: true})\n active?: boolean;\n\n /**\n * Tabindex value to set on the label button.\n * Useful to manage keyboard navigation focus with roving tabindex handled by this component's parent (usually ZMenu).\n */\n @Prop()\n htmlTabindex = -1;\n\n /** The opening state of the section. */\n @Prop({mutable: true})\n open: boolean;\n\n @State()\n hasItems: boolean;\n\n @State()\n items: HTMLElement[];\n\n /** The section has been opened. */\n @Event()\n opened: EventEmitter;\n\n /** The section has been closed. */\n @Event()\n closed: EventEmitter;\n\n private label: HTMLButtonElement;\n\n private get focusableItem(): HTMLElement {\n return this.items.find(({tabIndex}) => tabIndex === 0);\n }\n\n private toggle(): void {\n if (!this.hasItems) {\n return;\n }\n\n this.open = !this.open;\n this.setFocus();\n }\n\n private setItemsA11yAttrs(): void {\n if (!this.hasItems) {\n return;\n }\n\n this.items.forEach((item, index) => {\n item.setAttribute(\"role\", \"menuitem\");\n item.setAttribute(\"tabindex\", index === 0 ? \"0\" : \"-1\");\n });\n }\n\n private onItemsChange(): void {\n this.items = Array.from(this.host.querySelectorAll('[slot=\"section\"]')) as HTMLElement[];\n this.hasItems = this.items.length > 0;\n this.setItemsA11yAttrs();\n }\n\n /**\n * Sets slotted item text as `data-text` attribute value, to let CSS use it through `attr()`.\n * @param ev Slotchange event\n */\n private onLabelSlotChange(ev: Event): void {\n const labelElement = (ev.target as HTMLSlotElement).assignedElements()[0] as HTMLElement;\n labelElement.dataset.text = labelElement?.textContent;\n }\n\n private onLabelKeydown(ev: KeyboardEvent): void {\n if (ev.key === KeyboardCode.ENTER || ev.key === KeyboardCode.SPACE) {\n ev.preventDefault();\n ev.stopPropagation();\n this.toggle();\n }\n }\n\n /**\n * Move focus and adjust the tabindex value of `receiver` and `current` elements,\n * setting -1 to the `current` and 0 to the `receiver`, then focus the `receiver` element.\n */\n private moveFocus(receiver: HTMLElement, current?: HTMLElement): void {\n receiver.tabIndex = 0;\n setTimeout(() => {\n receiver.focus();\n }, 100);\n if (current) {\n current.tabIndex = -1;\n }\n }\n\n /** Set tabindex of the label to 0, then focus it. */\n @Method()\n async setFocus(): Promise<void> {\n this.htmlTabindex = 0;\n setTimeout(() => {\n this.label.focus();\n }, 100);\n }\n\n /** Focus the last item. */\n @Method()\n async focusLastItem(): Promise<void> {\n this.htmlTabindex = 0;\n this.moveFocus(this.items[this.items.length - 1]);\n }\n\n @Watch(\"open\")\n onOpenChange(): void {\n if (!this.open) {\n this.closed.emit();\n this.setItemsA11yAttrs();\n } else {\n this.opened.emit();\n }\n }\n\n @Watch(\"htmlTabindex\")\n onTabindexChange(): void {\n this.label.tabIndex = this.htmlTabindex;\n }\n\n @Listen(\"keydown\")\n private onItemsKeydown(ev: KeyboardEvent): void {\n switch (ev.key) {\n case KeyboardCode.ESC:\n case KeyboardCode.ARROW_LEFT:\n if (!this.open) {\n break;\n }\n ev.preventDefault();\n ev.stopPropagation();\n this.label.focus();\n this.open = false;\n break;\n case KeyboardCode.ARROW_RIGHT:\n if (this.open) {\n break;\n }\n ev.preventDefault();\n ev.stopPropagation();\n this.open = true;\n break;\n case KeyboardCode.ARROW_DOWN: {\n if (!this.open) {\n break;\n }\n if (document.activeElement === this.host) {\n ev.preventDefault();\n ev.stopPropagation();\n this.moveFocus(this.items[0]);\n break;\n }\n const currentIndex = this.items.indexOf(this.focusableItem);\n const receiver = this.items[currentIndex + 1];\n if (receiver) {\n ev.preventDefault();\n ev.stopPropagation();\n this.moveFocus(receiver, this.focusableItem);\n }\n break;\n }\n case KeyboardCode.ARROW_UP: {\n if (!this.open || document.activeElement === this.host) {\n break;\n }\n const currentIndex = this.items.indexOf(this.focusableItem);\n const receiver = this.items[currentIndex - 1];\n ev.preventDefault();\n ev.stopPropagation();\n if (receiver) {\n this.moveFocus(receiver, this.focusableItem);\n } else {\n // since there isn't a previous item to focus, give the focus to the label element\n this.setFocus();\n }\n break;\n }\n }\n }\n\n constructor() {\n this.toggle = this.toggle.bind(this);\n this.onItemsChange = this.onItemsChange.bind(this);\n this.onLabelSlotChange = this.onLabelSlotChange.bind(this);\n this.onLabelKeydown = this.onLabelKeydown.bind(this);\n this.onItemsKeydown = this.onItemsKeydown.bind(this);\n }\n\n connectedCallback(): void {\n this.onItemsChange();\n }\n\n render(): HTMLZMenuSectionElement {\n return (\n <Host open={this.open}>\n <button\n ref={(el) => (this.label = el)}\n class=\"label\"\n aria-haspopup={`${this.hasItems}`}\n aria-expanded={`${!!this.open}`}\n role=\"menuitem\"\n tabindex={this.htmlTabindex}\n onClick={this.toggle}\n onKeyDown={this.onLabelKeydown}\n >\n <slot onSlotchange={this.onLabelSlotChange} />\n {this.hasItems && <z-icon name={this.open ? \"chevron-up\" : \"chevron-down\"} />}\n </button>\n {this.open && (\n <div\n class=\"items\"\n role=\"menu\"\n >\n <slot\n name=\"section\"\n onSlotchange={this.onItemsChange}\n />\n </div>\n )}\n </Host>\n );\n }\n}\n"],"version":3}
1
+ {"file":"z-menu-section.entry.cjs.js","mappings":";;;;;;;AAAA,MAAM,SAAS,GAAG,ujEAAujE,CAAC;AAC1kE,2BAAe,SAAS;;MCYX,YAAY;IAkCvB,IAAY,aAAa;QACvB,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,EAAC,QAAQ,EAAC,KAAK,QAAQ,KAAK,CAAC,CAAC,CAAC;KACxD;IAEO,MAAM;QACZ,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;YAClB,OAAO;SACR;QAED,IAAI,CAAC,IAAI,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC;KACxB;IAEO,iBAAiB;QACvB,IAAI,C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EAAE,CAAC,EAC9B,KAAK,EAAC,OAAO,mBACE,GAAG,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,mBACpB,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,EAC/B,IAAI,EAAC,UAAU,EACf,QAAQ,EAAE,IAAI,CAAC,YAAY,EAC3B,OAAO,EAAE,IAAI,CAAC,YAAY,EAC1B,SAAS,EAAE,IAAI,CAAC,cAAc,IAE9BA,qEAAM,YAAY,EAAE,IAAI,CAAC,iBAAiB,GAAI,EAC7C,IAAI,CAAC,QAAQ,IAAIA,uEAAQ,IAAI,EAAE,IAAI,CAAC,IAAI,GAAG,YAAY,GAAG,cAAc,GAAI,CACtE,EACTA,oEACE,KAAK,EAAC,OAAO,EACb,IAAI,EAAC,MAAM,EACX,MAAM,EAAE,CAAC,IAAI,CAAC,IAAI,IAElBA,qEACE,IAAI,EAAC,SAAS,EACd,YAAY,EAAE,IAAI,CAAC,aAAa,GAChC,CACE,CACD,EACP;KACH;;;;;;;;;;;","names":["KeyboardCode","h","Host"],"sources":["src/components/z-menu-section/styles.css?tag=z-menu-section&encapsulation=shadow","src/components/z-menu-section/index.tsx"],"sourcesContent":[":host {\n display: flex;\n flex-direction: column;\n align-items: flex-start;\n justify-content: center;\n padding: 0;\n font-family: var(--font-family-sans);\n}\n\n:host,\n::slotted(*),\n* {\n box-sizing: border-box;\n}\n\n::slotted(a) {\n text-decoration: none;\n}\n\n::slotted(*) {\n color: var(--color-default-text);\n font-family: var(--font-family-sans);\n font-weight: var(--font-rg);\n}\n\n.label {\n display: flex;\n width: 100%;\n align-items: center;\n padding: var(--space-unit) 0;\n border: 0;\n border-bottom: var(--border-size-small) solid var(--color-surface03);\n margin: 0;\n background: transparent;\n border-radius: 0;\n cursor: pointer;\n text-align: left;\n}\n\n:host(:last-child:not([open])) .label {\n border-bottom: none;\n}\n\n:host(:is([active], [open])) .label,\n.label:focus:focus-visible,\n.label:hover {\n border-color: var(--color-secondary01);\n}\n\n.label:focus:focus-visible {\n box-shadow: var(--shadow-focus-primary);\n outline: none;\n}\n\n:host(:is([active], [open])) .label ::slotted(*),\n.label:focus:focus-visible ::slotted(*),\n.label:hover ::slotted(*) {\n font-weight: var(--font-bd);\n}\n\n::slotted([data-text]) {\n display: inline-flex;\n flex-direction: column;\n}\n\n/* Trick to prevent layout shifts on font-weight changes.\nThe trick is to put an hidden copy of the text already set to bold,\nso the needed space is correctly calculated before any hover/active state changes the\nfont-weight of the real text.\nThe hidden text has an height of 0px so it can expand the width without changing the height\nwhen placed below the real text using `flex-direction: column`. */\n::slotted([data-text])::after {\n overflow: hidden;\n height: 0;\n content: attr(data-text);\n content: attr(data-text) / \"\";\n font-weight: var(--font-bd);\n pointer-events: none;\n user-select: none;\n visibility: hidden;\n}\n\n@media speech {\n ::slotted([data-text])::after {\n display: none;\n }\n}\n\n.label ::slotted(*) {\n width: 100%;\n margin: 0;\n font-size: var(--font-size-3);\n line-height: 1.5;\n}\n\n.label z-icon {\n margin-left: calc(var(--space-unit) * 4);\n fill: var(--color-default-icon);\n}\n\n.items {\n display: flex;\n width: 100%;\n flex-direction: column;\n padding: calc(var(--space-unit) / 2);\n padding-bottom: calc(var(--space-unit) * 1.5);\n}\n\n.items[hidden] {\n display: none;\n}\n\n::slotted([slot=\"section\"]) {\n display: inline-flex;\n padding: calc(var(--space-unit) / 2);\n margin: 0;\n font-size: var(--font-size-1);\n line-height: 1.333;\n outline: none;\n}\n\n::slotted([slot=\"section\"]:last-of-type) {\n border: none;\n}\n\n::slotted([slot=\"section\"]:focus:focus-visible) {\n box-shadow: var(--shadow-focus-primary);\n color: var(--color-secondary01);\n}\n\n::slotted([slot=\"section\"]:hover),\n::slotted([slot=\"section\"]:focus:focus-visible),\n::slotted([slot=\"section\"][active]) {\n color: var(--color-secondary01);\n font-weight: var(--font-bd);\n}\n","import {Component, Element, Event, EventEmitter, Host, Listen, Method, Prop, State, Watch, h} from \"@stencil/core\";\nimport {KeyboardCode} from \"../../beans\";\n\n/**\n * A component to create submenus inside the ZMenu.\n * @slot - Label of the menu section.\n * @slot item - Single entry of the section. Set the same slot name to different items to put many of them. Add the `active` attribute to a slotted item to highlight it.\n */\n@Component({\n tag: \"z-menu-section\",\n styleUrl: \"styles.css\",\n shadow: true,\n})\nexport class ZMenuSection {\n @Element() host: HTMLZMenuSectionElement;\n\n /** Active state */\n @Prop({reflect: true})\n active?: boolean;\n\n /**\n * Tabindex value to set on the label button.\n * Useful to manage keyboard navigation focus with roving tabindex handled by this component's parent (usually ZMenu).\n */\n @Prop()\n htmlTabindex = -1;\n\n /** The opening state of the section. */\n @Prop({mutable: true})\n open: boolean;\n\n @State()\n hasItems: boolean;\n\n @State()\n items: HTMLElement[];\n\n /** The section has been opened. */\n @Event()\n opened: EventEmitter;\n\n /** The section has been closed. */\n @Event()\n closed: EventEmitter;\n\n private label: HTMLButtonElement;\n\n private get focusableItem(): HTMLElement {\n return this.items.find(({tabIndex}) => tabIndex === 0);\n }\n\n private toggle(): void {\n if (!this.hasItems) {\n return;\n }\n\n this.open = !this.open;\n }\n\n private setItemsA11yAttrs(): void {\n if (!this.hasItems) {\n return;\n }\n\n this.items.forEach((item) => {\n item.setAttribute(\"role\", \"menuitem\");\n item.tabIndex = -1;\n });\n }\n\n private onItemsChange(): void {\n this.items = Array.from(this.host.querySelectorAll('[slot=\"section\"]')) as HTMLElement[];\n this.hasItems = this.items.length > 0;\n this.setItemsA11yAttrs();\n }\n\n /**\n * Sets slotted item text as `data-text` attribute value, to let CSS use it through `attr()`.\n * @param ev Slotchange event\n */\n private onLabelSlotChange(ev: Event): void {\n const labelElement = (ev.target as HTMLSlotElement).assignedElements()[0] as HTMLElement;\n labelElement.dataset.text = labelElement?.textContent;\n }\n\n private onLabelClick(): void {\n this.toggle();\n this.setFocus();\n }\n\n private onLabelKeydown(ev: KeyboardEvent): void {\n if (ev.key === KeyboardCode.ENTER || ev.key === KeyboardCode.SPACE) {\n ev.preventDefault();\n ev.stopPropagation();\n this.toggle();\n if (this.open) {\n this.focustFirstItem();\n }\n }\n }\n\n /**\n * Move focus and adjust the tabindex value of `receiver` and `current` elements,\n * setting -1 to the `current` and 0 to the `receiver`, then focus the `receiver` element.\n */\n private moveFocus(receiver: HTMLElement, current?: HTMLElement): void {\n receiver.tabIndex = 0;\n setTimeout(() => {\n receiver.focus();\n }, 100);\n if (current) {\n current.tabIndex = -1;\n }\n }\n\n private focustFirstItem(): void {\n this.moveFocus(this.items[0]);\n }\n\n /** Focus the last item. */\n @Method()\n async focusLastItem(): Promise<void> {\n this.moveFocus(this.items[this.items.length - 1]);\n }\n\n /** Set tabindex of the label to 0, then focus it. */\n @Method()\n async setFocus(): Promise<void> {\n this.htmlTabindex = 0;\n setTimeout(() => {\n this.label.focus();\n }, 100);\n }\n\n @Watch(\"open\")\n onOpenChange(): void {\n if (!this.open) {\n this.setItemsA11yAttrs();\n this.closed.emit();\n } else {\n this.opened.emit();\n }\n }\n\n @Watch(\"htmlTabindex\")\n onTabindexChange(): void {\n this.label.tabIndex = this.htmlTabindex;\n }\n\n @Listen(\"keydown\")\n private onItemsKeydown(ev: KeyboardEvent): void {\n switch (ev.key) {\n case KeyboardCode.ESC:\n case KeyboardCode.ARROW_LEFT:\n if (!this.open) {\n break;\n }\n ev.preventDefault();\n ev.stopPropagation();\n this.moveFocus(this.label, this.focusableItem);\n this.open = false;\n break;\n case KeyboardCode.ARROW_RIGHT:\n if (this.open) {\n break;\n }\n ev.preventDefault();\n ev.stopPropagation();\n this.open = true;\n this.focustFirstItem();\n break;\n case KeyboardCode.ARROW_DOWN: {\n if (!this.open) {\n break;\n }\n if (document.activeElement === this.host) {\n ev.preventDefault();\n ev.stopPropagation();\n this.focustFirstItem();\n break;\n }\n const currentIndex = this.items.indexOf(this.focusableItem);\n const receiver = this.items[currentIndex + 1];\n if (receiver) {\n ev.preventDefault();\n ev.stopPropagation();\n this.moveFocus(receiver, this.focusableItem);\n } else {\n this.htmlTabindex = 0;\n this.focusableItem.tabIndex = -1;\n }\n break;\n }\n case KeyboardCode.ARROW_UP: {\n if (!this.open || document.activeElement === this.host) {\n break;\n }\n const currentIndex = this.items.indexOf(this.focusableItem);\n const receiver = this.items[currentIndex - 1];\n ev.preventDefault();\n ev.stopPropagation();\n if (receiver) {\n this.moveFocus(receiver, this.focusableItem);\n } else {\n // since there isn't a previous item to focus, give the focus to the label element\n this.focusableItem.tabIndex = -1;\n this.setFocus();\n }\n break;\n }\n }\n }\n\n constructor() {\n this.toggle = this.toggle.bind(this);\n this.onItemsChange = this.onItemsChange.bind(this);\n this.onLabelSlotChange = this.onLabelSlotChange.bind(this);\n this.onLabelClick = this.onLabelClick.bind(this);\n this.onLabelKeydown = this.onLabelKeydown.bind(this);\n this.onItemsKeydown = this.onItemsKeydown.bind(this);\n }\n\n connectedCallback(): void {\n this.onItemsChange();\n }\n\n render(): HTMLZMenuSectionElement {\n return (\n <Host open={this.open}>\n <button\n ref={(el) => (this.label = el)}\n class=\"label\"\n aria-haspopup={`${!!this.hasItems}`}\n aria-expanded={`${!!this.open}`}\n role=\"menuitem\"\n tabindex={this.htmlTabindex}\n onClick={this.onLabelClick}\n onKeyDown={this.onLabelKeydown}\n >\n <slot onSlotchange={this.onLabelSlotChange} />\n {this.hasItems && <z-icon name={this.open ? \"chevron-up\" : \"chevron-down\"} />}\n </button>\n <div\n class=\"items\"\n role=\"menu\"\n hidden={!this.open}\n >\n <slot\n name=\"section\"\n onSlotchange={this.onItemsChange}\n />\n </div>\n </Host>\n );\n }\n}\n"],"version":3}
@@ -4,8 +4,10 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  const index$1 = require('./index-96af6326.js');
6
6
  const index = require('./index-bab7a651.js');
7
+ const utils = require('./utils-257558ff.js');
8
+ require('./breakpoints-8a1e87e0.js');
7
9
 
8
- const stylesCss = ":host,::slotted(*),*{box-sizing:border-box;outline:none}:host{position:relative;display:inline-flex;height:fit-content;flex-direction:column}::slotted(a){text-decoration:none}::slotted(*){color:var(--color-default-text);font-family:var(--font-family-sans);font-weight:var(--font-rg)}.menu-label{position:relative;width:100%;padding:0;border:0;margin:0;background:transparent;border-radius:0;color:inherit;text-align:left}.menu-wrapper{display:flex;align-items:center}button.menu-label{cursor:pointer}.menu-label:focus-within{box-shadow:var(--shadow-focus-primary)}.menu-label .menu-label-content{position:relative;display:flex;align-items:center;border-bottom:var(--border-size-large) solid transparent}:host(:is([active],[open])) .menu-label-content,.menu-label:focus-within .menu-label-content{color:var(--color-primary01);font-weight:var(--font-bd)}:host(:is([active],[open])) .menu-label-content ::slotted(*),.menu-label:focus-within .menu-label-content ::slotted(*),.menu-label:focus-within .menu-label-content z-icon{color:var(--color-primary01);letter-spacing:normal}:host([vertical-context]) .menu-label-content{padding:var(--space-unit) 0;border-width:var(--border-size-small);border-color:var(--color-surface03)}:host([vertical-context]) .menu-label-content ::slotted(*){padding:0}:host(:is([active],[open])) .menu-label .menu-label-content,.menu-label .menu-label-content:hover,.menu-label:focus-within .menu-label-content{border-color:var(--color-secondary01)}:host([vertical-context]:is([active],[open])) .menu-label .menu-label-content::after,:host([vertical-context]) .menu-label:hover::after,:host([vertical-context]) .menu-label:focus-within .menu-label-content::after{position:absolute;bottom:0;left:0;width:100%;height:var(--border-size-large);background-color:var(--color-secondary01);content:\"\"}::slotted([data-text]:not([slot]))::after{height:0;content:attr(data-text);content:attr(data-text) / \"\";font-weight:var(--font-bd);letter-spacing:normal;pointer-events:none;user-select:none;visibility:hidden}@media speech{::slotted([data-text]:not([slot]))::after{display:none}}::slotted([data-text]:not([slot])){display:inline-flex;flex-direction:column}.menu-label .menu-label-content ::slotted(*){display:inline-flex;width:100%;min-width:fit-content;padding-bottom:2px;margin:0;appearance:none;color:var(--z-menu-label-color, var(--color-default-text));font-family:var(--font-family-sans);font-size:var(--font-size-3);font-weight:inherit;line-height:1.5}.menu-label .menu-label-content z-icon{margin-left:calc(var(--space-unit) * 1.5);fill:currentcolor}.content{background:var(--color-surface01)}:host(:not([open])) .content{display:none}:host([floating]:not([vertical-context])) .content{position:absolute;top:100%;left:0;width:375px;min-width:100%;max-width:100vw;padding:0 calc(var(--space-unit) * 2);box-shadow:var(--shadow-2)}:host(:not([floating])) .content{width:100%}.header{display:flex;align-items:center;padding:var(--space-unit) 0 calc(var(--space-unit) * 2)}.header ::slotted(img[slot=\"header\"]){width:calc(var(--space-unit) * 11.25);height:auto;object-fit:contain}.header ::slotted([slot=\"header\"]:not(:first-child)){margin:auto 0;margin-left:calc(var(--space-unit) * 2.5);font-size:var(--font-size-3);font-weight:var(--font-sb);line-height:1.5}.items{display:flex;flex-direction:column;align-items:flex-start;background:inherit}.items>::slotted([slot=\"item\"]){width:100%;margin:0;font-size:var(--font-size-3);line-height:1.5}.items>::slotted([slot=\"item\"]:focus:focus-visible){box-shadow:var(--shadow-focus-primary)}.items>::slotted([slot=\"item\"]:not(z-menu-section)){padding:var(--space-unit) 0;border-bottom:var(--border-size-small) solid var(--color-surface03)}:host(:not([vertical-context])) .items>::slotted([slot=\"item\"]:not(z-menu-section):last-of-type){border-bottom:0}.items>::slotted([slot=\"item\"]:hover),.items>::slotted([slot=\"item\"]:focus:focus-visible),.items>::slotted([slot=\"item\"]:active){border-color:var(--color-secondary01);font-weight:var(--font-bd)}";
10
+ const stylesCss = ":host,::slotted(*),*{box-sizing:border-box;outline:none}:host{position:relative;display:inline-flex;height:fit-content;flex-direction:column}::slotted(a){text-decoration:none}::slotted(*){color:var(--color-default-text);font-family:var(--font-family-sans);font-weight:var(--font-rg)}.menu-label{position:relative;display:flex;width:100%;align-items:center;padding:0;border:0;border-bottom:var(--border-size-large) solid transparent;margin:0;background:transparent;border-radius:0;color:inherit;text-align:left}button.menu-label{cursor:pointer}.menu-label:focus-visible,div.menu-label:focus-within{box-shadow:var(--shadow-focus-primary)}:host(:is([active],[open])) .menu-label ::slotted(*),.menu-label:focus-visible ::slotted(*),div.menu-label:focus-within ::slotted(*){color:var(--color-primary01);font-weight:var(--font-bd)}:host([vertical-context]) .menu-label{padding:var(--space-unit) 0;border-width:var(--border-size-small);border-color:var(--color-surface03)}:host(:is([active],[open])) .menu-label,.menu-label:hover,.menu-label:focus-visible,div.menu-label:focus-within{border-color:var(--color-secondary01)}:host([vertical-context]:is([active],[open])) .menu-label::after,:host([vertical-context]) .menu-label:hover::after,:host([vertical-context]) .menu-label:focus-visible::after,:host([vertical-context]) div.menu-label:focus-within::after{position:absolute;bottom:0;left:0;width:100%;height:var(--border-size-large);background-color:var(--color-secondary01);content:\"\"}:host([vertical-context]) .menu-label ::slotted(*){padding:0}.menu-label ::slotted(*){display:inline-flex;width:100%;min-width:fit-content;padding-bottom:2px;margin:0;appearance:none;color:var(--z-menu-label-color, var(--color-default-text));font-family:var(--font-family-sans);font-size:var(--font-size-3);font-weight:inherit;line-height:1.5}.menu-label z-icon{margin-left:calc(var(--space-unit) * 1.5);fill:var(--color-default-icon)}::slotted([data-text]:not([slot]))::after{height:0;content:attr(data-text);content:attr(data-text) / \"\";font-weight:var(--font-bd);letter-spacing:normal;pointer-events:none;user-select:none;visibility:hidden}@media speech{::slotted([data-text]:not([slot]))::after{display:none}}::slotted([data-text]:not([slot])){display:inline-flex;flex-direction:column}.content{background:var(--color-surface01)}:host(:not([open])) .content{display:none}:host([floating]:not([vertical-context])) .content{position:absolute;top:100%;left:0;width:375px;min-width:100%;max-width:100vw;padding:0 calc(var(--space-unit) * 2);box-shadow:var(--shadow-2)}:host(:not([floating])) .content{width:100%}.header{display:flex;align-items:center;padding:var(--space-unit) 0 calc(var(--space-unit) * 2)}.header ::slotted(img[slot=\"header\"]){width:calc(var(--space-unit) * 11.25);height:auto;object-fit:contain}.header ::slotted([slot=\"header\"]:not(:first-child)){margin:auto 0;margin-left:calc(var(--space-unit) * 2.5);font-size:var(--font-size-3);font-weight:var(--font-sb);line-height:1.5}.items{display:flex;flex-direction:column;align-items:flex-start;background:inherit}.items>::slotted([slot=\"item\"]){width:100%;margin:0;font-size:var(--font-size-3);line-height:1.5}.items>::slotted([slot=\"item\"]:focus:focus-visible){box-shadow:var(--shadow-focus-primary)}.items>::slotted([slot=\"item\"]:not(z-menu-section)){padding:var(--space-unit) 0;border-bottom:var(--border-size-small) solid var(--color-surface03)}:host(:not([vertical-context])) .items>::slotted([slot=\"item\"]:last-child){border-bottom:0}.items>::slotted([slot=\"item\"]:hover),.items>::slotted([slot=\"item\"]:focus:focus-visible),.items>::slotted([slot=\"item\"]:active){border-color:var(--color-secondary01);font-weight:var(--font-bd)}";
9
11
  const ZMenuStyle0 = stylesCss;
10
12
 
11
13
  const isZMenuSection = (el) => (el === null || el === void 0 ? void 0 : el.tagName) === "Z-MENU-SECTION";
@@ -59,12 +61,9 @@ const ZMenu = class {
59
61
  setItemsA11yAttrs() {
60
62
  this.items.forEach((item, index) => {
61
63
  const tabindex = index === 0 ? 0 : -1;
62
- if (isZMenuSection(item)) {
63
- item.htmlTabindex = tabindex;
64
- }
65
- else {
64
+ this.setItemTabindex(item, tabindex);
65
+ if (!isZMenuSection(item)) {
66
66
  item.setAttribute("role", "menuitem");
67
- item.tabIndex = tabindex;
68
67
  }
69
68
  });
70
69
  }
@@ -78,6 +77,14 @@ const ZMenu = class {
78
77
  }
79
78
  });
80
79
  }
80
+ setItemTabindex(item, tabIndex) {
81
+ if (isZMenuSection(item)) {
82
+ item.htmlTabindex = tabIndex;
83
+ }
84
+ else {
85
+ item.tabIndex = tabIndex;
86
+ }
87
+ }
81
88
  /**
82
89
  * Move focus and adjust the tabindex value of `receiver` and `current` elements,
83
90
  * setting -1 to the `current` and 0 to the `receiver`, then focus the `receiver` element.
@@ -96,18 +103,21 @@ const ZMenu = class {
96
103
  if (!current) {
97
104
  return;
98
105
  }
99
- if (isZMenuSection(current)) {
100
- current.htmlTabindex = -1;
101
- }
102
- else {
103
- current.tabIndex = -1;
104
- }
106
+ this.setItemTabindex(current, -1);
107
+ }
108
+ onLabelClick() {
109
+ this.toggle();
110
+ this.setFocus();
105
111
  }
106
112
  onLabelKeydown(ev) {
107
113
  if (ev.key === index.KeyboardCode.ENTER || ev.key === index.KeyboardCode.SPACE) {
108
114
  ev.preventDefault();
109
115
  ev.stopPropagation();
110
116
  this.toggle();
117
+ if (this.open) {
118
+ this.moveFocus(this.items[0]);
119
+ }
120
+ return;
111
121
  }
112
122
  if (!this.verticalContext) {
113
123
  return;
@@ -116,12 +126,7 @@ const ZMenu = class {
116
126
  ev.preventDefault();
117
127
  ev.stopPropagation();
118
128
  this.open = true;
119
- return;
120
- }
121
- if (ev.key === index.KeyboardCode.ARROW_LEFT && this.open) {
122
- ev.preventDefault();
123
- ev.stopPropagation();
124
- this.open = false;
129
+ this.moveFocus(this.items[0]);
125
130
  }
126
131
  }
127
132
  /** Set tabindex of the label to 0, then focus it. */
@@ -130,13 +135,18 @@ const ZMenu = class {
130
135
  const label = this.hasContent ? this.labelButton : this.host.firstElementChild;
131
136
  label.focus();
132
137
  }
133
- /** Focus the last item. */
138
+ /**
139
+ * Focus the last item.
140
+ */
134
141
  async focusLastItem() {
135
- this.htmlTabindex = 0;
136
- this.moveFocus(this.items[this.items.length - 1]);
142
+ const lastItem = this.items[this.items.length - 1];
143
+ if (isZMenuSection(lastItem) && lastItem.open) {
144
+ lastItem.focusLastItem();
145
+ return;
146
+ }
147
+ this.moveFocus(lastItem);
137
148
  }
138
149
  onOpenChanged() {
139
- this.setItemsA11yAttrs();
140
150
  if (!this.open) {
141
151
  cancelAnimationFrame(this.raf);
142
152
  this.closed.emit();
@@ -147,6 +157,7 @@ const ZMenu = class {
147
157
  });
148
158
  return;
149
159
  }
160
+ this.setItemsA11yAttrs();
150
161
  this.opened.emit();
151
162
  if (this.floating) {
152
163
  this.reflow(true);
@@ -164,74 +175,108 @@ const ZMenu = class {
164
175
  slottedLabel.role = "menuitem";
165
176
  slottedLabel.tabIndex = this.htmlTabindex;
166
177
  }
178
+ /**
179
+ * Set tabindex to -1 to all siblings of the clicked item.
180
+ */
181
+ onItemClick(ev) {
182
+ const clickedItem = this.items.find((item) => utils.containsElement(item, ev.target));
183
+ if (clickedItem) {
184
+ this.items.forEach((item) => {
185
+ if (item === clickedItem) {
186
+ return;
187
+ }
188
+ if (isZMenuSection(item)) {
189
+ item.htmlTabindex = -1;
190
+ }
191
+ else {
192
+ item.tabIndex = -1;
193
+ }
194
+ });
195
+ }
196
+ }
167
197
  onKeyDown(ev) {
198
+ var _a;
168
199
  if (!this.hasContent) {
169
200
  return;
170
201
  }
171
202
  switch (ev.key) {
172
203
  case index.KeyboardCode.ESC:
204
+ if (!this.open) {
205
+ break;
206
+ }
173
207
  ev.stopPropagation();
174
208
  ev.preventDefault();
175
209
  this.open = false;
176
210
  this.setFocus();
177
211
  break;
178
212
  case index.KeyboardCode.ARROW_DOWN: {
179
- if (this.verticalContext && document.activeElement === this.host && !this.open) {
180
- break;
181
- }
182
213
  if (document.activeElement === this.host) {
183
- if (!this.open) {
184
- this.open = true;
214
+ if (this.verticalContext && !this.open) {
215
+ break;
185
216
  }
186
217
  ev.stopPropagation();
187
218
  ev.preventDefault();
219
+ if (!this.open) {
220
+ this.open = true;
221
+ }
188
222
  this.moveFocus(this.items[0]);
189
223
  break;
190
224
  }
191
225
  const currentIndex = this.items.indexOf(this.focusableItem);
192
- const receiver = this.items[currentIndex + 1];
193
- if (this.verticalContext && !receiver) {
226
+ if (this.verticalContext && currentIndex === this.items.length - 1) {
227
+ // navigation is going to leave this menu. restore tabindex to the label and let the parent handle it
228
+ this.setItemTabindex(this.items[currentIndex], -1);
229
+ this.htmlTabindex = 0;
194
230
  break;
195
231
  }
196
232
  ev.stopPropagation();
197
233
  ev.preventDefault();
234
+ const receiver = this.items[currentIndex + 1];
198
235
  // if the last item is already focused, navigate to the first one
199
236
  this.moveFocus(receiver !== null && receiver !== void 0 ? receiver : this.items[0], this.focusableItem);
200
237
  break;
201
238
  }
202
239
  case index.KeyboardCode.ARROW_UP: {
203
- if (this.verticalContext && document.activeElement === this.host) {
204
- break;
205
- }
206
240
  if (document.activeElement === this.host) {
241
+ if (this.verticalContext) {
242
+ break;
243
+ }
244
+ ev.stopPropagation();
245
+ ev.preventDefault();
207
246
  // open the menu and focus the last item
208
247
  if (!this.open) {
209
248
  this.open = true;
210
249
  }
211
- ev.stopPropagation();
212
- ev.preventDefault();
213
250
  this.moveFocus(this.items[this.items.length - 1], this.focusableItem);
214
251
  break;
215
252
  }
216
253
  ev.stopPropagation();
217
254
  ev.preventDefault();
218
255
  const currentIndex = this.items.indexOf(this.focusableItem);
219
- const receiver = this.items[currentIndex - 1];
220
- if (!receiver && this.verticalContext) {
256
+ if (currentIndex === 0 && this.verticalContext) {
257
+ this.setItemTabindex(this.focusableItem, -1);
221
258
  this.setFocus();
222
259
  break;
223
260
  }
261
+ const receiver = (_a = this.items[currentIndex - 1]) !== null && _a !== void 0 ? _a : this.items[this.items.length - 1];
262
+ // if the receiver is a ZMenuSection and it's open, focus its last item
224
263
  if (isZMenuSection(receiver) && receiver.open) {
225
- isZMenuSection(this.focusableItem)
226
- ? (this.focusableItem.htmlTabindex = -1)
227
- : (this.focusableItem.tabIndex = -1);
264
+ this.setItemTabindex(this.focusableItem, -1);
228
265
  receiver.focusLastItem();
229
266
  break;
230
267
  }
231
- // if the first item is already focused, navigate to the last one
232
- this.moveFocus(receiver !== null && receiver !== void 0 ? receiver : this.items[this.items.length - 1], this.focusableItem);
268
+ this.moveFocus(receiver, this.focusableItem);
233
269
  break;
234
270
  }
271
+ case index.KeyboardCode.ARROW_LEFT:
272
+ if (!this.open || !this.verticalContext) {
273
+ break;
274
+ }
275
+ // close the menu and focus the label
276
+ ev.preventDefault();
277
+ ev.stopPropagation();
278
+ this.open = false;
279
+ this.setFocus();
235
280
  }
236
281
  }
237
282
  constructor(hostRef) {
@@ -248,6 +293,7 @@ const ZMenu = class {
248
293
  this.toggle = this.toggle.bind(this);
249
294
  this.checkContent = this.checkContent.bind(this);
250
295
  this.onLabelSlotChange = this.onLabelSlotChange.bind(this);
296
+ this.onLabelClick = this.onLabelClick.bind(this);
251
297
  this.onItemsChange = this.onItemsChange.bind(this);
252
298
  this.onLabelKeydown = this.onLabelKeydown.bind(this);
253
299
  }
@@ -257,9 +303,9 @@ const ZMenu = class {
257
303
  }
258
304
  render() {
259
305
  if (!this.hasContent) {
260
- return (index$1.h("div", { class: "menu-wrapper" }, index$1.h("div", { class: "menu-label" }, index$1.h("div", { class: "menu-label-content" }, index$1.h("slot", { onSlotchange: this.onLabelSlotChange })))));
306
+ return (index$1.h("div", { class: "menu-label" }, index$1.h("slot", { onSlotchange: this.onLabelSlotChange })));
261
307
  }
262
- return (index$1.h(index$1.Host, null, index$1.h("div", { class: "menu-wrapper" }, index$1.h("button", { ref: (el) => (this.labelButton = el), class: "menu-label", "aria-expanded": `${!!this.open}`, "aria-haspopup": `${this.hasContent}`, "aria-label": this.open ? "Chiudi menù" : "Apri menù", role: "menuitem", tabindex: this.htmlTabindex, onClick: this.toggle, onKeyDown: this.onLabelKeydown }, index$1.h("div", { class: "menu-label-content" }, index$1.h("slot", { onSlotchange: this.onLabelSlotChange }), index$1.h("z-icon", { name: this.open ? "chevron-up" : "chevron-down" })))), index$1.h("div", { class: "content", ref: (el) => (this.content = el) }, this.hasHeader && (index$1.h("header", { class: "header" }, index$1.h("slot", { name: "header", onSlotchange: this.checkContent }))), index$1.h("div", { class: "items", role: "menu" }, index$1.h("slot", { name: "item", onSlotchange: this.onItemsChange })))));
308
+ return (index$1.h(index$1.Host, null, index$1.h("button", { ref: (el) => (this.labelButton = el), class: "menu-label", "aria-expanded": `${!!this.open}`, "aria-haspopup": `${this.hasContent}`, "aria-label": this.open ? "Chiudi menù" : "Apri menù", role: "menuitem", tabIndex: this.htmlTabindex, onClick: this.onLabelClick, onKeyDown: this.onLabelKeydown }, index$1.h("slot", { onSlotchange: this.onLabelSlotChange }), index$1.h("z-icon", { name: this.open ? "chevron-up" : "chevron-down" })), index$1.h("div", { class: "content", ref: (el) => (this.content = el) }, this.hasHeader && (index$1.h("header", { class: "header" }, index$1.h("slot", { name: "header", onSlotchange: this.checkContent }))), index$1.h("div", { class: "items", role: "menu" }, index$1.h("slot", { name: "item", onSlotchange: this.onItemsChange })))));
263
309
  }
264
310
  get host() { return index$1.getElement(this); }
265
311
  static get watchers() { return {
@@ -1 +1 @@
1
- {"file":"z-menu.entry.cjs.js","mappings":";;;;;;;AAAA,MAAM,SAAS,GAAG,67HAA67H,CAAC;AACh9H,oBAAe,SAAS;;ACExB,MAAM,cAAc,GAAG,CAAC,EAAyC,KAC/D,CAAA,EAAE,aAAF,EAAE,uBAAF,EAAE,CAAE,OAAO,MAAK,gBAAgB,CAAC;MAatB,KAAK;IAwDhB,IAAY,aAAa;QACvB,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,MAAM,cAAc,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,YAAY,KAAK,CAAC,GAAG,IAAI,CAAC,QAAQ,KAAK,CAAC,CAAC,CAAC,CAAC;KAC1G;IAEO,MAAM;QACZ,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE;YACpB,OAAO;SACR;QAED,IAAI,CAAC,IAAI,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC;KACxB;;;;;IAMO,iBAAiB,CAAC,EAAS;QACjC,MAAM,YAAY,GAAI,EAAE,CAAC,MAA0B,CAAC,gBAAgB,EAAE,CAAC,CAAC,CAAgB,CAAC;QACzF,YAAY,CAAC,OAAO,CAAC,IAAI,GAAG,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,WAAW,CAAC;QACtD,IAAI,CAAC,iBAAiB,EAAE,CAAC;KAC1B;;;;;IAMO,MAAM,CAAC,IAAI,GAAG,KAAK;QACzB,IAAI,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,UAAU,EAAE;YACnC,MAAM,EAAC,KAAK,EAAC,GAAG,IAAI,CAAC,OAAO,CAAC;YAC7B,MAAM,EAAC,IAAI,EAAC,GAAG,IAAI,CAAC,IAAI,CAAC,qBAAqB,EAAE,CAAC;YACjD,MAAM,OAAO,GAAG,gBAAgB,CAAC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,IAEXA,oBACE,IAAI,EAAC,MAAM,EACX,YAAY,EAAE,IAAI,CAAC,aAAa,GAChC,CACE,CACF,CACD,EACP;KACH;;;;;;;;;;;","names":["KeyboardCode","h","Host"],"sources":["src/components/z-menu/styles.css?tag=z-menu&encapsulation=shadow","src/components/z-menu/index.tsx"],"sourcesContent":[":host,\n::slotted(*),\n* {\n box-sizing: border-box;\n outline: none;\n}\n\n:host {\n --z-menu-label-color: ;\n\n position: relative;\n display: inline-flex;\n height: fit-content;\n flex-direction: column;\n}\n\n::slotted(a) {\n text-decoration: none;\n}\n\n::slotted(*) {\n color: var(--color-default-text);\n font-family: var(--font-family-sans);\n font-weight: var(--font-rg);\n}\n\n.menu-label {\n position: relative;\n width: 100%;\n padding: 0;\n border: 0;\n margin: 0;\n background: transparent;\n border-radius: 0;\n color: inherit;\n text-align: left;\n}\n\n.menu-wrapper {\n display: flex;\n align-items: center;\n}\n\nbutton.menu-label {\n cursor: pointer;\n}\n\n.menu-label:focus-within {\n box-shadow: var(--shadow-focus-primary);\n}\n\n.menu-label .menu-label-content {\n position: relative;\n display: flex;\n align-items: center;\n border-bottom: var(--border-size-large) solid transparent;\n}\n\n:host(:is([active], [open])) .menu-label-content,\n.menu-label:focus-within .menu-label-content {\n color: var(--color-primary01);\n font-weight: var(--font-bd);\n}\n\n:host(:is([active], [open])) .menu-label-content ::slotted(*),\n.menu-label:focus-within .menu-label-content ::slotted(*),\n.menu-label:focus-within .menu-label-content z-icon {\n color: var(--color-primary01);\n letter-spacing: normal;\n}\n\n:host([vertical-context]) .menu-label-content {\n padding: var(--space-unit) 0;\n border-width: var(--border-size-small);\n border-color: var(--color-surface03);\n}\n\n:host([vertical-context]) .menu-label-content ::slotted(*) {\n padding: 0;\n}\n\n:host(:is([active], [open])) .menu-label .menu-label-content,\n.menu-label .menu-label-content:hover,\n.menu-label:focus-within .menu-label-content {\n border-color: var(--color-secondary01);\n}\n\n:host([vertical-context]:is([active], [open])) .menu-label .menu-label-content::after,\n:host([vertical-context]) .menu-label:hover::after,\n:host([vertical-context]) .menu-label:focus-within .menu-label-content::after {\n position: absolute;\n bottom: 0;\n left: 0;\n width: 100%;\n height: var(--border-size-large);\n background-color: var(--color-secondary01);\n content: \"\";\n}\n\n/* Prevents layout shifts on font-weight changes.\nThe trick is to put an hidden copy of the text already set to bold,\nso the needed space is correctly calculated before any hover/active state changes the\nfont-weight of the real text.\nThe hidden text has an height of 0px so it can expand the width without changing the height\nwhen placed below the real text using `flex-direction: column`. */\n::slotted([data-text]:not([slot]))::after {\n height: 0;\n content: attr(data-text);\n content: attr(data-text) / \"\";\n font-weight: var(--font-bd);\n letter-spacing: normal;\n pointer-events: none;\n user-select: none;\n visibility: hidden;\n}\n\n@media speech {\n ::slotted([data-text]:not([slot]))::after {\n display: none;\n }\n}\n\n::slotted([data-text]:not([slot])) {\n display: inline-flex;\n flex-direction: column;\n}\n\n.menu-label .menu-label-content ::slotted(*) {\n display: inline-flex;\n width: 100%;\n min-width: fit-content;\n padding-bottom: 2px;\n margin: 0;\n appearance: none;\n color: var(--z-menu-label-color, var(--color-default-text));\n font-family: var(--font-family-sans);\n font-size: var(--font-size-3);\n font-weight: inherit;\n line-height: 1.5;\n}\n\n.menu-label .menu-label-content z-icon {\n margin-left: calc(var(--space-unit) * 1.5);\n fill: currentcolor;\n}\n\n.content {\n background: var(--color-surface01);\n}\n\n:host(:not([open])) .content {\n display: none;\n}\n\n:host([floating]:not([vertical-context])) .content {\n position: absolute;\n top: 100%;\n left: 0;\n width: 375px;\n min-width: 100%;\n max-width: 100vw;\n padding: 0 calc(var(--space-unit) * 2);\n box-shadow: var(--shadow-2);\n}\n\n:host(:not([floating])) .content {\n width: 100%;\n}\n\n.header {\n display: flex;\n align-items: center;\n padding: var(--space-unit) 0 calc(var(--space-unit) * 2);\n}\n\n.header ::slotted(img[slot=\"header\"]) {\n width: calc(var(--space-unit) * 11.25);\n height: auto;\n object-fit: contain;\n}\n\n.header ::slotted([slot=\"header\"]:not(:first-child)) {\n margin: auto 0;\n margin-left: calc(var(--space-unit) * 2.5);\n font-size: var(--font-size-3);\n font-weight: var(--font-sb);\n line-height: 1.5;\n}\n\n.items {\n display: flex;\n flex-direction: column;\n align-items: flex-start;\n background: inherit;\n}\n\n.items > ::slotted([slot=\"item\"]) {\n width: 100%;\n margin: 0;\n font-size: var(--font-size-3);\n line-height: 1.5;\n}\n\n.items > ::slotted([slot=\"item\"]:focus:focus-visible) {\n box-shadow: var(--shadow-focus-primary);\n}\n\n.items > ::slotted([slot=\"item\"]:not(z-menu-section)) {\n padding: var(--space-unit) 0;\n border-bottom: var(--border-size-small) solid var(--color-surface03);\n}\n\n:host(:not([vertical-context])) .items > ::slotted([slot=\"item\"]:not(z-menu-section):last-of-type) {\n border-bottom: 0;\n}\n\n.items > ::slotted([slot=\"item\"]:hover),\n.items > ::slotted([slot=\"item\"]:focus:focus-visible),\n.items > ::slotted([slot=\"item\"]:active) {\n border-color: var(--color-secondary01);\n font-weight: var(--font-bd);\n}\n","import {Component, Element, Event, EventEmitter, Host, Listen, Method, Prop, State, Watch, h} from \"@stencil/core\";\nimport {KeyboardCode} from \"../../beans\";\n\nconst isZMenuSection = (el: HTMLElement | HTMLZMenuSectionElement): el is HTMLZMenuSectionElement =>\n el?.tagName === \"Z-MENU-SECTION\";\n\n/**\n * @slot - Menu label\n * @slot header - Header to display as the first entry of the open menu.\n * @slot item - Single entry of the section. Can be slotted multiple times to insert items onto the menu. Set the `active` HTML attribute on the element to highlight it. Use `z-menu-section` for submenus.\n * @cssprop --z-menu-label-color - Color of the label's text.\n */\n@Component({\n tag: \"z-menu\",\n styleUrl: \"styles.css\",\n shadow: true,\n})\nexport class ZMenu {\n @Element() host: HTMLZMenuElement;\n\n /** Flag to set the active status of the menu. */\n @Prop({reflect: true})\n active?: boolean;\n\n /**\n * Flag to set the display mode of the list.\n * If true, the list will be absolutely positioned under the menu label,\n * stacked beneath it otherwise.\n */\n @Prop({reflect: true})\n floating? = true;\n\n /** The opening state of the menu. */\n @Prop({mutable: true, reflect: true})\n open = false;\n\n /**\n * Tells the component that it's placed in a vertical context with other `ZMenu`s (usually in the ZAppHeader's offcanvas).\n * A small border is placed under it as a separator from other elements.\n */\n @Prop({reflect: true})\n verticalContext = false;\n\n /**\n * Tabindex value to set on the menu label.\n * Useful to manage keyboard navigation focus with roving tabindex handled by this component's parent (usually ZAppHeader).\n */\n @Prop()\n htmlTabindex = -1;\n\n @State()\n hasHeader: boolean;\n\n @State()\n hasContent: boolean;\n\n /** The menu has been opened. */\n @Event()\n opened: EventEmitter;\n\n /** The menu has been closed. */\n @Event()\n closed: EventEmitter;\n\n private labelButton: HTMLButtonElement;\n\n private content: HTMLElement;\n\n private items: (HTMLElement | HTMLZMenuSectionElement)[];\n\n /** Animation frame request id. */\n private raf: number;\n\n private get focusableItem(): HTMLZMenuSectionElement | HTMLElement | null {\n return this.items.find((item) => (isZMenuSection(item) ? item.htmlTabindex === 0 : item.tabIndex === 0));\n }\n\n private toggle(): void {\n if (!this.hasContent) {\n return;\n }\n\n this.open = !this.open;\n }\n\n /**\n * Sets slotted item text as `data-text` attribute value, to let CSS use it through `attr()`.\n * @param ev Slotchange event\n */\n private onLabelSlotChange(ev: Event): void {\n const labelElement = (ev.target as HTMLSlotElement).assignedElements()[0] as HTMLElement;\n labelElement.dataset.text = labelElement?.textContent;\n this.setLabelA11yAttrs();\n }\n\n /**\n * Correctly set position of the floating menu in order to prevent overflow.\n * @param live Should run the method on every refresh frame.\n */\n private reflow(live = false): void {\n if (this.content && this.hasContent) {\n const {style} = this.content;\n const {left} = this.host.getBoundingClientRect();\n const widthPx = getComputedStyle(this.content).width;\n const width = widthPx ? parseFloat(widthPx.replace(\"px\", \"\")) : 375;\n const safeScrollbarSpace = 30;\n style.left = `${Math.min(window.innerWidth - left - width - safeScrollbarSpace, 0)}px`;\n }\n if (live) {\n this.raf = requestAnimationFrame(this.reflow.bind(this, live));\n }\n }\n\n /**\n * Check if some content slot is set.\n */\n private checkContent(): void {\n this.hasHeader = !!this.host.querySelectorAll(\"[slot=header]\").length;\n this.hasContent = !!this.host.querySelectorAll(\"[slot=item]\").length || this.hasHeader;\n }\n\n /**\n * Set `menuitem` role to all menu items (ZMenuSection items already have it).\n * Set -1 to the tabindex of the items and 0 to the first one.\n */\n private setItemsA11yAttrs(): void {\n this.items.forEach((item, index) => {\n const tabindex = index === 0 ? 0 : -1;\n if (isZMenuSection(item)) {\n item.htmlTabindex = tabindex;\n } else {\n item.setAttribute(\"role\", \"menuitem\");\n item.tabIndex = tabindex;\n }\n });\n }\n\n private onItemsChange(): void {\n this.checkContent();\n this.items = Array.from(this.host.children).filter(({slot}) => slot === \"item\") as HTMLElement[];\n this.setItemsA11yAttrs();\n this.items.forEach((item) => {\n if (!isZMenuSection(item)) {\n item.dataset.text = item.textContent;\n }\n });\n }\n\n /**\n * Move focus and adjust the tabindex value of `receiver` and `current` elements,\n * setting -1 to the `current` and 0 to the `receiver`, then focus the `receiver` element.\n * If the receiver is a ZMenuSection and it's open, focus its first focusable item.\n */\n private moveFocus(\n receiver: HTMLElement | HTMLZMenuSectionElement,\n current?: HTMLElement | HTMLZMenuSectionElement\n ): void {\n if (isZMenuSection(receiver)) {\n receiver.setFocus();\n } else {\n receiver.tabIndex = 0;\n setTimeout(() => {\n receiver.focus();\n }, 100);\n }\n if (!current) {\n return;\n }\n\n if (isZMenuSection(current)) {\n current.htmlTabindex = -1;\n } else {\n current.tabIndex = -1;\n }\n }\n\n private onLabelKeydown(ev: KeyboardEvent): void {\n if (ev.key === KeyboardCode.ENTER || ev.key === KeyboardCode.SPACE) {\n ev.preventDefault();\n ev.stopPropagation();\n this.toggle();\n }\n\n if (!this.verticalContext) {\n return;\n }\n\n if (ev.key === KeyboardCode.ARROW_RIGHT && !this.open) {\n ev.preventDefault();\n ev.stopPropagation();\n this.open = true;\n\n return;\n }\n\n if (ev.key === KeyboardCode.ARROW_LEFT && this.open) {\n ev.preventDefault();\n ev.stopPropagation();\n this.open = false;\n }\n }\n\n /** Set tabindex of the label to 0, then focus it. */\n @Method()\n async setFocus(): Promise<void> {\n this.htmlTabindex = 0;\n const label = this.hasContent ? this.labelButton : (this.host.firstElementChild as HTMLElement);\n label.focus();\n }\n\n /** Focus the last item. */\n @Method()\n async focusLastItem(): Promise<void> {\n this.htmlTabindex = 0;\n this.moveFocus(this.items[this.items.length - 1]);\n }\n\n @Watch(\"open\")\n onOpenChanged(): void {\n this.setItemsA11yAttrs();\n if (!this.open) {\n cancelAnimationFrame(this.raf);\n this.closed.emit();\n this.items.forEach((item) => {\n if (isZMenuSection(item) && item.open) {\n item.open = false;\n }\n });\n\n return;\n }\n\n this.opened.emit();\n if (this.floating) {\n this.reflow(true);\n }\n }\n\n @Watch(\"htmlTabindex\")\n setLabelA11yAttrs(): void {\n if (this.hasContent && !this.labelButton) {\n return;\n }\n\n if (this.hasContent) {\n this.labelButton.tabIndex = this.htmlTabindex;\n\n return;\n }\n\n const slottedLabel = this.host.firstElementChild as HTMLElement;\n slottedLabel.role = \"menuitem\";\n slottedLabel.tabIndex = this.htmlTabindex;\n }\n\n @Listen(\"keydown\")\n onKeyDown(ev: KeyboardEvent): void {\n if (!this.hasContent) {\n return;\n }\n\n switch (ev.key) {\n case KeyboardCode.ESC:\n ev.stopPropagation();\n ev.preventDefault();\n this.open = false;\n this.setFocus();\n break;\n case KeyboardCode.ARROW_DOWN: {\n if (this.verticalContext && document.activeElement === this.host && !this.open) {\n break;\n }\n\n if (document.activeElement === this.host) {\n if (!this.open) {\n this.open = true;\n }\n ev.stopPropagation();\n ev.preventDefault();\n this.moveFocus(this.items[0]);\n break;\n }\n\n const currentIndex = this.items.indexOf(this.focusableItem);\n const receiver = this.items[currentIndex + 1];\n if (this.verticalContext && !receiver) {\n break;\n }\n\n ev.stopPropagation();\n ev.preventDefault();\n // if the last item is already focused, navigate to the first one\n this.moveFocus(receiver ?? this.items[0], this.focusableItem);\n break;\n }\n case KeyboardCode.ARROW_UP: {\n if (this.verticalContext && document.activeElement === this.host) {\n break;\n }\n\n if (document.activeElement === this.host) {\n // open the menu and focus the last item\n if (!this.open) {\n this.open = true;\n }\n ev.stopPropagation();\n ev.preventDefault();\n this.moveFocus(this.items[this.items.length - 1], this.focusableItem);\n break;\n }\n\n ev.stopPropagation();\n ev.preventDefault();\n const currentIndex = this.items.indexOf(this.focusableItem);\n const receiver = this.items[currentIndex - 1];\n if (!receiver && this.verticalContext) {\n this.setFocus();\n break;\n }\n\n if (isZMenuSection(receiver) && receiver.open) {\n isZMenuSection(this.focusableItem)\n ? (this.focusableItem.htmlTabindex = -1)\n : (this.focusableItem.tabIndex = -1);\n receiver.focusLastItem();\n break;\n }\n\n // if the first item is already focused, navigate to the last one\n this.moveFocus(receiver ?? this.items[this.items.length - 1], this.focusableItem);\n break;\n }\n }\n }\n\n constructor() {\n this.toggle = this.toggle.bind(this);\n this.checkContent = this.checkContent.bind(this);\n this.onLabelSlotChange = this.onLabelSlotChange.bind(this);\n this.onItemsChange = this.onItemsChange.bind(this);\n this.onLabelKeydown = this.onLabelKeydown.bind(this);\n }\n\n connectedCallback(): void {\n this.onItemsChange();\n this.setLabelA11yAttrs();\n }\n\n render(): HTMLDivElement | HTMLZMenuElement {\n if (!this.hasContent) {\n return (\n <div class=\"menu-wrapper\">\n <div class=\"menu-label\">\n <div class=\"menu-label-content\">\n <slot onSlotchange={this.onLabelSlotChange} />\n </div>\n </div>\n </div>\n );\n }\n\n return (\n <Host>\n <div class=\"menu-wrapper\">\n <button\n ref={(el) => (this.labelButton = el)}\n class=\"menu-label\"\n aria-expanded={`${!!this.open}`}\n aria-haspopup={`${this.hasContent}`}\n aria-label={this.open ? \"Chiudi menù\" : \"Apri menù\"}\n role=\"menuitem\"\n tabindex={this.htmlTabindex}\n onClick={this.toggle}\n onKeyDown={this.onLabelKeydown}\n >\n <div class=\"menu-label-content\">\n <slot onSlotchange={this.onLabelSlotChange} />\n <z-icon name={this.open ? \"chevron-up\" : \"chevron-down\"} />\n </div>\n </button>\n </div>\n\n <div\n class=\"content\"\n ref={(el) => (this.content = el)}\n >\n {this.hasHeader && (\n <header class=\"header\">\n <slot\n name=\"header\"\n onSlotchange={this.checkContent}\n />\n </header>\n )}\n\n <div\n class=\"items\"\n role=\"menu\"\n >\n <slot\n name=\"item\"\n onSlotchange={this.onItemsChange}\n />\n </div>\n </div>\n </Host>\n );\n }\n}\n"],"version":3}
1
+ {"file":"z-menu.entry.cjs.js","mappings":";;;;;;;;;AAAA,MAAM,SAAS,GAAG,0nHAA0nH,CAAC;AAC7oH,oBAAe,SAAS;;ACGxB,MAAM,cAAc,GAAG,CAAC,EAAyC,KAC/D,CAAA,EAAE,aAAF,EAAE,uBAAF,EAAE,CAAE,OAAO,MAAK,gBAAgB,CAAC;MAatB,KAAK;IAwDhB,IAAY,aAAa;QACvB,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,MAAM,cAAc,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,YAAY,KAAK,CAAC,GAAG,IAAI,CAAC,QAAQ,KAAK,CAAC,CAAC,CAAC,CAAC;KAC1G;IAEO,MAAM;QACZ,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE;YACpB,OAAO;SACR;QAED,IAAI,CAAC,IAAI,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC;KACxB;;;;;IAMO,iBAAiB,CAAC,EAAS;QACjC,MAAM,YAAY,GAAI,EAAE,CAAC,MAA0B,CAAC,gBAAgB,EAAE,CAAC,CAAC,CAAgB,CAAC;QACzF,YAAY,CAAC,OAAO,CAAC,IAAI,GAAG,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,WAAW,CAAC;QACtD,IAAI,CAAC,iBAAiB,EAAE,CAAC;KAC1B;;;;;IAMO,MAAM,CAAC,IAAI,GAAG,KAAK;QACzB,IAAI,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,UAAU,EAAE;YACnC,MAAM,EAAC,KAAK,EAAC,GAAG,IAAI,CAAC,OAAO,CA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A,oBACE,IAAI,EAAC,MAAM,EACX,YAAY,EAAE,IAAI,CAAC,aAAa,GAChC,CACE,CACF,CACD,EACP;KACH;;;;;;;;;;;","names":["KeyboardCode","containsElement","h","Host"],"sources":["src/components/z-menu/styles.css?tag=z-menu&encapsulation=shadow","src/components/z-menu/index.tsx"],"sourcesContent":[":host,\n::slotted(*),\n* {\n box-sizing: border-box;\n outline: none;\n}\n\n:host {\n --z-menu-label-color: ;\n\n position: relative;\n display: inline-flex;\n height: fit-content;\n flex-direction: column;\n}\n\n::slotted(a) {\n text-decoration: none;\n}\n\n::slotted(*) {\n color: var(--color-default-text);\n font-family: var(--font-family-sans);\n font-weight: var(--font-rg);\n}\n\n.menu-label {\n position: relative;\n display: flex;\n width: 100%;\n align-items: center;\n padding: 0;\n border: 0;\n border-bottom: var(--border-size-large) solid transparent;\n margin: 0;\n background: transparent;\n border-radius: 0;\n color: inherit;\n text-align: left;\n}\n\nbutton.menu-label {\n cursor: pointer;\n}\n\n.menu-label:focus-visible,\ndiv.menu-label:focus-within {\n box-shadow: var(--shadow-focus-primary);\n}\n\n:host(:is([active], [open])) .menu-label ::slotted(*),\n.menu-label:focus-visible ::slotted(*),\ndiv.menu-label:focus-within ::slotted(*) {\n color: var(--color-primary01);\n font-weight: var(--font-bd);\n}\n\n:host([vertical-context]) .menu-label {\n padding: var(--space-unit) 0;\n border-width: var(--border-size-small);\n border-color: var(--color-surface03);\n}\n\n:host(:is([active], [open])) .menu-label,\n.menu-label:hover,\n.menu-label:focus-visible,\ndiv.menu-label:focus-within {\n border-color: var(--color-secondary01);\n}\n\n:host([vertical-context]:is([active], [open])) .menu-label::after,\n:host([vertical-context]) .menu-label:hover::after,\n:host([vertical-context]) .menu-label:focus-visible::after,\n:host([vertical-context]) div.menu-label:focus-within::after {\n position: absolute;\n bottom: 0;\n left: 0;\n width: 100%;\n height: var(--border-size-large);\n background-color: var(--color-secondary01);\n content: \"\";\n}\n\n:host([vertical-context]) .menu-label ::slotted(*) {\n padding: 0;\n}\n\n.menu-label ::slotted(*) {\n display: inline-flex;\n width: 100%;\n min-width: fit-content;\n padding-bottom: 2px;\n margin: 0;\n appearance: none;\n color: var(--z-menu-label-color, var(--color-default-text));\n font-family: var(--font-family-sans);\n font-size: var(--font-size-3);\n font-weight: inherit;\n line-height: 1.5;\n}\n\n.menu-label z-icon {\n margin-left: calc(var(--space-unit) * 1.5);\n fill: var(--color-default-icon);\n}\n\n/* Prevents layout shifts on font-weight changes.\nThe trick is to put an hidden copy of the text already set to bold,\nso the needed space is correctly calculated before any hover/active state changes the\nfont-weight of the real text.\nThe hidden text has an height of 0px so it can expand the width without changing the height\nwhen placed below the real text using `flex-direction: column`. */\n::slotted([data-text]:not([slot]))::after {\n height: 0;\n content: attr(data-text);\n content: attr(data-text) / \"\";\n font-weight: var(--font-bd);\n letter-spacing: normal;\n pointer-events: none;\n user-select: none;\n visibility: hidden;\n}\n\n@media speech {\n ::slotted([data-text]:not([slot]))::after {\n display: none;\n }\n}\n\n::slotted([data-text]:not([slot])) {\n display: inline-flex;\n flex-direction: column;\n}\n\n.content {\n background: var(--color-surface01);\n}\n\n:host(:not([open])) .content {\n display: none;\n}\n\n:host([floating]:not([vertical-context])) .content {\n position: absolute;\n top: 100%;\n left: 0;\n width: 375px;\n min-width: 100%;\n max-width: 100vw;\n padding: 0 calc(var(--space-unit) * 2);\n box-shadow: var(--shadow-2);\n}\n\n:host(:not([floating])) .content {\n width: 100%;\n}\n\n.header {\n display: flex;\n align-items: center;\n padding: var(--space-unit) 0 calc(var(--space-unit) * 2);\n}\n\n.header ::slotted(img[slot=\"header\"]) {\n width: calc(var(--space-unit) * 11.25);\n height: auto;\n object-fit: contain;\n}\n\n.header ::slotted([slot=\"header\"]:not(:first-child)) {\n margin: auto 0;\n margin-left: calc(var(--space-unit) * 2.5);\n font-size: var(--font-size-3);\n font-weight: var(--font-sb);\n line-height: 1.5;\n}\n\n.items {\n display: flex;\n flex-direction: column;\n align-items: flex-start;\n background: inherit;\n}\n\n.items > ::slotted([slot=\"item\"]) {\n width: 100%;\n margin: 0;\n font-size: var(--font-size-3);\n line-height: 1.5;\n}\n\n.items > ::slotted([slot=\"item\"]:focus:focus-visible) {\n box-shadow: var(--shadow-focus-primary);\n}\n\n.items > ::slotted([slot=\"item\"]:not(z-menu-section)) {\n padding: var(--space-unit) 0;\n border-bottom: var(--border-size-small) solid var(--color-surface03);\n}\n\n:host(:not([vertical-context])) .items > ::slotted([slot=\"item\"]:last-child) {\n border-bottom: 0;\n}\n\n.items > ::slotted([slot=\"item\"]:hover),\n.items > ::slotted([slot=\"item\"]:focus:focus-visible),\n.items > ::slotted([slot=\"item\"]:active) {\n border-color: var(--color-secondary01);\n font-weight: var(--font-bd);\n}\n","import {Component, Element, Event, EventEmitter, Host, Listen, Method, Prop, State, Watch, h} from \"@stencil/core\";\nimport {KeyboardCode} from \"../../beans\";\nimport {containsElement} from \"../../utils/utils\";\n\nconst isZMenuSection = (el: HTMLElement | HTMLZMenuSectionElement): el is HTMLZMenuSectionElement =>\n el?.tagName === \"Z-MENU-SECTION\";\n\n/**\n * @slot - Menu label\n * @slot header - Header to display as the first entry of the open menu.\n * @slot item - Single entry of the section. Can be slotted multiple times to insert items onto the menu. Set the `active` HTML attribute on the element to highlight it. Use `z-menu-section` for submenus.\n * @cssprop --z-menu-label-color - Color of the label's text.\n */\n@Component({\n tag: \"z-menu\",\n styleUrl: \"styles.css\",\n shadow: true,\n})\nexport class ZMenu {\n @Element() host: HTMLZMenuElement;\n\n /** Flag to set the active status of the menu. */\n @Prop({reflect: true})\n active?: boolean;\n\n /**\n * Flag to set the display mode of the list.\n * If true, the list will be absolutely positioned under the menu label,\n * stacked beneath it otherwise.\n */\n @Prop({reflect: true})\n floating? = true;\n\n /** The opening state of the menu. */\n @Prop({mutable: true, reflect: true})\n open = false;\n\n /**\n * Tells the component that it's placed in a vertical context with other `ZMenu`s (usually in the ZAppHeader's offcanvas).\n * A small border is placed under it as a separator from other elements.\n */\n @Prop({reflect: true})\n verticalContext = false;\n\n /**\n * Tabindex value to set on the menu label.\n * Useful to manage keyboard navigation focus with roving tabindex handled by this component's parent (usually ZAppHeader).\n */\n @Prop()\n htmlTabindex = -1;\n\n @State()\n hasHeader: boolean;\n\n @State()\n hasContent: boolean;\n\n /** The menu has been opened. */\n @Event()\n opened: EventEmitter;\n\n /** The menu has been closed. */\n @Event()\n closed: EventEmitter;\n\n private labelButton: HTMLButtonElement;\n\n private content: HTMLElement;\n\n private items: (HTMLElement | HTMLZMenuSectionElement)[];\n\n /** Animation frame request id. */\n private raf: number;\n\n private get focusableItem(): HTMLZMenuSectionElement | HTMLElement | null {\n return this.items.find((item) => (isZMenuSection(item) ? item.htmlTabindex === 0 : item.tabIndex === 0));\n }\n\n private toggle(): void {\n if (!this.hasContent) {\n return;\n }\n\n this.open = !this.open;\n }\n\n /**\n * Sets slotted item text as `data-text` attribute value, to let CSS use it through `attr()`.\n * @param ev Slotchange event\n */\n private onLabelSlotChange(ev: Event): void {\n const labelElement = (ev.target as HTMLSlotElement).assignedElements()[0] as HTMLElement;\n labelElement.dataset.text = labelElement?.textContent;\n this.setLabelA11yAttrs();\n }\n\n /**\n * Correctly set position of the floating menu in order to prevent overflow.\n * @param live Should run the method on every refresh frame.\n */\n private reflow(live = false): void {\n if (this.content && this.hasContent) {\n const {style} = this.content;\n const {left} = this.host.getBoundingClientRect();\n const widthPx = getComputedStyle(this.content).width;\n const width = widthPx ? parseFloat(widthPx.replace(\"px\", \"\")) : 375;\n const safeScrollbarSpace = 30;\n style.left = `${Math.min(window.innerWidth - left - width - safeScrollbarSpace, 0)}px`;\n }\n if (live) {\n this.raf = requestAnimationFrame(this.reflow.bind(this, live));\n }\n }\n\n /**\n * Check if some content slot is set.\n */\n private checkContent(): void {\n this.hasHeader = !!this.host.querySelectorAll(\"[slot=header]\").length;\n this.hasContent = !!this.host.querySelectorAll(\"[slot=item]\").length || this.hasHeader;\n }\n\n /**\n * Set `menuitem` role to all menu items (ZMenuSection items already have it).\n * Set -1 to the tabindex of the items and 0 to the first one.\n */\n private setItemsA11yAttrs(): void {\n this.items.forEach((item, index) => {\n const tabindex = index === 0 ? 0 : -1;\n this.setItemTabindex(item, tabindex);\n if (!isZMenuSection(item)) {\n item.setAttribute(\"role\", \"menuitem\");\n }\n });\n }\n\n private onItemsChange(): void {\n this.checkContent();\n this.items = Array.from(this.host.children).filter(({slot}) => slot === \"item\") as HTMLElement[];\n this.setItemsA11yAttrs();\n this.items.forEach((item) => {\n if (!isZMenuSection(item)) {\n item.dataset.text = item.textContent;\n }\n });\n }\n\n private setItemTabindex(item: HTMLElement | HTMLZMenuSectionElement, tabIndex: number): void {\n if (isZMenuSection(item)) {\n item.htmlTabindex = tabIndex;\n } else {\n item.tabIndex = tabIndex;\n }\n }\n\n /**\n * Move focus and adjust the tabindex value of `receiver` and `current` elements,\n * setting -1 to the `current` and 0 to the `receiver`, then focus the `receiver` element.\n * If the receiver is a ZMenuSection and it's open, focus its first focusable item.\n */\n private moveFocus(\n receiver: HTMLElement | HTMLZMenuSectionElement,\n current?: HTMLElement | HTMLZMenuSectionElement\n ): void {\n if (isZMenuSection(receiver)) {\n receiver.setFocus();\n } else {\n receiver.tabIndex = 0;\n setTimeout(() => {\n receiver.focus();\n }, 100);\n }\n if (!current) {\n return;\n }\n\n this.setItemTabindex(current, -1);\n }\n\n private onLabelClick(): void {\n this.toggle();\n this.setFocus();\n }\n\n private onLabelKeydown(ev: KeyboardEvent): void {\n if (ev.key === KeyboardCode.ENTER || ev.key === KeyboardCode.SPACE) {\n ev.preventDefault();\n ev.stopPropagation();\n this.toggle();\n if (this.open) {\n this.moveFocus(this.items[0]);\n }\n\n return;\n }\n\n if (!this.verticalContext) {\n return;\n }\n\n if (ev.key === KeyboardCode.ARROW_RIGHT && !this.open) {\n ev.preventDefault();\n ev.stopPropagation();\n this.open = true;\n this.moveFocus(this.items[0]);\n }\n }\n\n /** Set tabindex of the label to 0, then focus it. */\n @Method()\n async setFocus(): Promise<void> {\n this.htmlTabindex = 0;\n const label = this.hasContent ? this.labelButton : (this.host.firstElementChild as HTMLElement);\n label.focus();\n }\n\n /**\n * Focus the last item.\n */\n @Method()\n async focusLastItem(): Promise<void> {\n const lastItem = this.items[this.items.length - 1];\n if (isZMenuSection(lastItem) && lastItem.open) {\n lastItem.focusLastItem();\n\n return;\n }\n\n this.moveFocus(lastItem);\n }\n\n @Watch(\"open\")\n onOpenChanged(): void {\n if (!this.open) {\n cancelAnimationFrame(this.raf);\n this.closed.emit();\n this.items.forEach((item) => {\n if (isZMenuSection(item) && item.open) {\n item.open = false;\n }\n });\n\n return;\n }\n\n this.setItemsA11yAttrs();\n this.opened.emit();\n if (this.floating) {\n this.reflow(true);\n }\n }\n\n @Watch(\"htmlTabindex\")\n setLabelA11yAttrs(): void {\n if (this.hasContent && !this.labelButton) {\n return;\n }\n\n if (this.hasContent) {\n this.labelButton.tabIndex = this.htmlTabindex;\n\n return;\n }\n\n const slottedLabel = this.host.firstElementChild as HTMLElement;\n slottedLabel.role = \"menuitem\";\n slottedLabel.tabIndex = this.htmlTabindex;\n }\n\n /**\n * Set tabindex to -1 to all siblings of the clicked item.\n */\n @Listen(\"click\", {target: \"document\"})\n onItemClick(ev: MouseEvent): void {\n const clickedItem = this.items.find((item) => containsElement(item, ev.target as HTMLElement));\n if (clickedItem) {\n this.items.forEach((item) => {\n if (item === clickedItem) {\n return;\n }\n\n if (isZMenuSection(item)) {\n item.htmlTabindex = -1;\n } else {\n item.tabIndex = -1;\n }\n });\n }\n }\n\n @Listen(\"keydown\")\n onKeyDown(ev: KeyboardEvent): void {\n if (!this.hasContent) {\n return;\n }\n\n switch (ev.key) {\n case KeyboardCode.ESC:\n if (!this.open) {\n break;\n }\n ev.stopPropagation();\n ev.preventDefault();\n this.open = false;\n this.setFocus();\n break;\n case KeyboardCode.ARROW_DOWN: {\n if (document.activeElement === this.host) {\n if (this.verticalContext && !this.open) {\n break;\n }\n\n ev.stopPropagation();\n ev.preventDefault();\n if (!this.open) {\n this.open = true;\n }\n this.moveFocus(this.items[0]);\n break;\n }\n\n const currentIndex = this.items.indexOf(this.focusableItem);\n if (this.verticalContext && currentIndex === this.items.length - 1) {\n // navigation is going to leave this menu. restore tabindex to the label and let the parent handle it\n this.setItemTabindex(this.items[currentIndex], -1);\n this.htmlTabindex = 0;\n break;\n }\n\n ev.stopPropagation();\n ev.preventDefault();\n const receiver = this.items[currentIndex + 1];\n // if the last item is already focused, navigate to the first one\n this.moveFocus(receiver ?? this.items[0], this.focusableItem);\n break;\n }\n case KeyboardCode.ARROW_UP: {\n if (document.activeElement === this.host) {\n if (this.verticalContext) {\n break;\n }\n\n ev.stopPropagation();\n ev.preventDefault();\n // open the menu and focus the last item\n if (!this.open) {\n this.open = true;\n }\n this.moveFocus(this.items[this.items.length - 1], this.focusableItem);\n break;\n }\n\n ev.stopPropagation();\n ev.preventDefault();\n const currentIndex = this.items.indexOf(this.focusableItem);\n if (currentIndex === 0 && this.verticalContext) {\n this.setItemTabindex(this.focusableItem, -1);\n this.setFocus();\n break;\n }\n\n const receiver = this.items[currentIndex - 1] ?? this.items[this.items.length - 1];\n // if the receiver is a ZMenuSection and it's open, focus its last item\n if (isZMenuSection(receiver) && receiver.open) {\n this.setItemTabindex(this.focusableItem, -1);\n receiver.focusLastItem();\n break;\n }\n\n this.moveFocus(receiver, this.focusableItem);\n break;\n }\n case KeyboardCode.ARROW_LEFT:\n if (!this.open || !this.verticalContext) {\n break;\n }\n\n // close the menu and focus the label\n ev.preventDefault();\n ev.stopPropagation();\n this.open = false;\n this.setFocus();\n }\n }\n\n constructor() {\n this.toggle = this.toggle.bind(this);\n this.checkContent = this.checkContent.bind(this);\n this.onLabelSlotChange = this.onLabelSlotChange.bind(this);\n this.onLabelClick = this.onLabelClick.bind(this);\n this.onItemsChange = this.onItemsChange.bind(this);\n this.onLabelKeydown = this.onLabelKeydown.bind(this);\n }\n\n connectedCallback(): void {\n this.onItemsChange();\n this.setLabelA11yAttrs();\n }\n\n render(): HTMLDivElement | HTMLZMenuElement {\n if (!this.hasContent) {\n return (\n <div class=\"menu-label\">\n <slot onSlotchange={this.onLabelSlotChange} />\n </div>\n );\n }\n\n return (\n <Host>\n <button\n ref={(el) => (this.labelButton = el)}\n class=\"menu-label\"\n aria-expanded={`${!!this.open}`}\n aria-haspopup={`${this.hasContent}`}\n aria-label={this.open ? \"Chiudi menù\" : \"Apri menù\"}\n role=\"menuitem\"\n tabIndex={this.htmlTabindex}\n onClick={this.onLabelClick}\n onKeyDown={this.onLabelKeydown}\n >\n <slot onSlotchange={this.onLabelSlotChange} />\n <z-icon name={this.open ? \"chevron-up\" : \"chevron-down\"} />\n </button>\n\n <div\n class=\"content\"\n ref={(el) => (this.content = el)}\n >\n {this.hasHeader && (\n <header class=\"header\">\n <slot\n name=\"header\"\n onSlotchange={this.checkContent}\n />\n </header>\n )}\n\n <div\n class=\"items\"\n role=\"menu\"\n >\n <slot\n name=\"item\"\n onSlotchange={this.onItemsChange}\n />\n </div>\n </div>\n </Host>\n );\n }\n}\n"],"version":3}