@itcenteratunihelsinki/huds-lib 0.8.69 → 0.8.71
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/hy-dropdown.js +147 -46
- package/components/hy-dropdown.js.map +1 -1
- package/components/hy-footer-info.js +1 -1
- package/components/hy-footer-info.js.map +1 -1
- package/components/hy-footer-link-item2.js +2 -2
- package/components/hy-footer-link-item2.js.map +1 -1
- package/dist/cjs/huds-lib.cjs.js +1 -1
- package/dist/cjs/hy-breadcrumbs_15.cjs.entry.js +3 -3
- package/dist/cjs/hy-breadcrumbs_15.cjs.entry.js.map +1 -1
- package/dist/cjs/hy-dropdown.cjs.entry.js +226 -0
- package/dist/cjs/hy-dropdown.cjs.entry.js.map +1 -0
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/collection/collection-manifest.json +5 -9
- package/dist/collection/components/footer/hy-footer-info/hy-footer-info.css +2 -2
- package/dist/collection/components/footer/hy-footer-link-item/hy-footer-link-item.css +8 -1
- package/dist/collection/components/footer/hy-footer-link-item/hy-footer-link-item.js +1 -1
- package/dist/collection/components/footer/hy-footer-link-item/hy-footer-link-item.js.map +1 -1
- package/dist/collection/components/hy-dropdown/hy-dropdown.css +48 -33
- package/dist/collection/components/hy-dropdown/hy-dropdown.js +232 -35
- package/dist/collection/components/hy-dropdown/hy-dropdown.js.map +1 -1
- package/dist/esm/huds-lib.js +1 -1
- package/dist/esm/hy-breadcrumbs_15.entry.js +3 -3
- package/dist/esm/hy-breadcrumbs_15.entry.js.map +1 -1
- package/dist/esm/hy-dropdown.entry.js +222 -0
- package/dist/esm/hy-dropdown.entry.js.map +1 -0
- package/dist/esm/loader.js +1 -1
- package/dist/huds-lib/huds-lib.esm.js +1 -1
- package/dist/huds-lib/huds-lib.esm.js.map +1 -1
- package/dist/huds-lib/hy-breadcrumbs_15.entry.js +1 -1
- package/dist/huds-lib/hy-breadcrumbs_15.entry.js.map +1 -1
- package/dist/huds-lib/hy-dropdown.entry.js +2 -0
- package/dist/huds-lib/hy-dropdown.entry.js.map +1 -0
- package/dist/types/components/hy-dropdown/hy-dropdown.d.ts +17 -3
- package/dist/types/components.d.ts +10 -36
- package/package.json +2 -2
- package/components/hy-dropdown-panel-item.d.ts +0 -11
- package/components/hy-dropdown-panel-item.js +0 -8
- package/components/hy-dropdown-panel-item.js.map +0 -1
- package/components/hy-dropdown-panel.d.ts +0 -11
- package/components/hy-dropdown-panel.js +0 -8
- package/components/hy-dropdown-panel.js.map +0 -1
- package/components/hy-dropdown.panel.item.js +0 -43
- package/components/hy-dropdown.panel.item.js.map +0 -1
- package/components/hy-dropdown.panel.js +0 -31
- package/components/hy-dropdown.panel.js.map +0 -1
- package/dist/cjs/hy-dropdown_3.cjs.entry.js +0 -141
- package/dist/cjs/hy-dropdown_3.cjs.entry.js.map +0 -1
- package/dist/collection/components/hy-dropdown/hy-dropdown.panel.item.js +0 -87
- package/dist/collection/components/hy-dropdown/hy-dropdown.panel.item.js.map +0 -1
- package/dist/collection/components/hy-dropdown/hy-dropdown.panel.js +0 -32
- package/dist/collection/components/hy-dropdown/hy-dropdown.panel.js.map +0 -1
- package/dist/esm/hy-dropdown_3.entry.js +0 -135
- package/dist/esm/hy-dropdown_3.entry.js.map +0 -1
- package/dist/huds-lib/hy-dropdown_3.entry.js +0 -2
- package/dist/huds-lib/hy-dropdown_3.entry.js.map +0 -1
- package/dist/types/components/hy-dropdown/hy-dropdown.panel.d.ts +0 -4
- package/dist/types/components/hy-dropdown/hy-dropdown.panel.item.d.ts +0 -7
|
@@ -93,6 +93,12 @@
|
|
|
93
93
|
min-width: 100%;
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
+
.hy-dropdown .hy-dropdown__hidden-input {
|
|
97
|
+
display: none;
|
|
98
|
+
height: 0;
|
|
99
|
+
font-size: 0;
|
|
100
|
+
}
|
|
101
|
+
|
|
96
102
|
.hy-dropdown__toggle {
|
|
97
103
|
font-size: 0.875rem;
|
|
98
104
|
line-height: 24px;
|
|
@@ -238,14 +244,6 @@
|
|
|
238
244
|
}
|
|
239
245
|
|
|
240
246
|
.hy-dropdown__panel-item {
|
|
241
|
-
position: relative;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
.hy-dropdown__panel-item:not(.is-last) {
|
|
245
|
-
margin-bottom: 6px;
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
.hy-dropdown__label {
|
|
249
247
|
font-size: 0.875rem;
|
|
250
248
|
line-height: 24px;
|
|
251
249
|
-webkit-box-align: center;
|
|
@@ -265,18 +263,48 @@
|
|
|
265
263
|
-ms-flex-pack: justify;
|
|
266
264
|
justify-content: space-between;
|
|
267
265
|
letter-spacing: normal;
|
|
268
|
-
|
|
266
|
+
position: relative;
|
|
267
|
+
padding: 0;
|
|
269
268
|
text-align: left;
|
|
270
269
|
width: 100%;
|
|
271
270
|
}
|
|
272
271
|
|
|
273
272
|
@media (min-width: 30rem) {
|
|
274
|
-
.hy-
|
|
273
|
+
.hy-dropdown__panel-item {
|
|
275
274
|
font-size: 1rem;
|
|
276
275
|
line-height: 24px;
|
|
277
276
|
}
|
|
278
277
|
}
|
|
279
278
|
|
|
279
|
+
.hy-dropdown__panel-item:not(.is-last) {
|
|
280
|
+
margin-bottom: 6px;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
.hy-dropdown__panel-item[aria-selected=true] .hy-dropdown__checkbox {
|
|
284
|
+
border-color: var(--grayscale-black);
|
|
285
|
+
border-style: solid inset solid solid;
|
|
286
|
+
border-width: 2px;
|
|
287
|
+
color: var(--grayscale-black);
|
|
288
|
+
outline: 0;
|
|
289
|
+
text-indent: -1px;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
.hy-dropdown__panel-item[aria-selected=true] .hy-dropdown__checkbox .hy-dropdown__label-icon {
|
|
293
|
+
display: -webkit-inline-box !important;
|
|
294
|
+
display: -ms-inline-flexbox !important;
|
|
295
|
+
display: inline-flex !important;
|
|
296
|
+
visibility: visible;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
.hy-dropdown__panel-item--focused {
|
|
300
|
+
cursor: pointer;
|
|
301
|
+
border-color: var(--brand-main-light);
|
|
302
|
+
border-style: solid inset solid solid;
|
|
303
|
+
border-width: 2px;
|
|
304
|
+
outline: 0;
|
|
305
|
+
text-indent: -1px;
|
|
306
|
+
}
|
|
307
|
+
|
|
280
308
|
.hy-dropdown__label-icon {
|
|
281
309
|
-webkit-box-align: center;
|
|
282
310
|
-ms-flex-align: center;
|
|
@@ -294,39 +322,26 @@
|
|
|
294
322
|
}
|
|
295
323
|
|
|
296
324
|
.hy-dropdown__checkbox {
|
|
325
|
+
display: -webkit-box;
|
|
326
|
+
display: -ms-flexbox;
|
|
327
|
+
display: flex;
|
|
328
|
+
-webkit-box-align: center;
|
|
329
|
+
-ms-flex-align: center;
|
|
330
|
+
align-items: center;
|
|
331
|
+
min-height: 40px;
|
|
297
332
|
height: 100%;
|
|
298
333
|
margin: 0;
|
|
299
|
-
|
|
300
|
-
position: absolute;
|
|
334
|
+
padding: 0 16px;
|
|
301
335
|
width: 100%;
|
|
302
336
|
z-index: 10;
|
|
303
337
|
}
|
|
304
338
|
|
|
305
|
-
.hy-dropdown__checkbox:checked + label {
|
|
306
|
-
border-color: var(--grayscale-black);
|
|
307
|
-
border-style: solid inset solid solid;
|
|
308
|
-
border-width: 2px;
|
|
309
|
-
color: var(--grayscale-black);
|
|
310
|
-
outline: 0;
|
|
311
|
-
text-indent: -1px;
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
.hy-dropdown__checkbox:checked + label .hy-dropdown__label-icon {
|
|
315
|
-
display: -webkit-inline-box !important;
|
|
316
|
-
display: -ms-inline-flexbox !important;
|
|
317
|
-
display: inline-flex !important;
|
|
318
|
-
visibility: visible;
|
|
319
|
-
}
|
|
320
|
-
|
|
321
339
|
.hy-dropdown__checkbox:hover {
|
|
322
340
|
cursor: pointer;
|
|
341
|
+
border-color: var(--brand-main-active);
|
|
323
342
|
}
|
|
324
343
|
|
|
325
|
-
.hy-dropdown__checkbox:
|
|
326
|
-
border-color: var(--brand-main-light);
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
.hy-dropdown__checkbox:focus + label {
|
|
344
|
+
.hy-dropdown__checkbox:focus-within {
|
|
330
345
|
border-color: var(--brand-main-light);
|
|
331
346
|
border-style: solid inset solid solid;
|
|
332
347
|
border-width: 2px;
|
|
@@ -7,10 +7,13 @@ export class HyDropdown {
|
|
|
7
7
|
this.dropdownId = "dropdownToggle";
|
|
8
8
|
this.dropdownOptions = undefined;
|
|
9
9
|
this.defaultLabel = "All";
|
|
10
|
+
this.type = null;
|
|
10
11
|
this.defaultOption = null;
|
|
11
12
|
this.isPanelOpen = false;
|
|
12
13
|
this.isChecked = false;
|
|
13
14
|
this.currentSingle = [{ id: 0, label: this.defaultLabel, value: 0 }];
|
|
15
|
+
this.currentMulti = undefined;
|
|
16
|
+
this.focusedOptionIndex = 0;
|
|
14
17
|
}
|
|
15
18
|
async componentWillLoad() {
|
|
16
19
|
this._dropdownOptions = await jsonParserWorker(this.dropdownOptions);
|
|
@@ -41,59 +44,164 @@ export class HyDropdown {
|
|
|
41
44
|
});
|
|
42
45
|
}
|
|
43
46
|
}
|
|
44
|
-
|
|
45
|
-
this.isPanelOpen
|
|
46
|
-
}
|
|
47
|
-
handleClick(event) {
|
|
48
|
-
const dropdownToggleButtonElement = this.el.querySelector(`#${this.dropdownId}`);
|
|
49
|
-
const dropdownPanelElement = this.el.querySelector(".hy-dropdown__panel");
|
|
50
|
-
const dropdownPanelCheckboxElements = this.el.querySelectorAll(".hy-dropdown__checkbox");
|
|
51
|
-
const dropdownToggleButtonIconElement = this.el.querySelector(".hy-dropdown__icon");
|
|
52
|
-
const { target } = event;
|
|
53
|
-
const allowedElements = [
|
|
54
|
-
dropdownToggleButtonElement,
|
|
55
|
-
dropdownPanelElement,
|
|
56
|
-
dropdownToggleButtonIconElement,
|
|
57
|
-
...dropdownPanelCheckboxElements, // Spread ("copy") items to allowedElement array.
|
|
58
|
-
];
|
|
59
|
-
if (this.isPanelOpen && !allowedElements.includes(target)) {
|
|
47
|
+
panelListener(e) {
|
|
48
|
+
if (this.isPanelOpen && e.detail.dropdownId !== this.dropdownId) {
|
|
60
49
|
this.isPanelOpen = false;
|
|
61
50
|
}
|
|
51
|
+
}
|
|
52
|
+
handleMultiClick(event, option) {
|
|
62
53
|
event.stopPropagation();
|
|
54
|
+
const dropdownPanelCheckboxElements = this.el.getElementsByClassName("hy-dropdown__checkbox");
|
|
55
|
+
Array.from(dropdownPanelCheckboxElements).filter((i) => {
|
|
56
|
+
const item = i.closest("li");
|
|
57
|
+
if (item.dataset.id == option.id && !item.hasAttribute("aria-selected")) {
|
|
58
|
+
item.setAttribute("aria-selected", "true");
|
|
59
|
+
this.currentMulti =
|
|
60
|
+
this.currentMulti && this.currentMulti.length > 0 ? [...this.currentMulti, option] : [option];
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (item.dataset.id === option.id && item.hasAttribute("aria-selected")) {
|
|
64
|
+
item.removeAttribute("aria-selected");
|
|
65
|
+
if (this.currentMulti.length > 0) {
|
|
66
|
+
const index = this.currentMulti.indexOf(option);
|
|
67
|
+
this.currentMulti = this.currentMulti.splice(index, 1);
|
|
68
|
+
}
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
return null;
|
|
72
|
+
});
|
|
63
73
|
}
|
|
64
|
-
handleSingleClick(event) {
|
|
74
|
+
handleSingleClick(event, option) {
|
|
65
75
|
if (!this.single || !this.isPanelOpen)
|
|
66
76
|
return;
|
|
67
77
|
const dropdownPanelCheckboxElements = this.el.getElementsByClassName("hy-dropdown__checkbox");
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
if (!item.checked) {
|
|
78
|
+
event.stopPropagation();
|
|
79
|
+
Array.from(dropdownPanelCheckboxElements).filter((i) => {
|
|
80
|
+
const item = i.closest("li");
|
|
81
|
+
if (item.dataset.id == option.id) {
|
|
82
|
+
if (item.hasAttribute("aria-selected")) {
|
|
83
|
+
item.removeAttribute("aria-selected");
|
|
75
84
|
this.currentSingle = [{ id: null, label: this.defaultLabel, value: null }];
|
|
76
85
|
return;
|
|
77
86
|
}
|
|
78
|
-
|
|
87
|
+
item.setAttribute("aria-selected", "true");
|
|
88
|
+
this.currentSingle = this._dropdownOptions.filter((o) => o.id == option.id);
|
|
79
89
|
return;
|
|
80
90
|
}
|
|
81
|
-
if (item.id !==
|
|
82
|
-
item.
|
|
91
|
+
if (item.dataset.id !== option.id && item.hasAttribute("aria-selected")) {
|
|
92
|
+
item.removeAttribute("aria-selected");
|
|
83
93
|
return;
|
|
84
94
|
}
|
|
85
95
|
return null;
|
|
86
96
|
});
|
|
97
|
+
}
|
|
98
|
+
handleKeyDown(event) {
|
|
87
99
|
event.stopPropagation();
|
|
100
|
+
switch (event.key) {
|
|
101
|
+
case "ArrowDown":
|
|
102
|
+
event.preventDefault();
|
|
103
|
+
if (!this.isPanelOpen) {
|
|
104
|
+
this.handlePanelToggle(event);
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
this.focusedOptionIndex = (this.focusedOptionIndex + 1) % this._dropdownOptions.length;
|
|
108
|
+
break;
|
|
109
|
+
case "ArrowUp":
|
|
110
|
+
this.focusedOptionIndex =
|
|
111
|
+
(this.focusedOptionIndex - 1 + this._dropdownOptions.length) % this._dropdownOptions.length;
|
|
112
|
+
event.preventDefault();
|
|
113
|
+
break;
|
|
114
|
+
case "Enter":
|
|
115
|
+
case " ":
|
|
116
|
+
if (!this.isPanelOpen) {
|
|
117
|
+
event.preventDefault();
|
|
118
|
+
this.handlePanelToggle(event);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
if (this.single) {
|
|
122
|
+
this.handleOptionSingleClick(event, this._dropdownOptions[this.focusedOptionIndex]);
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
this.handleMultiOptionClick(event, this._dropdownOptions[this.focusedOptionIndex]);
|
|
126
|
+
}
|
|
127
|
+
const emitDetails = {
|
|
128
|
+
id: this.dropdownId,
|
|
129
|
+
type: this.type,
|
|
130
|
+
data: this._dropdownOptions[this.focusedOptionIndex],
|
|
131
|
+
};
|
|
132
|
+
this.dropdownKeyPress.emit(emitDetails);
|
|
133
|
+
event.preventDefault();
|
|
134
|
+
break;
|
|
135
|
+
case "Escape":
|
|
136
|
+
case "Tab":
|
|
137
|
+
this.isPanelOpen = false;
|
|
138
|
+
break;
|
|
139
|
+
default:
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
handlePanelToggle(e) {
|
|
144
|
+
e.stopPropagation();
|
|
145
|
+
this.isPanelOpen = !this.isPanelOpen;
|
|
146
|
+
const emitDetails = {
|
|
147
|
+
dropdownId: this.dropdownId,
|
|
148
|
+
panelOpen: this.isPanelOpen,
|
|
149
|
+
};
|
|
150
|
+
this.dropdownPanelToggled.emit(emitDetails);
|
|
151
|
+
}
|
|
152
|
+
handlePanelClickOutside(e) {
|
|
153
|
+
e.stopPropagation();
|
|
154
|
+
const dropdownToggleButtonElement = this.el.querySelector(`#${this.dropdownId}`);
|
|
155
|
+
const dropdownPanelElement = this.el.querySelector(".hy-dropdown__panel");
|
|
156
|
+
const dropdownPanelCheckboxElements = this.el.querySelectorAll(".hy-dropdown__panel-item");
|
|
157
|
+
const dropdownPanelCheckboxes = this.el.querySelectorAll(".hy-dropdown__checkbox");
|
|
158
|
+
const dropdownToggleButtonIconElement = this.el.querySelectorAll(".hy-dropdown__icon");
|
|
159
|
+
const { target } = e;
|
|
160
|
+
const allowedElements = [
|
|
161
|
+
this.el,
|
|
162
|
+
dropdownToggleButtonElement,
|
|
163
|
+
dropdownPanelElement,
|
|
164
|
+
...dropdownPanelCheckboxes,
|
|
165
|
+
dropdownToggleButtonIconElement,
|
|
166
|
+
...dropdownPanelCheckboxElements, // Spread ("copy") items to allowedElement array.
|
|
167
|
+
];
|
|
168
|
+
if (this.isPanelOpen && !allowedElements.includes(target)) {
|
|
169
|
+
this.isPanelOpen = false;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
handleOptionSingleClick(event, option) {
|
|
173
|
+
event.stopPropagation();
|
|
174
|
+
this.handleSingleClick(event, option);
|
|
175
|
+
const emitDetails = {
|
|
176
|
+
id: this.dropdownId,
|
|
177
|
+
type: this.type,
|
|
178
|
+
data: option,
|
|
179
|
+
};
|
|
180
|
+
this.dropdropValueChange.emit(emitDetails);
|
|
181
|
+
}
|
|
182
|
+
handleMultiOptionClick(event, option) {
|
|
183
|
+
event.stopPropagation();
|
|
184
|
+
this.handleMultiClick(event, option);
|
|
185
|
+
const emitDetails = {
|
|
186
|
+
id: this.dropdownId,
|
|
187
|
+
type: this.type,
|
|
188
|
+
data: this.currentMulti,
|
|
189
|
+
};
|
|
190
|
+
this.dropdropMultiValueChange.emit(emitDetails);
|
|
191
|
+
}
|
|
192
|
+
handleOptionHover(index) {
|
|
193
|
+
this.focusedOptionIndex = index;
|
|
88
194
|
}
|
|
89
195
|
render() {
|
|
90
196
|
const { label: currentLabel, id: currentId, value: currentValue } = this.currentSingle[0];
|
|
91
197
|
const classAttributes = ["hy-dropdown", this.single ? "hy-dropdown--single" : ""].join(" ");
|
|
92
198
|
if (this.single) {
|
|
93
|
-
return (h(Host, { class: classAttributes }, this.dropdownLabel && (h("label", { class: "hy-dropdown__button-label", htmlFor: this.dropdownId }, this.dropdownLabel)), h("
|
|
199
|
+
return (h(Host, { class: classAttributes }, this.dropdownLabel && (h("label", { class: "hy-dropdown__button-label", htmlFor: this.dropdownId }, this.dropdownLabel)), h("div", { id: this.dropdownId, class: `hy-dropdown__toggle ${this.isPanelOpen ? "is-open" : ""}`, "aria-expanded": `${this.isPanelOpen || false}`, "aria-controls": "dropdownPanel", "aria-haspopup": "listbox", role: "combobox", onClick: (event) => this.handlePanelToggle(event), onKeyDown: (event) => this.handleKeyDown(event), "aria-label": this.dropdownLabel, "data-current-id": currentId, "data-current-value": currentValue, "data-value": currentId, tabIndex: 0 }, h("input", { "aria-hidden": "true", class: "hy-dropdown__hidden-input", type: "hidden", value: currentId }), currentLabel, h("hy-icon", { class: "hy-dropdown__icon", icon: "hy-icon-caret-down", size: 14, "aria-hidden": "true" })), h("ul", { "checkbox-checked": this.isChecked ? "true" : "false", id: "dropdownPanel", class: `hy-dropdown__panel ${!this.isPanelOpen ? "is-hidden" : ""}`, "aria-expanded": `${!this.isPanelOpen || false}`, role: "listbox", "aria-labelledby": "dropdownToggle" }, this._dropdownOptions.map(({ id, label, value }, index, items) => (h("li", { key: id, "data-id": `${id}`, role: "option", class: `hy-dropdown__panel-item ${this._dropdownOptions.length - 1 === index ? "is-last" : ""}
|
|
200
|
+
${this.focusedOptionIndex === index ? "hy-dropdown__panel-item--focused" : ""}`, onClick: (event) => this.handleOptionSingleClick(event, items[index]), onMouseEnter: () => this.handleOptionHover(index) }, h("span", { "data-id": `${id}`, class: "hy-dropdown__checkbox", "data-value": `${value}` }, label, h("hy-icon", { class: "hy-dropdown__label-icon", icon: "hy-icon-done", size: 14, "aria-hidden": "true" }))))))));
|
|
94
201
|
}
|
|
95
202
|
else {
|
|
96
|
-
return (h(Host, { class: classAttributes }, h("button", { id: this.dropdownId, class: `hy-dropdown__toggle ${this.isPanelOpen ? "is-open" : ""}`, "aria-expanded": `${this.isPanelOpen || false}`, "aria-controls": "dropdownPanel", onClick: () => this.handlePanelToggle(), "aria-label": this.dropdownLabel, type: "button" }, this.dropdownLabel && this.dropdownLabel, h("hy-icon", { class: "hy-dropdown__icon", icon: "hy-icon-caret-down", size: 14, "aria-hidden": "true" })), h("
|
|
203
|
+
return (h(Host, { class: classAttributes }, h("button", { id: this.dropdownId, class: `hy-dropdown__toggle ${this.isPanelOpen ? "is-open" : ""}`, "aria-expanded": `${this.isPanelOpen || false}`, "aria-controls": "dropdownPanel", "aria-haspopup": "listbox", role: "combobox", onClick: (event) => this.handlePanelToggle(event), "aria-label": this.dropdownLabel, type: "button" }, this.dropdownLabel && this.dropdownLabel, h("hy-icon", { class: "hy-dropdown__icon", icon: "hy-icon-caret-down", size: 14, "aria-hidden": "true" })), h("ul", { "checkbox-checked": this.isChecked ? "true" : "false", id: "dropdownPanel", class: `hy-dropdown__panel ${!this.isPanelOpen ? "is-hidden" : ""}`, "aria-expanded": `${!this.isPanelOpen || false}`, role: "listbox", "aria-labelledby": "dropdownToggle" }, this._dropdownOptions.map(({ id, label, value }, index, items) => (h("li", { key: id, "data-id": `${id}`, role: "option", class: `hy-dropdown__panel-item ${this._dropdownOptions.length - 1 === index ? "is-last" : ""}
|
|
204
|
+
${this.focusedOptionIndex === index ? "hy-dropdown__panel-item--focused" : ""}`, onClick: (event) => this.handleMultiOptionClick(event, items[index]), onMouseEnter: () => this.handleOptionHover(index) }, h("span", { "data-id": `${id}`, class: "hy-dropdown__checkbox", "data-value": `${value}` }, label, h("hy-icon", { class: "hy-dropdown__label-icon", icon: "hy-icon-done", size: 14, "aria-hidden": "true" }))))))));
|
|
97
205
|
}
|
|
98
206
|
}
|
|
99
207
|
static get is() { return "hy-dropdown"; }
|
|
@@ -203,6 +311,24 @@ export class HyDropdown {
|
|
|
203
311
|
"reflect": false,
|
|
204
312
|
"defaultValue": "\"All\""
|
|
205
313
|
},
|
|
314
|
+
"type": {
|
|
315
|
+
"type": "string",
|
|
316
|
+
"mutable": false,
|
|
317
|
+
"complexType": {
|
|
318
|
+
"original": "string",
|
|
319
|
+
"resolved": "string",
|
|
320
|
+
"references": {}
|
|
321
|
+
},
|
|
322
|
+
"required": false,
|
|
323
|
+
"optional": false,
|
|
324
|
+
"docs": {
|
|
325
|
+
"tags": [],
|
|
326
|
+
"text": ""
|
|
327
|
+
},
|
|
328
|
+
"attribute": "type",
|
|
329
|
+
"reflect": false,
|
|
330
|
+
"defaultValue": "null"
|
|
331
|
+
},
|
|
206
332
|
"defaultOption": {
|
|
207
333
|
"type": "any",
|
|
208
334
|
"mutable": true,
|
|
@@ -227,9 +353,74 @@ export class HyDropdown {
|
|
|
227
353
|
return {
|
|
228
354
|
"isPanelOpen": {},
|
|
229
355
|
"isChecked": {},
|
|
230
|
-
"currentSingle": {}
|
|
356
|
+
"currentSingle": {},
|
|
357
|
+
"currentMulti": {},
|
|
358
|
+
"focusedOptionIndex": {}
|
|
231
359
|
};
|
|
232
360
|
}
|
|
361
|
+
static get events() {
|
|
362
|
+
return [{
|
|
363
|
+
"method": "dropdownPanelToggled",
|
|
364
|
+
"name": "dropdownPanelToggled",
|
|
365
|
+
"bubbles": true,
|
|
366
|
+
"cancelable": true,
|
|
367
|
+
"composed": true,
|
|
368
|
+
"docs": {
|
|
369
|
+
"tags": [],
|
|
370
|
+
"text": ""
|
|
371
|
+
},
|
|
372
|
+
"complexType": {
|
|
373
|
+
"original": "any",
|
|
374
|
+
"resolved": "any",
|
|
375
|
+
"references": {}
|
|
376
|
+
}
|
|
377
|
+
}, {
|
|
378
|
+
"method": "dropdropValueChange",
|
|
379
|
+
"name": "dropdownValueChanged",
|
|
380
|
+
"bubbles": true,
|
|
381
|
+
"cancelable": true,
|
|
382
|
+
"composed": true,
|
|
383
|
+
"docs": {
|
|
384
|
+
"tags": [],
|
|
385
|
+
"text": ""
|
|
386
|
+
},
|
|
387
|
+
"complexType": {
|
|
388
|
+
"original": "any",
|
|
389
|
+
"resolved": "any",
|
|
390
|
+
"references": {}
|
|
391
|
+
}
|
|
392
|
+
}, {
|
|
393
|
+
"method": "dropdropMultiValueChange",
|
|
394
|
+
"name": "dropdownMultiValueChanged",
|
|
395
|
+
"bubbles": true,
|
|
396
|
+
"cancelable": true,
|
|
397
|
+
"composed": true,
|
|
398
|
+
"docs": {
|
|
399
|
+
"tags": [],
|
|
400
|
+
"text": ""
|
|
401
|
+
},
|
|
402
|
+
"complexType": {
|
|
403
|
+
"original": "any",
|
|
404
|
+
"resolved": "any",
|
|
405
|
+
"references": {}
|
|
406
|
+
}
|
|
407
|
+
}, {
|
|
408
|
+
"method": "dropdownKeyPress",
|
|
409
|
+
"name": "dropdownKeyPress",
|
|
410
|
+
"bubbles": true,
|
|
411
|
+
"cancelable": true,
|
|
412
|
+
"composed": true,
|
|
413
|
+
"docs": {
|
|
414
|
+
"tags": [],
|
|
415
|
+
"text": ""
|
|
416
|
+
},
|
|
417
|
+
"complexType": {
|
|
418
|
+
"original": "any",
|
|
419
|
+
"resolved": "any",
|
|
420
|
+
"references": {}
|
|
421
|
+
}
|
|
422
|
+
}];
|
|
423
|
+
}
|
|
233
424
|
static get elementRef() { return "el"; }
|
|
234
425
|
static get watchers() {
|
|
235
426
|
return [{
|
|
@@ -239,16 +430,22 @@ export class HyDropdown {
|
|
|
239
430
|
}
|
|
240
431
|
static get listeners() {
|
|
241
432
|
return [{
|
|
242
|
-
"name": "
|
|
243
|
-
"method": "
|
|
433
|
+
"name": "dropdownPanelToggled",
|
|
434
|
+
"method": "panelListener",
|
|
244
435
|
"target": "window",
|
|
245
436
|
"capture": false,
|
|
246
437
|
"passive": false
|
|
247
438
|
}, {
|
|
248
|
-
"name": "
|
|
249
|
-
"method": "
|
|
439
|
+
"name": "keydown",
|
|
440
|
+
"method": "handleKeyDown",
|
|
250
441
|
"target": undefined,
|
|
251
|
-
"capture":
|
|
442
|
+
"capture": false,
|
|
443
|
+
"passive": false
|
|
444
|
+
}, {
|
|
445
|
+
"name": "click",
|
|
446
|
+
"method": "handlePanelClickOutside",
|
|
447
|
+
"target": "window",
|
|
448
|
+
"capture": false,
|
|
252
449
|
"passive": false
|
|
253
450
|
}];
|
|
254
451
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hy-dropdown.js","sourceRoot":"","sources":["../../../src/components/hy-dropdown/hy-dropdown.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAC,MAAM,eAAe,CAAC;AAC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,CAAC,WAAW,IAAI,KAAK,EAAE,mBAC/B,eAAe,EAC7B,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,iBAAiB,EAAE,gBAC3B,IAAI,CAAC,aAAa,EAC9B,IAAI,EAAC,QAAQ;UAEZ,IAAI,CAAC,aAAa,IAAI,IAAI,CAAC,aAAa;UACzC,eAAS,KAAK,EAAC,mBAAmB,EAAC,IAAI,EAAE,oBAAoB,EAAE,IAAI,EAAE,EAAE,iBAAc,MAAM,GAAG,CACvF;QACT,6CAAqC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,eAAa,CAAC,IAAI,CAAC,WAAW,IACjG,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC,EAAC,EAAE,EAAE,KAAK,EAAE,KAAK,EAAC,EAAE,KAAK,EAAE,EAAE,CAAC,CACxD,kDACoB,EAAE,yBACC,KAAK,yBACL,KAAK,aACjB,IAAI,CAAC,gBAAgB,CAAC,MAAM,GAAG,CAAC,KAAK,KAAK,GACnD,CACH,CAAC,CACgB,CACf,CACR,CAAC;KACH;EACH,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACF","sourcesContent":["import {Component, Element, Host, h, State, Listen, Prop, Watch} from \"@stencil/core\";\nimport {jsonParserWorker} from \"../../global/globalScript\";\n\nexport interface IDropdownItem {\n id: string | number;\n label: string;\n value: string | number;\n}\n\nexport interface DefaultValue {\n id: string | number;\n label: string;\n value: string | number;\n}\n\n@Component({\n tag: \"hy-dropdown\",\n styleUrl: \"hy-dropdown.scss\",\n shadow: false,\n})\nexport class HyDropdown {\n private _dropdownOptions: IDropdownItem[];\n @Element() el: HTMLElement;\n @Prop() single: boolean = false;\n @Prop() dropdownLabel: string = null;\n @Prop() dropdownId: string = \"dropdownToggle\";\n @Prop() dropdownOptions: IDropdownItem[] | string;\n @Prop() defaultLabel: string = \"All\";\n @Prop({mutable: true}) defaultOption: string | number = null;\n @State() isPanelOpen: boolean = false;\n @State() isChecked: boolean = false;\n @State() currentSingle: DefaultValue[] = [{id: 0, label: this.defaultLabel, value: 0}];\n\n async componentWillLoad() {\n this._dropdownOptions = await jsonParserWorker(this.dropdownOptions);\n }\n\n componentWillUpdate() {\n const items = this.el.querySelectorAll(\".hy-dropdown__checkbox\") as any;\n if (items) {\n if ([...items].some((item) => item.checked == true)) {\n this.isChecked = true;\n } else {\n this.isChecked = false;\n }\n }\n }\n\n @Watch(\"defaultOption\")\n watchPropHandler(newValue: string | number, oldValue: string | number) {\n if (!this.single) return;\n\n if (newValue !== oldValue) {\n const dropdownPanelCheckboxElements = this.el.getElementsByClassName(\"hy-dropdown__checkbox\") as HTMLCollectionOf<\n HTMLInputElement\n >;\n\n Array.from(dropdownPanelCheckboxElements).filter((item) => {\n if (item.id == newValue) {\n item.checked = true;\n this.currentSingle = this._dropdownOptions.filter((option) => option.id == newValue) as any;\n return;\n }\n return null;\n });\n }\n }\n\n handlePanelToggle() {\n this.isPanelOpen = !this.isPanelOpen;\n }\n\n @Listen(\"click\", {target: \"window\"})\n handleClick(event) {\n const dropdownToggleButtonElement = this.el.querySelector(`#${this.dropdownId}`) as HTMLButtonElement;\n const dropdownPanelElement = this.el.querySelector(\".hy-dropdown__panel\") as HTMLElement;\n const dropdownPanelCheckboxElements = this.el.querySelectorAll(\".hy-dropdown__checkbox\");\n const dropdownToggleButtonIconElement = this.el.querySelector(\".hy-dropdown__icon\") as HTMLElement;\n\n const {target} = event;\n\n const allowedElements = [\n dropdownToggleButtonElement,\n dropdownPanelElement,\n dropdownToggleButtonIconElement,\n ...dropdownPanelCheckboxElements, // Spread (\"copy\") items to allowedElement array.\n ];\n\n if (this.isPanelOpen && !allowedElements.includes(target)) {\n this.isPanelOpen = false;\n }\n event.stopPropagation();\n }\n\n @Listen(\"click\", {capture: true})\n handleSingleClick(event) {\n if (!this.single || !this.isPanelOpen) return;\n const dropdownPanelCheckboxElements = this.el.getElementsByClassName(\"hy-dropdown__checkbox\") as HTMLCollectionOf<\n HTMLInputElement\n >;\n const allowedElements = [...dropdownPanelCheckboxElements];\n const {target} = event;\n if (!allowedElements.includes(target)) return;\n Array.from(dropdownPanelCheckboxElements).filter((item) => {\n if (item.id == target.id) {\n if (!item.checked) {\n this.currentSingle = [{id: null, label: this.defaultLabel, value: null}];\n return;\n }\n this.currentSingle = this._dropdownOptions.filter((option) => option.id == target.id) as any;\n return;\n }\n if (item.id !== target.id && item.checked) {\n item.checked = false;\n return;\n }\n return null;\n });\n\n event.stopPropagation();\n }\n\n render() {\n const {label: currentLabel, id: currentId, value: currentValue} = this.currentSingle[0];\n const classAttributes = [\"hy-dropdown\", this.single ? \"hy-dropdown--single\" : \"\"].join(\" \");\n\n if (this.single) {\n return (\n <Host class={classAttributes}>\n {this.dropdownLabel && (\n <label class=\"hy-dropdown__button-label\" htmlFor={this.dropdownId}>\n {this.dropdownLabel}\n </label>\n )}\n <button\n id={this.dropdownId}\n class={`hy-dropdown__toggle ${this.isPanelOpen ? \"is-open\" : \"\"}`}\n aria-expanded={`${this.isPanelOpen || false}`}\n aria-controls=\"dropdownPanel\"\n onClick={() => this.handlePanelToggle()}\n aria-label={this.dropdownLabel}\n data-current-id={currentId}\n data-current-value={currentValue}\n value={currentId}\n type=\"button\"\n >\n {currentLabel}\n <hy-icon class=\"hy-dropdown__icon\" icon={\"hy-icon-caret-down\"} size={14} aria-hidden=\"true\" />\n </button>\n <hy-dropdown-panel checkbox-checked={this.isChecked ? \"true\" : \"false\"} is-hidden={!this.isPanelOpen}>\n {this._dropdownOptions.map(({id, label, value}, index) => (\n <hy-dropdown-panel-item\n dropdown-item-id={id}\n dropdown-item-label={label}\n dropdown-item-value={value}\n is-last={this._dropdownOptions.length - 1 === index}\n />\n ))}\n </hy-dropdown-panel>\n </Host>\n );\n } else {\n return (\n <Host class={classAttributes}>\n <button\n id={this.dropdownId}\n class={`hy-dropdown__toggle ${this.isPanelOpen ? \"is-open\" : \"\"}`}\n aria-expanded={`${this.isPanelOpen || false}`}\n aria-controls=\"dropdownPanel\"\n onClick={() => this.handlePanelToggle()}\n aria-label={this.dropdownLabel}\n type=\"button\"\n >\n {this.dropdownLabel && this.dropdownLabel}\n <hy-icon class=\"hy-dropdown__icon\" icon={\"hy-icon-caret-down\"} size={14} aria-hidden=\"true\" />\n </button>\n <hy-dropdown-panel checkbox-checked={this.isChecked ? \"true\" : \"false\"} is-hidden={!this.isPanelOpen}>\n {this._dropdownOptions.map(({id, label, value}, index) => (\n <hy-dropdown-panel-item\n dropdown-item-id={id}\n dropdown-item-label={label}\n dropdown-item-value={value}\n is-last={this._dropdownOptions.length - 1 === index}\n />\n ))}\n </hy-dropdown-panel>\n </Host>\n );\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"hy-dropdown.js","sourceRoot":"","sources":["../../../src/components/hy-dropdown/hy-dropdown.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAgB,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAC,MAAM,eAAe,CAAC;AAC3G,OAAO,EAAC,gBAAgB,EAAC,MAAM,2BAA2B,CAAC;AAmB3D,MAAM,OAAO,UAAU;;kBAGK,KAAK;yBACC,IAAI;sBACP,gBAAgB;;wBAEd,KAAK;gBACb,IAAI;yBAC6B,IAAI;uBAC5B,KAAK;qBACP,KAAK;yBACM,CAAC,EAAC,EAAE,EAAE,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,YAAY,EAAE,KAAK,EAAE,CAAC,EAAC,CAAC;;8BAGhD,CAAC;;EA2BvC,KAAK,CAAC,iBAAiB;IACrB,IAAI,CAAC,gBAAgB,GAAG,MAAM,gBAAgB,CAAC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AAC,yBAAyB,EAAC,IAAI,EAAE,cAAc,EAAE,IAAI,EAAE,EAAE,iBAAc,MAAM,GAAG,CACzF,CACJ,CACN,CAAC,CACC,CACA,CACR,CAAC;KACH;EACH,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACF","sourcesContent":["import {Component, Element, Host, Listen, Event, EventEmitter, h, State, Prop, Watch} from \"@stencil/core\";\nimport {jsonParserWorker} from \"../../global/globalScript\";\n\nexport interface IDropdownItem {\n id: string | number;\n label: string;\n value: string | number;\n}\n\nexport interface DefaultValue {\n id: string | number;\n label: string;\n value: string | number;\n}\n\n@Component({\n tag: \"hy-dropdown\",\n styleUrl: \"hy-dropdown.scss\",\n shadow: false,\n})\nexport class HyDropdown {\n private _dropdownOptions: IDropdownItem[];\n @Element() el: HTMLElement;\n @Prop() single: boolean = false;\n @Prop() dropdownLabel: string = null;\n @Prop() dropdownId: string = \"dropdownToggle\";\n @Prop() dropdownOptions: IDropdownItem[] | string;\n @Prop() defaultLabel: string = \"All\";\n @Prop() type: string = null;\n @Prop({mutable: true}) defaultOption: string | number = null;\n @State() isPanelOpen: boolean = false;\n @State() isChecked: boolean = false;\n @State() currentSingle: DefaultValue[] = [{id: 0, label: this.defaultLabel, value: 0}];\n @State() currentMulti: IDropdownItem[];\n\n @State() focusedOptionIndex: number = 0;\n\n @Event({\n eventName: `dropdownPanelToggled`,\n composed: true,\n bubbles: true,\n })\n dropdownPanelToggled: EventEmitter;\n\n @Event({\n eventName: `dropdownValueChanged`,\n composed: true,\n })\n dropdropValueChange: EventEmitter;\n\n @Event({\n eventName: `dropdownMultiValueChanged`,\n composed: true,\n })\n dropdropMultiValueChange: EventEmitter;\n\n @Event({\n eventName: `dropdownKeyPress`,\n composed: true,\n })\n dropdownKeyPress: EventEmitter;\n\n async componentWillLoad() {\n this._dropdownOptions = await jsonParserWorker(this.dropdownOptions);\n }\n\n componentWillUpdate() {\n const items = this.el.querySelectorAll(\".hy-dropdown__checkbox\") as any;\n if (items) {\n if ([...items].some((item) => item.checked == true)) {\n this.isChecked = true;\n } else {\n this.isChecked = false;\n }\n }\n }\n\n @Watch(\"defaultOption\")\n watchPropHandler(newValue: string | number, oldValue: string | number) {\n if (!this.single) return;\n\n if (newValue !== oldValue) {\n const dropdownPanelCheckboxElements = this.el.getElementsByClassName(\"hy-dropdown__checkbox\") as HTMLCollectionOf<\n HTMLInputElement\n >;\n\n Array.from(dropdownPanelCheckboxElements).filter((item) => {\n if (item.id == newValue) {\n item.checked = true;\n this.currentSingle = this._dropdownOptions.filter((option) => option.id == newValue) as any;\n return;\n }\n return null;\n });\n }\n }\n\n @Listen(\"dropdownPanelToggled\", {target: \"window\"})\n panelListener(e) {\n if (this.isPanelOpen && e.detail.dropdownId !== this.dropdownId) {\n this.isPanelOpen = false;\n }\n }\n\n private handleMultiClick(event, option) {\n event.stopPropagation();\n const dropdownPanelCheckboxElements = this.el.getElementsByClassName(\"hy-dropdown__checkbox\") as HTMLCollectionOf<\n HTMLInputElement\n >;\n Array.from(dropdownPanelCheckboxElements).filter((i) => {\n const item = i.closest(\"li\");\n if (item.dataset.id == option.id && !item.hasAttribute(\"aria-selected\")) {\n item.setAttribute(\"aria-selected\", \"true\");\n this.currentMulti =\n this.currentMulti && this.currentMulti.length > 0 ? [...this.currentMulti, option] : [option];\n return;\n }\n if (item.dataset.id === option.id && item.hasAttribute(\"aria-selected\")) {\n item.removeAttribute(\"aria-selected\");\n if (this.currentMulti.length > 0) {\n const index = this.currentMulti.indexOf(option);\n this.currentMulti = this.currentMulti.splice(index, 1);\n }\n return;\n }\n return null;\n });\n }\n\n private handleSingleClick(event, option) {\n if (!this.single || !this.isPanelOpen) return;\n const dropdownPanelCheckboxElements = this.el.getElementsByClassName(\"hy-dropdown__checkbox\") as HTMLCollectionOf<\n HTMLInputElement\n >;\n event.stopPropagation();\n\n Array.from(dropdownPanelCheckboxElements).filter((i) => {\n const item = i.closest(\"li\");\n if (item.dataset.id == option.id) {\n if (item.hasAttribute(\"aria-selected\")) {\n item.removeAttribute(\"aria-selected\");\n this.currentSingle = [{id: null, label: this.defaultLabel, value: null}];\n return;\n }\n item.setAttribute(\"aria-selected\", \"true\");\n this.currentSingle = this._dropdownOptions.filter((o) => o.id == option.id) as any;\n return;\n }\n if (item.dataset.id !== option.id && item.hasAttribute(\"aria-selected\")) {\n item.removeAttribute(\"aria-selected\");\n return;\n }\n return null;\n });\n }\n\n @Listen(\"keydown\", {capture: false})\n handleKeyDown(event: KeyboardEvent) {\n event.stopPropagation();\n switch (event.key) {\n case \"ArrowDown\":\n event.preventDefault();\n if (!this.isPanelOpen) {\n this.handlePanelToggle(event);\n return;\n }\n this.focusedOptionIndex = (this.focusedOptionIndex + 1) % this._dropdownOptions.length;\n break;\n case \"ArrowUp\":\n this.focusedOptionIndex =\n (this.focusedOptionIndex - 1 + this._dropdownOptions.length) % this._dropdownOptions.length;\n event.preventDefault();\n break;\n case \"Enter\":\n case \" \":\n if (!this.isPanelOpen) {\n event.preventDefault();\n this.handlePanelToggle(event);\n return;\n }\n if (this.single) {\n this.handleOptionSingleClick(event, this._dropdownOptions[this.focusedOptionIndex]);\n } else {\n this.handleMultiOptionClick(event, this._dropdownOptions[this.focusedOptionIndex]);\n }\n const emitDetails = {\n id: this.dropdownId,\n type: this.type,\n data: this._dropdownOptions[this.focusedOptionIndex],\n };\n this.dropdownKeyPress.emit(emitDetails);\n event.preventDefault();\n break;\n case \"Escape\":\n case \"Tab\":\n this.isPanelOpen = false;\n break;\n default:\n break;\n }\n }\n\n private handlePanelToggle(e) {\n e.stopPropagation();\n this.isPanelOpen = !this.isPanelOpen;\n\n const emitDetails = {\n dropdownId: this.dropdownId,\n panelOpen: this.isPanelOpen,\n };\n this.dropdownPanelToggled.emit(emitDetails);\n }\n\n @Listen(\"click\", {target: \"window\"})\n handlePanelClickOutside(e) {\n e.stopPropagation();\n const dropdownToggleButtonElement = this.el.querySelector(`#${this.dropdownId}`) as HTMLButtonElement;\n const dropdownPanelElement = this.el.querySelector(\".hy-dropdown__panel\") as HTMLElement;\n const dropdownPanelCheckboxElements = this.el.querySelectorAll(\".hy-dropdown__panel-item\");\n const dropdownPanelCheckboxes = this.el.querySelectorAll(\".hy-dropdown__checkbox\");\n const dropdownToggleButtonIconElement = this.el.querySelectorAll(\".hy-dropdown__icon\");\n\n const {target} = e;\n\n const allowedElements = [\n this.el,\n dropdownToggleButtonElement,\n dropdownPanelElement,\n ...dropdownPanelCheckboxes,\n dropdownToggleButtonIconElement,\n ...dropdownPanelCheckboxElements, // Spread (\"copy\") items to allowedElement array.\n ];\n\n if (this.isPanelOpen && !allowedElements.includes(target)) {\n this.isPanelOpen = false;\n }\n }\n\n private handleOptionSingleClick(event, option) {\n event.stopPropagation();\n this.handleSingleClick(event, option);\n const emitDetails = {\n id: this.dropdownId,\n type: this.type,\n data: option,\n };\n this.dropdropValueChange.emit(emitDetails);\n }\n\n private handleMultiOptionClick(event, option) {\n event.stopPropagation();\n this.handleMultiClick(event, option);\n const emitDetails = {\n id: this.dropdownId,\n type: this.type,\n data: this.currentMulti,\n };\n this.dropdropMultiValueChange.emit(emitDetails);\n }\n\n private handleOptionHover(index) {\n this.focusedOptionIndex = index;\n }\n\n render() {\n const {label: currentLabel, id: currentId, value: currentValue} = this.currentSingle[0];\n const classAttributes = [\"hy-dropdown\", this.single ? \"hy-dropdown--single\" : \"\"].join(\" \");\n if (this.single) {\n return (\n <Host class={classAttributes}>\n {this.dropdownLabel && (\n <label class=\"hy-dropdown__button-label\" htmlFor={this.dropdownId}>\n {this.dropdownLabel}\n </label>\n )}\n <div\n id={this.dropdownId}\n class={`hy-dropdown__toggle ${this.isPanelOpen ? \"is-open\" : \"\"}`}\n aria-expanded={`${this.isPanelOpen || false}`}\n aria-controls=\"dropdownPanel\"\n aria-haspopup=\"listbox\"\n role=\"combobox\"\n onClick={(event) => this.handlePanelToggle(event)}\n onKeyDown={(event) => this.handleKeyDown(event)}\n aria-label={this.dropdownLabel}\n data-current-id={currentId}\n data-current-value={currentValue}\n data-value={currentId}\n tabIndex={0}\n >\n <input aria-hidden=\"true\" class=\"hy-dropdown__hidden-input\" type=\"hidden\" value={currentId}></input>\n {currentLabel}\n <hy-icon class=\"hy-dropdown__icon\" icon={\"hy-icon-caret-down\"} size={14} aria-hidden=\"true\" />\n </div>\n <ul\n checkbox-checked={this.isChecked ? \"true\" : \"false\"}\n id=\"dropdownPanel\"\n class={`hy-dropdown__panel ${!this.isPanelOpen ? \"is-hidden\" : \"\"}`}\n aria-expanded={`${!this.isPanelOpen || false}`}\n role=\"listbox\"\n aria-labelledby=\"dropdownToggle\"\n >\n {this._dropdownOptions.map(({id, label, value}, index, items) => (\n <li\n key={id}\n data-id={`${id}`}\n role=\"option\"\n class={`hy-dropdown__panel-item ${this._dropdownOptions.length - 1 === index ? \"is-last\" : \"\"}\n ${this.focusedOptionIndex === index ? \"hy-dropdown__panel-item--focused\" : \"\"}`}\n onClick={(event) => this.handleOptionSingleClick(event, items[index])}\n onMouseEnter={() => this.handleOptionHover(index)}\n >\n <span data-id={`${id}`} class=\"hy-dropdown__checkbox\" data-value={`${value}`}>\n {label}\n <hy-icon class=\"hy-dropdown__label-icon\" icon={\"hy-icon-done\"} size={14} aria-hidden=\"true\" />\n </span>\n </li>\n ))}\n </ul>\n </Host>\n );\n } else {\n return (\n <Host class={classAttributes}>\n <button\n id={this.dropdownId}\n class={`hy-dropdown__toggle ${this.isPanelOpen ? \"is-open\" : \"\"}`}\n aria-expanded={`${this.isPanelOpen || false}`}\n aria-controls=\"dropdownPanel\"\n aria-haspopup=\"listbox\"\n role=\"combobox\"\n onClick={(event) => this.handlePanelToggle(event)}\n aria-label={this.dropdownLabel}\n type=\"button\"\n >\n {this.dropdownLabel && this.dropdownLabel}\n <hy-icon class=\"hy-dropdown__icon\" icon={\"hy-icon-caret-down\"} size={14} aria-hidden=\"true\" />\n </button>\n <ul\n checkbox-checked={this.isChecked ? \"true\" : \"false\"}\n id=\"dropdownPanel\"\n class={`hy-dropdown__panel ${!this.isPanelOpen ? \"is-hidden\" : \"\"}`}\n aria-expanded={`${!this.isPanelOpen || false}`}\n role=\"listbox\"\n aria-labelledby=\"dropdownToggle\"\n >\n {this._dropdownOptions.map(({id, label, value}, index, items) => (\n <li\n key={id}\n data-id={`${id}`}\n role=\"option\"\n class={`hy-dropdown__panel-item ${this._dropdownOptions.length - 1 === index ? \"is-last\" : \"\"}\n ${this.focusedOptionIndex === index ? \"hy-dropdown__panel-item--focused\" : \"\"}`}\n onClick={(event) => this.handleMultiOptionClick(event, items[index])}\n onMouseEnter={() => this.handleOptionHover(index)}\n >\n <span data-id={`${id}`} class=\"hy-dropdown__checkbox\" data-value={`${value}`}>\n {label}\n <hy-icon class=\"hy-dropdown__label-icon\" icon={\"hy-icon-done\"} size={14} aria-hidden=\"true\" />\n </span>\n </li>\n ))}\n </ul>\n </Host>\n );\n }\n }\n}\n"]}
|