@oslokommune/punkt-elements 15.4.5 → 16.0.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.
- package/CHANGELOG.md +34 -0
- package/dist/{card-CnPjrdre.js → card-CmfUyl_s.js} +1 -1
- package/dist/{card-5S2r9UD1.cjs → card-Db9QSEqh.cjs} +1 -1
- package/dist/{checkbox-D98_NjcU.cjs → checkbox-Cpyay9_l.cjs} +1 -1
- package/dist/{checkbox-BSz71IeT.js → checkbox-D6nltMuc.js} +1 -1
- package/dist/combobox-Bv37b6cI.cjs +135 -0
- package/dist/combobox-CoO8T-F-.js +818 -0
- package/dist/{datepicker-SEKblnRR.cjs → datepicker-CrvQ5Y5w.cjs} +1 -1
- package/dist/{datepicker-nnyTW0vf.js → datepicker-DbsIuC5Z.js} +2 -2
- package/dist/index.d.ts +157 -90
- package/dist/{input-element-Bkv6Yxld.js → input-element-BGNbdzy2.js} +1 -1
- package/dist/{input-element-DM0tY799.cjs → input-element-CSDVA3Y6.cjs} +1 -1
- package/dist/listbox-Dm2mKp6_.cjs +101 -0
- package/dist/listbox-OdkIn9_A.js +431 -0
- package/dist/pkt-card.cjs +1 -1
- package/dist/pkt-card.js +1 -1
- package/dist/pkt-checkbox.cjs +1 -1
- package/dist/pkt-checkbox.js +1 -1
- package/dist/pkt-combobox.cjs +1 -1
- package/dist/pkt-combobox.js +1 -1
- package/dist/pkt-datepicker.cjs +1 -1
- package/dist/pkt-datepicker.js +2 -2
- package/dist/pkt-header.cjs +1 -1
- package/dist/pkt-header.js +1 -1
- package/dist/pkt-index.cjs +1 -1
- package/dist/pkt-index.js +9 -9
- package/dist/pkt-listbox.cjs +1 -1
- package/dist/pkt-listbox.js +1 -1
- package/dist/pkt-options-controller-BogGk-6J.cjs +1 -0
- package/dist/{pkt-options-controller-BcGywCmf.js → pkt-options-controller-Z-bPox7n.js} +2 -2
- package/dist/pkt-radiobutton.cjs +1 -1
- package/dist/pkt-radiobutton.js +1 -1
- package/dist/pkt-select.cjs +1 -1
- package/dist/pkt-select.js +1 -1
- package/dist/pkt-tag.cjs +1 -1
- package/dist/pkt-tag.js +1 -1
- package/dist/pkt-textarea.cjs +1 -1
- package/dist/pkt-textarea.js +1 -1
- package/dist/pkt-textinput.cjs +1 -1
- package/dist/pkt-textinput.js +1 -1
- package/dist/{radiobutton-95wp024h.cjs → radiobutton-CNHCpKn0.cjs} +1 -1
- package/dist/{radiobutton-CTFAV5GU.js → radiobutton-DgC27mb0.js} +1 -1
- package/dist/{select-YLvYAQX6.js → select-7VuYtPZv.js} +2 -2
- package/dist/{select-CZ_Lx5W6.cjs → select-PWPy5gTB.cjs} +1 -1
- package/dist/{tag-68q0_Sn0.js → tag-DZPqFiem.js} +37 -33
- package/dist/tag-DmbgBCKu.cjs +27 -0
- package/dist/{textarea-CuTsE1WX.cjs → textarea-CO7Ikug5.cjs} +1 -1
- package/dist/{textarea-DhWH99qN.js → textarea-VpCEjVFx.js} +1 -1
- package/dist/{textinput-BCi9p0Du.js → textinput-C2AZ9ss2.js} +1 -1
- package/dist/{textinput-st4Vml5J.cjs → textinput-DRFZU3dA.cjs} +1 -1
- package/package.json +4 -4
- package/src/components/card/card.ts +1 -0
- package/src/components/combobox/combobox-base.ts +158 -0
- package/src/components/combobox/combobox-handlers.ts +419 -0
- package/src/components/combobox/combobox-types.ts +10 -0
- package/src/components/combobox/combobox-utils.ts +135 -0
- package/src/components/combobox/combobox-value.ts +248 -0
- package/src/components/combobox/combobox.accessibility.test.ts +243 -0
- package/src/components/combobox/{combobox.test.ts → combobox.core.test.ts} +104 -46
- package/src/components/combobox/combobox.interaction.test.ts +436 -0
- package/src/components/combobox/combobox.selection.test.ts +543 -0
- package/src/components/combobox/combobox.ts +260 -734
- package/src/components/listbox/index.ts +2 -0
- package/src/components/listbox/listbox.interaction.test.ts +580 -0
- package/src/components/listbox/listbox.test.ts +32 -6
- package/src/components/listbox/listbox.ts +109 -126
- package/src/components/tag/tag.ts +3 -0
- package/dist/combobox-C5YcNVSZ.cjs +0 -128
- package/dist/combobox-cer7PLSE.js +0 -533
- package/dist/listbox-C7NEa9SU.cjs +0 -96
- package/dist/listbox-Cykec1bj.js +0 -361
- package/dist/pkt-options-controller-BnTmkl3g.cjs +0 -1
- package/dist/tag-BnT5onW2.cjs +0 -26
|
@@ -1,533 +0,0 @@
|
|
|
1
|
-
import { A as I, b as d, n as r, t as w } from "./element-CV9utnHJ.js";
|
|
2
|
-
import { o as v } from "./if-defined-rXcLNTzN.js";
|
|
3
|
-
import { r as c } from "./state-l4hGZdFJ.js";
|
|
4
|
-
import { e as f, n as _ } from "./ref-Dma3n3i8.js";
|
|
5
|
-
import { e as k } from "./class-map-3ADKve8g.js";
|
|
6
|
-
import { c as R } from "./repeat-DnlRNf63.js";
|
|
7
|
-
import { P as V } from "./input-element-Bkv6Yxld.js";
|
|
8
|
-
import { P as A } from "./pkt-options-controller-BcGywCmf.js";
|
|
9
|
-
import { P as C } from "./pkt-slot-controller-D7CrjM52.js";
|
|
10
|
-
import "./input-wrapper-CaUY90qz.js";
|
|
11
|
-
import "./icon-D0IQAVwS.js";
|
|
12
|
-
import "./tag-68q0_Sn0.js";
|
|
13
|
-
import "./listbox-Cykec1bj.js";
|
|
14
|
-
const S = { displayValueAs: { default: "label" } }, T = {
|
|
15
|
-
props: S
|
|
16
|
-
};
|
|
17
|
-
var M = Object.defineProperty, P = Object.getOwnPropertyDescriptor, n = (t, e, i, s) => {
|
|
18
|
-
for (var a = s > 1 ? void 0 : s ? P(e, i) : e, l = t.length - 1, h; l >= 0; l--)
|
|
19
|
-
(h = t[l]) && (a = (s ? h(e, i, a) : h(a)) || a);
|
|
20
|
-
return s && a && M(e, i, a), a;
|
|
21
|
-
};
|
|
22
|
-
let o = class extends V {
|
|
23
|
-
constructor() {
|
|
24
|
-
super(), this.helptextSlot = f(), this.value = "", this.options = [], this.defaultOptions = [], this.allowUserInput = !1, this.typeahead = !1, this.includeSearch = !1, this.searchPlaceholder = "", this.multiple = !1, this.maxlength = null, this.displayValueAs = T.props.displayValueAs.default, this.tagPlacement = null, this._options = [], this._value = [], this._isOptionsOpen = !1, this._userInfoMessage = "", this._addValueText = null, this._maxIsReached = !1, this._search = "", this._inputFocus = !1, this._editingSingleValue = !1, this.inputRef = f(), this.arrowRef = f(), this.listboxRef = f(), this.focusRef = f(), this.optionTagRef = f(), this.optionsController = new A(this), this.slotController = new C(this, this.helptextSlot), this.slotController.skipOptions = !0;
|
|
25
|
-
}
|
|
26
|
-
// Lifecycle methods
|
|
27
|
-
connectedCallback() {
|
|
28
|
-
var t, e;
|
|
29
|
-
if (super.connectedCallback(), document && document.body.addEventListener("click", (i) => {
|
|
30
|
-
this._isOptionsOpen && !this.contains(i.target) && this.handleFocusOut(i);
|
|
31
|
-
}), this._options = [], this.defaultOptions && this.defaultOptions.length) {
|
|
32
|
-
const i = ((t = this.options) == null ? void 0 : t.filter((s) => s.userAdded)) || [];
|
|
33
|
-
this.options = [...i, ...JSON.parse(JSON.stringify(this.defaultOptions))], this._options = Array.isArray(this.options) ? [...this.options] : [];
|
|
34
|
-
}
|
|
35
|
-
if ((e = this.optionsController) != null && e.nodes && this.optionsController.nodes.length) {
|
|
36
|
-
const i = [];
|
|
37
|
-
this.optionsController.nodes.forEach((s) => {
|
|
38
|
-
if (!s.textContent && !s.getAttribute("value")) return null;
|
|
39
|
-
const a = {
|
|
40
|
-
value: s.getAttribute("value") || s.textContent || "",
|
|
41
|
-
label: s.textContent || s.getAttribute("value") || ""
|
|
42
|
-
};
|
|
43
|
-
s.getAttribute("data-prefix") && (a.prefix = s.getAttribute("data-prefix") || void 0), s.getAttribute("tagskincolor") && (a.tagSkinColor = s.getAttribute("tagskincolor")), s.getAttribute("description") && (a.description = s.getAttribute("description") || void 0), a.fulltext = a.value + a.label + (a.prefix || ""), i.push(a);
|
|
44
|
-
}), i.length && (this.options = [...i], this._options = [...i]);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
updated(t) {
|
|
48
|
-
if (t.has("_value") && this.valueChanged(this._value, t.get("_value")), t.has("value") && (Array.isArray(this.value) ? this._value = this.value : this.value && this.multiple ? this._value = this.value.split(",") : this.value ? this._value = [this.value] : this._value = [], !this.multiple && this._value.length > 1 && (this._value = [this._value[0]]), this.isMaxItemsReached()), t.has("defaultOptions") && this.defaultOptions.length) {
|
|
49
|
-
const e = (Array.isArray(this.options) ? this.options : []).filter((i) => i.userAdded) || [];
|
|
50
|
-
this.options = [...e, ...JSON.parse(JSON.stringify(this.defaultOptions))], this._options = Array.isArray(this.options) ? [...this.options] : [];
|
|
51
|
-
}
|
|
52
|
-
if (t.has("options")) {
|
|
53
|
-
const s = (t.get("options") || this._options || []).filter((l) => l && l.userAdded).filter(
|
|
54
|
-
(l) => !(Array.isArray(this.options) ? this.options : []).some(
|
|
55
|
-
(h) => h.value === l.value
|
|
56
|
-
)
|
|
57
|
-
), a = [...s, ...this.options];
|
|
58
|
-
this._options = a, s.length > 0 && (this.options = a), this._options.forEach((l) => {
|
|
59
|
-
if (l.value && !l.label && (l.label = l.value), l.selected && !this._value.includes(l.value)) {
|
|
60
|
-
const h = [...this._value];
|
|
61
|
-
this._value = [...this._value, l.value], this.valueChanged(this._value, h);
|
|
62
|
-
}
|
|
63
|
-
l.fulltext = l.value + l.label + (l.prefix || ""), l.selected = l.selected || this._value.includes(l.value);
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
t.has("_search") && this.dispatchEvent(
|
|
67
|
-
new CustomEvent("search", {
|
|
68
|
-
detail: this._search,
|
|
69
|
-
bubbles: !1
|
|
70
|
-
})
|
|
71
|
-
), super.updated(t);
|
|
72
|
-
}
|
|
73
|
-
attributeChangedCallback(t, e, i) {
|
|
74
|
-
t === "value" && (Array.isArray(this.value) ? this._value = this.value : this.value && this.multiple ? this._value = this.value.split(",") : this.value ? this._value = [this.value] : this._value = [], !this.multiple && this._value.length > 1 && (this._value = [this._value[0]])), t === "options" && (this._options = Array.isArray(this.options) ? [...this.options] : [], this._options.forEach((s) => {
|
|
75
|
-
s.value && !s.label && (s.label = s.value), s.selected && !this._value.includes(s.value) && (this._value = [...this._value, s.value]), s.fulltext = s.value + s.label + (s.prefix || "");
|
|
76
|
-
}), this._search = ""), super.attributeChangedCallback(t, e, i);
|
|
77
|
-
}
|
|
78
|
-
// Render methods
|
|
79
|
-
render() {
|
|
80
|
-
return d`
|
|
81
|
-
<pkt-input-wrapper
|
|
82
|
-
.label=${this.label}
|
|
83
|
-
.helptext=${this.helptext}
|
|
84
|
-
.helptextDropdown=${v(this.helptextDropdown)}
|
|
85
|
-
.helptextDropdownButton=${v(this.helptextDropdownButton)}
|
|
86
|
-
?fullwidth=${this.fullwidth}
|
|
87
|
-
?hasError=${this.hasError}
|
|
88
|
-
?inline=${this.inline}
|
|
89
|
-
?disabled=${this.disabled}
|
|
90
|
-
.errorMessage=${this.errorMessage}
|
|
91
|
-
?optionalTag=${this.optionalTag}
|
|
92
|
-
.optionalText=${this.optionalText}
|
|
93
|
-
?requiredTag=${this.requiredTag}
|
|
94
|
-
.requiredText=${this.requiredText}
|
|
95
|
-
.tagText=${this.tagText}
|
|
96
|
-
useWrapper=${this.useWrapper}
|
|
97
|
-
.forId=${this.allowUserInput || this.typeahead ? this.id + "-input" : this.id + "-arrow"}
|
|
98
|
-
class="pkt-combobox__wrapper"
|
|
99
|
-
@labelClick=${this.handleInputClick}
|
|
100
|
-
>
|
|
101
|
-
<div class="pkt-contents" ${_(this.helptextSlot)} name="helptext" slot="helptext"></div>
|
|
102
|
-
<div class="pkt-combobox" @focusout=${this.handleFocusOut}>
|
|
103
|
-
<div
|
|
104
|
-
class=${k({
|
|
105
|
-
"pkt-combobox__input": !0,
|
|
106
|
-
"pkt-combobox__input--fullwidth": this.fullwidth,
|
|
107
|
-
"pkt-combobox__input--open": this._isOptionsOpen,
|
|
108
|
-
"pkt-combobox__input--error": this.hasError,
|
|
109
|
-
"pkt-combobox__input--disabled": this.disabled
|
|
110
|
-
})}
|
|
111
|
-
tabindex="-1"
|
|
112
|
-
@click=${this.handleInputClick}
|
|
113
|
-
>
|
|
114
|
-
${this.placeholder && (!this._value.length || this.multiple && this.tagPlacement == "outside") && !this._inputFocus ? d`<span class="pkt-combobox__placeholder" @click=${this.handlePlaceholderClick}
|
|
115
|
-
>${this.placeholder}</span
|
|
116
|
-
>` : this.tagPlacement !== "outside" ? this.renderSingleOrMultipleValues() : I}
|
|
117
|
-
${this.renderInputField()}
|
|
118
|
-
<div
|
|
119
|
-
class="pkt-btn pkt-btn--tertiary pkt-combobox__arrow"
|
|
120
|
-
@click=${this.handleArrowClick}
|
|
121
|
-
@keydown=${this.handleArrowClick}
|
|
122
|
-
id="${this.id}-arrow"
|
|
123
|
-
${_(this.arrowRef)}
|
|
124
|
-
aria-expanded=${this._isOptionsOpen}
|
|
125
|
-
aria-controls="${this.id}-listbox"
|
|
126
|
-
aria-haspopup="listbox"
|
|
127
|
-
aria-label="Åpne liste"
|
|
128
|
-
?disabled=${this.disabled}
|
|
129
|
-
?data-disabled=${this.disabled}
|
|
130
|
-
role="button"
|
|
131
|
-
tabindex="${this.disabled ? "-1" : "0"}"
|
|
132
|
-
>
|
|
133
|
-
<pkt-icon
|
|
134
|
-
class=${k({
|
|
135
|
-
"pkt-combobox__arrow-icon": !0,
|
|
136
|
-
"pkt-combobox__arrow-icon--open": this._isOptionsOpen
|
|
137
|
-
})}
|
|
138
|
-
name="chevron-thin-down"
|
|
139
|
-
></pkt-icon>
|
|
140
|
-
</div>
|
|
141
|
-
<div
|
|
142
|
-
${_(this.focusRef)}
|
|
143
|
-
tabindex="-1"
|
|
144
|
-
@keydown=${this.handleArrowClick}
|
|
145
|
-
class="pkt-contents"
|
|
146
|
-
></div>
|
|
147
|
-
</div>
|
|
148
|
-
|
|
149
|
-
<pkt-listbox
|
|
150
|
-
id="${this.id}-listbox"
|
|
151
|
-
.options=${this._options}
|
|
152
|
-
.isOpen=${this._isOptionsOpen}
|
|
153
|
-
.searchPlaceholder=${this.searchPlaceholder}
|
|
154
|
-
.label="Liste: ${this.label || ""}"
|
|
155
|
-
?includeSearch=${this.includeSearch}
|
|
156
|
-
?isMultiSelect=${this.multiple}
|
|
157
|
-
?allowUserInput=${this.allowUserInput && !this._maxIsReached}
|
|
158
|
-
?maxIsReached=${this._maxIsReached}
|
|
159
|
-
.customUserInput=${v(this._addValueText)}
|
|
160
|
-
.userMessage=${this._userInfoMessage}
|
|
161
|
-
@search=${this.handleSearch}
|
|
162
|
-
@option-toggle=${this.handleOptionToggled}
|
|
163
|
-
@select-all=${this.addAllOptions}
|
|
164
|
-
@close-options=${() => this._isOptionsOpen = !1}
|
|
165
|
-
.searchValue=${this._search || null}
|
|
166
|
-
.maxLength=${this.maxlength || 0}
|
|
167
|
-
${_(this.listboxRef)}
|
|
168
|
-
></pkt-listbox>
|
|
169
|
-
</div>
|
|
170
|
-
|
|
171
|
-
${this.tagPlacement === "outside" && this.multiple ? d`<div class="pkt-combobox__tags-outside">
|
|
172
|
-
${this.renderSingleOrMultipleValues()}
|
|
173
|
-
</div>` : I}
|
|
174
|
-
</pkt-input-wrapper>
|
|
175
|
-
`;
|
|
176
|
-
}
|
|
177
|
-
renderInputField() {
|
|
178
|
-
return this.typeahead || this.allowUserInput ? d`
|
|
179
|
-
<div class="pkt-combobox__input-div combobox__input">
|
|
180
|
-
<input
|
|
181
|
-
type="text"
|
|
182
|
-
id="${this.id}-input"
|
|
183
|
-
name=${(this.name || this.id) + "-input"}
|
|
184
|
-
@input=${this.handleInput}
|
|
185
|
-
@keydown=${this.handleInputKeydown}
|
|
186
|
-
@focus=${this.handleFocus}
|
|
187
|
-
@blur=${this.handleBlur}
|
|
188
|
-
autocomplete="off"
|
|
189
|
-
role="combobox"
|
|
190
|
-
aria-label=${v(this.label)}
|
|
191
|
-
aria-autocomplete=${this.typeahead ? "both" : "list"}
|
|
192
|
-
aria-controls="${this.id}-listbox"
|
|
193
|
-
aria-activedescendant=${v(
|
|
194
|
-
this._value[0] && this.findValueInOptions(this._value[0]) ? `${this.id}-listbox-${this.findIndexInOptions(this._value[0])}` : void 0
|
|
195
|
-
)}
|
|
196
|
-
${_(this.inputRef)}
|
|
197
|
-
/>
|
|
198
|
-
</div>
|
|
199
|
-
` : d`
|
|
200
|
-
<input
|
|
201
|
-
type="hidden"
|
|
202
|
-
id="${this.id}-input"
|
|
203
|
-
name=${(this.name || this.id) + "-input"}
|
|
204
|
-
.value=${this._value.join(",")}
|
|
205
|
-
${_(this.inputRef)}
|
|
206
|
-
/>
|
|
207
|
-
`;
|
|
208
|
-
}
|
|
209
|
-
renderSingleOrMultipleValues() {
|
|
210
|
-
const t = !this.multiple, e = this._editingSingleValue ? null : this.renderValueTag(this.findValueInOptions(this._value[0])), i = R(
|
|
211
|
-
this._value,
|
|
212
|
-
(s) => s,
|
|
213
|
-
(s) => {
|
|
214
|
-
var h;
|
|
215
|
-
const a = this.findValueInOptions(s), l = (h = this.options.find((u) => u.value === s)) == null ? void 0 : h.tagSkinColor;
|
|
216
|
-
return d`
|
|
217
|
-
<pkt-tag
|
|
218
|
-
skin=${l || "blue-dark"}
|
|
219
|
-
?closeTag=${!this.disabled}
|
|
220
|
-
@close=${() => this.handleTagRemove(s)}
|
|
221
|
-
>
|
|
222
|
-
${this.renderValueTag(a)}
|
|
223
|
-
</pkt-tag>
|
|
224
|
-
`;
|
|
225
|
-
}
|
|
226
|
-
);
|
|
227
|
-
return t ? e : i;
|
|
228
|
-
}
|
|
229
|
-
renderValueTag(t) {
|
|
230
|
-
if (!t) return "";
|
|
231
|
-
switch (this.displayValueAs) {
|
|
232
|
-
case "prefixAndValue":
|
|
233
|
-
return d`<span class="pkt-combobox__value" data-focusfix=${this.id}
|
|
234
|
-
>${t.prefix || ""} ${t.value}</span
|
|
235
|
-
>`;
|
|
236
|
-
case "value":
|
|
237
|
-
return d`<span class="pkt-combobox__value" data-focusfix=${this.id}
|
|
238
|
-
>${t.value}</span
|
|
239
|
-
>`;
|
|
240
|
-
case "label":
|
|
241
|
-
default:
|
|
242
|
-
return d`<span class="pkt-combobox__value" data-focusfix=${this.id}
|
|
243
|
-
>${t.label || t.value}</span
|
|
244
|
-
>`;
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
// Event handlers
|
|
248
|
-
handleInput(t) {
|
|
249
|
-
if (t.stopPropagation(), t.stopImmediatePropagation(), this.disabled) return;
|
|
250
|
-
this.touched = !0;
|
|
251
|
-
const e = t.target;
|
|
252
|
-
if (this._search = e.value, this.checkForMatches(), this.typeahead)
|
|
253
|
-
if (this._search) {
|
|
254
|
-
if (this._options = this.options.filter(
|
|
255
|
-
(i) => {
|
|
256
|
-
var s;
|
|
257
|
-
return (s = i.fulltext) == null ? void 0 : s.toLowerCase().includes(this._search.toLowerCase());
|
|
258
|
-
}
|
|
259
|
-
), t.inputType !== "deleteContentBackward") {
|
|
260
|
-
const i = this._options.filter(
|
|
261
|
-
(s) => {
|
|
262
|
-
var a;
|
|
263
|
-
return !s.selected && ((a = s.label) == null ? void 0 : a.toLowerCase().startsWith(this._search.toLowerCase()));
|
|
264
|
-
}
|
|
265
|
-
);
|
|
266
|
-
if (i.length > 0 && this.inputRef.value && this.inputRef.value.type !== "hidden") {
|
|
267
|
-
const s = i[0];
|
|
268
|
-
s != null && s.label && (e.value = s.label, window.setTimeout(
|
|
269
|
-
() => e.setSelectionRange(this._search.length, e.value.length),
|
|
270
|
-
0
|
|
271
|
-
), e.selectionDirection = "backward");
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
} else
|
|
275
|
-
this._options = [...this.options];
|
|
276
|
-
}
|
|
277
|
-
handleFocus() {
|
|
278
|
-
if (!this.disabled) {
|
|
279
|
-
if (!this.multiple && this._value[0] && this.inputRef.value && this.inputRef.value.type !== "hidden") {
|
|
280
|
-
const t = this.findValueInOptions(this._value[0]);
|
|
281
|
-
this._editingSingleValue = !0, this.inputRef.value.value = this.displayValueAs === "label" && (t != null && t.label) ? t.label : this._value[0];
|
|
282
|
-
}
|
|
283
|
-
this._inputFocus = !0, this._search = "", this._options = [...this.options], this._isOptionsOpen = !0, this.onFocus(), this.requestUpdate();
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
handleFocusOut(t) {
|
|
287
|
-
var e, i, s, a, l;
|
|
288
|
-
if (!this.disabled && ((i = (e = t.relatedTarget) == null ? void 0 : e.closest("pkt-combobox")) == null ? void 0 : i.id) !== this.id && ((a = (s = t.relatedTarget) == null ? void 0 : s.closest("pkt-combobox")) == null ? void 0 : a.id) !== this.id && ((l = t.target) == null ? void 0 : l.getAttribute("data-focusfix")) !== this.id && t.relatedTarget !== this.focusRef.value && t.relatedTarget !== this.inputRef.value && t.relatedTarget !== this.arrowRef.value && this._isOptionsOpen) {
|
|
289
|
-
if (this._inputFocus = !1, this._addValueText = null, this._userInfoMessage = "", this._search = "", this.inputRef.value && this.inputRef.value.type !== "hidden" && this.inputRef.value.value !== "") {
|
|
290
|
-
const h = this.inputRef.value.value, u = this.findValueInOptions(h);
|
|
291
|
-
!this._value.includes(h) && !u ? this.allowUserInput ? this.addNewUserValue(h) : this.multiple || this.removeValue(this._value[0]) : u && !this._value.includes(u.value) && this.setSelected(u.value), this.inputRef.value.value = "";
|
|
292
|
-
}
|
|
293
|
-
this._isOptionsOpen = !1, this.onBlur();
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
handleBlur() {
|
|
297
|
-
this._inputFocus = !1, this._editingSingleValue = !1, this.onBlur();
|
|
298
|
-
}
|
|
299
|
-
handleInputClick(t) {
|
|
300
|
-
var e, i;
|
|
301
|
-
if (this.disabled) {
|
|
302
|
-
t.preventDefault(), t.stopImmediatePropagation();
|
|
303
|
-
return;
|
|
304
|
-
}
|
|
305
|
-
t.currentTarget && t.currentTarget !== this.arrowRef.value && ((e = this.inputRef.value) == null ? void 0 : e.type) !== "hidden" ? ((i = this.inputRef.value) == null || i.focus(), this.requestUpdate()) : this.handleArrowClick(t);
|
|
306
|
-
}
|
|
307
|
-
handlePlaceholderClick(t) {
|
|
308
|
-
this.disabled || (t.stopPropagation(), this.inputRef.value && this.inputRef.value.type !== "hidden" && (this.inputRef.value.focus(), this._inputFocus = !0, this.requestUpdate()));
|
|
309
|
-
}
|
|
310
|
-
handleArrowClick(t) {
|
|
311
|
-
var e, i;
|
|
312
|
-
this.disabled || t instanceof KeyboardEvent && t.key && t.key !== "Enter" && t.key !== " " && t.key !== "ArrowDown" || (t.stopImmediatePropagation(), t.preventDefault(), this._isOptionsOpen = !this._isOptionsOpen, this._isOptionsOpen ? (e = this.listboxRef.value) == null || e.focusFirstOrSelectedOption() : (i = this.arrowRef.value) == null || i.focus());
|
|
313
|
-
}
|
|
314
|
-
handleOptionToggled(t) {
|
|
315
|
-
this.toggleValue(t.detail);
|
|
316
|
-
}
|
|
317
|
-
handleSearch(t) {
|
|
318
|
-
t.stopPropagation(), this._search = t.detail.toLowerCase();
|
|
319
|
-
}
|
|
320
|
-
handleInputKeydown(t) {
|
|
321
|
-
var e, i, s;
|
|
322
|
-
switch (t.key) {
|
|
323
|
-
case ",":
|
|
324
|
-
this.multiple && (t.preventDefault(), this.addValue());
|
|
325
|
-
break;
|
|
326
|
-
case "Enter":
|
|
327
|
-
t.preventDefault(), this.addValue();
|
|
328
|
-
break;
|
|
329
|
-
case "Backspace":
|
|
330
|
-
!this._search && ((e = this.inputRef.value) == null ? void 0 : e.type) === "hidden" && this.removeLastValue(t);
|
|
331
|
-
break;
|
|
332
|
-
case "Tab":
|
|
333
|
-
case "ArrowDown":
|
|
334
|
-
t.shiftKey || ((i = this.listboxRef.value) == null || i.focusFirstOrSelectedOption(), t.preventDefault());
|
|
335
|
-
break;
|
|
336
|
-
case "Escape":
|
|
337
|
-
this._isOptionsOpen = !1, (s = this.arrowRef.value) == null || s.focus(), t.preventDefault();
|
|
338
|
-
break;
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
handleTagRemove(t) {
|
|
342
|
-
this.removeSelected(t);
|
|
343
|
-
}
|
|
344
|
-
blurInput() {
|
|
345
|
-
this.inputRef.value && this.inputRef.value.matches(":focus") && this.inputRef.value.blur();
|
|
346
|
-
}
|
|
347
|
-
checkForMatches() {
|
|
348
|
-
var l;
|
|
349
|
-
const t = ((l = this.inputRef.value) == null ? void 0 : l.value) || this._search || "", e = t.trim().toLowerCase() || "";
|
|
350
|
-
if (!e) {
|
|
351
|
-
!this.multiple && this._value[0] && this.removeValue(this._value[0]), this.resetComboboxInput(!1);
|
|
352
|
-
return;
|
|
353
|
-
}
|
|
354
|
-
const i = this._value.find((h) => h.toLowerCase() === e), s = this._options.filter(
|
|
355
|
-
(h) => {
|
|
356
|
-
var u;
|
|
357
|
-
return ((u = h.label) == null ? void 0 : u.toLowerCase().includes(e)) ?? !1;
|
|
358
|
-
}
|
|
359
|
-
), a = s.find(
|
|
360
|
-
(h) => {
|
|
361
|
-
var u;
|
|
362
|
-
return ((u = h.label) == null ? void 0 : u.toLowerCase()) === e || h.value.toLowerCase() === e;
|
|
363
|
-
}
|
|
364
|
-
);
|
|
365
|
-
switch (!0) {
|
|
366
|
-
case ((s.length === 0 || !a) && this.allowUserInput):
|
|
367
|
-
this._addValueText = t, this._userInfoMessage = "";
|
|
368
|
-
break;
|
|
369
|
-
case (s.length === 0 && !this._options.length && !this.allowUserInput):
|
|
370
|
-
this._addValueText = null, this._userInfoMessage = "Ingen match i søket";
|
|
371
|
-
break;
|
|
372
|
-
case !!i:
|
|
373
|
-
this._addValueText = null, this._userInfoMessage = "Verdien er allerede valgt";
|
|
374
|
-
break;
|
|
375
|
-
case s.length > 1:
|
|
376
|
-
this._addValueText = null, this._userInfoMessage = "";
|
|
377
|
-
break;
|
|
378
|
-
default:
|
|
379
|
-
this._addValueText = null, this._userInfoMessage = "";
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
findValueInOptions(t) {
|
|
383
|
-
return this.options.find((e) => e.value === t || e.label === t) || null;
|
|
384
|
-
}
|
|
385
|
-
findIndexInOptions(t) {
|
|
386
|
-
return this._options.findIndex((e) => e.value === t || e.label === t);
|
|
387
|
-
}
|
|
388
|
-
isMaxItemsReached() {
|
|
389
|
-
const t = this.maxlength !== null && this._value.length >= this.maxlength;
|
|
390
|
-
return t ? this._maxIsReached = !0 : this._maxIsReached = !1, t;
|
|
391
|
-
}
|
|
392
|
-
toggleValue(t) {
|
|
393
|
-
var O, $;
|
|
394
|
-
if (this.disabled) return;
|
|
395
|
-
this.touched = !0, this._userInfoMessage = "", this._addValueText = null;
|
|
396
|
-
const e = ((O = this.findValueInOptions(t)) == null ? void 0 : O.value) || null, i = this._value.includes(t || e || ""), s = !!e, a = (($ = this._options.find((m) => m.value === t)) == null ? void 0 : $.disabled) || !1, l = !(t != null && t.trim()), h = !this.multiple, u = this.multiple, y = this.isMaxItemsReached();
|
|
397
|
-
let p = !1, b = !0, g = "", x = "";
|
|
398
|
-
a || (!s && this.allowUserInput && !l ? (this.addNewUserValue(t), g = "Ny verdi lagt til", p = !u) : !s && !this.allowUserInput ? (h && this._value[0] && this.removeValue(this._value[0]), b = !1, p = !0, g = "Ingen treff i søket") : i ? (this.removeValue(e), p = !0) : l && h ? (this.removeAllSelected(), p = !0) : h ? (this._value[0] && this.removeSelected(this._value[0]), this.setSelected(e), p = !1, this.inputRef.value && this.inputRef.value.type !== "hidden" && (this.inputRef.value.value = "", this.inputRef.value.blur())) : u && !y ? (this.setSelected(e), p = !0) : u && y ? (this._userInfoMessage = "Maks antall valg nådd", b = !1, x = t) : (h && this.removeAllSelected(), this._userInfoMessage = "Ingen gyldig verdi valgt", b = !1, p = !0, x = t), this._isOptionsOpen = p, p || window.setTimeout(() => {
|
|
399
|
-
var m;
|
|
400
|
-
(m = this.focusRef.value) == null || m.focus();
|
|
401
|
-
}, 0), this._userInfoMessage = g, this._search = x || "", this.resetComboboxInput(b), u && this.isMaxItemsReached());
|
|
402
|
-
}
|
|
403
|
-
setSelected(t) {
|
|
404
|
-
if (!this._value.includes(t)) {
|
|
405
|
-
if (this.multiple && this.isMaxItemsReached()) {
|
|
406
|
-
this._userInfoMessage = "Maks antall valg nådd";
|
|
407
|
-
return;
|
|
408
|
-
}
|
|
409
|
-
!this.multiple && this.removeAllSelected(), this._value = t ? [...this._value, t] : this._value, this._options = this._options.map((e) => (e.value === t && (e.selected = !0), e)), this.resetComboboxInput(!0);
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
removeSelected(t) {
|
|
413
|
-
if (!t) return;
|
|
414
|
-
this._value = this._value.filter((i) => i !== t);
|
|
415
|
-
const e = this.findValueInOptions(t);
|
|
416
|
-
e ? (e.selected = !1, e.userAdded ? (this._options = [...this._options.filter((i) => i.value !== t)], this.options = [...this.options.filter((i) => i.value !== t)]) : this._options = [...this._options, e]) : !t && !this.multiple && (this._options = this._options.map((i) => (i.selected = !1, i)));
|
|
417
|
-
}
|
|
418
|
-
addAllOptions() {
|
|
419
|
-
if (this.multiple) {
|
|
420
|
-
if (this.maxlength && this._options.length > this.maxlength) {
|
|
421
|
-
this._userInfoMessage = "For mange valgt";
|
|
422
|
-
return;
|
|
423
|
-
}
|
|
424
|
-
this._value = this._options.map((t) => t.value), this._options = this._options.map((t) => (t.selected = !0, t)), this.requestUpdate();
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
removeAllSelected() {
|
|
428
|
-
this._value = [], this._options = this._options.map((t) => (t.selected = !1, t)), this._options = this._options.filter((t) => !t.userAdded), this.requestUpdate();
|
|
429
|
-
}
|
|
430
|
-
addValue() {
|
|
431
|
-
var e;
|
|
432
|
-
const t = ((e = this.inputRef.value) == null ? void 0 : e.value.trim()) || "";
|
|
433
|
-
this._search = t, this.toggleValue(t);
|
|
434
|
-
}
|
|
435
|
-
removeValue(t) {
|
|
436
|
-
this._value = this.multiple ? this._value.filter((e) => e !== t) : [], this.removeSelected(t);
|
|
437
|
-
}
|
|
438
|
-
addNewUserValue(t) {
|
|
439
|
-
if (!t || t.trim() === "") return;
|
|
440
|
-
if (!this.multiple)
|
|
441
|
-
this._value[0] && this.removeSelected(this._value[0]), this._value = [t], this._isOptionsOpen = !1, this.blurInput();
|
|
442
|
-
else if (!this.findValueInOptions(t)) {
|
|
443
|
-
if (this.isMaxItemsReached()) return;
|
|
444
|
-
this._value = [...this._value, t];
|
|
445
|
-
}
|
|
446
|
-
const e = { value: t, label: t, userAdded: !0 };
|
|
447
|
-
this.options = [e, ...this.options], this._options = [e, ...this._options], this.setSelected(t), this.requestUpdate();
|
|
448
|
-
}
|
|
449
|
-
resetComboboxInput(t = !0) {
|
|
450
|
-
if (this._addValueText = null, this.inputRef.value && this.inputRef.value.type !== "hidden" && t)
|
|
451
|
-
if (this._search = "", this.multiple)
|
|
452
|
-
this.inputRef.value.value = "";
|
|
453
|
-
else {
|
|
454
|
-
const e = this.findValueInOptions(this._value[0]);
|
|
455
|
-
window.setTimeout(() => {
|
|
456
|
-
!this.inputRef.value || this.inputRef.value.type === "hidden" || (this.inputRef.value.value = this.displayValueAs === "label" && (e != null && e.label) ? e.label : this._value[0] || "");
|
|
457
|
-
}, 0), this._userInfoMessage = "";
|
|
458
|
-
}
|
|
459
|
-
this._options = [...this.options];
|
|
460
|
-
}
|
|
461
|
-
removeLastValue(t) {
|
|
462
|
-
if (this._value.length === 0) return;
|
|
463
|
-
t.preventDefault();
|
|
464
|
-
const e = this._value[this._value.length - 1];
|
|
465
|
-
e && this.removeSelected(e), this.isMaxItemsReached();
|
|
466
|
-
}
|
|
467
|
-
};
|
|
468
|
-
n([
|
|
469
|
-
r({ type: String, reflect: !0 })
|
|
470
|
-
], o.prototype, "value", 2);
|
|
471
|
-
n([
|
|
472
|
-
r({ type: Array })
|
|
473
|
-
], o.prototype, "options", 2);
|
|
474
|
-
n([
|
|
475
|
-
r({ type: Array })
|
|
476
|
-
], o.prototype, "defaultOptions", 2);
|
|
477
|
-
n([
|
|
478
|
-
r({ type: Boolean })
|
|
479
|
-
], o.prototype, "allowUserInput", 2);
|
|
480
|
-
n([
|
|
481
|
-
r({ type: Boolean })
|
|
482
|
-
], o.prototype, "typeahead", 2);
|
|
483
|
-
n([
|
|
484
|
-
r({ type: Boolean })
|
|
485
|
-
], o.prototype, "includeSearch", 2);
|
|
486
|
-
n([
|
|
487
|
-
r({ type: String })
|
|
488
|
-
], o.prototype, "searchPlaceholder", 2);
|
|
489
|
-
n([
|
|
490
|
-
r({ type: Boolean })
|
|
491
|
-
], o.prototype, "multiple", 2);
|
|
492
|
-
n([
|
|
493
|
-
r({ type: Number })
|
|
494
|
-
], o.prototype, "maxlength", 2);
|
|
495
|
-
n([
|
|
496
|
-
r({ type: String })
|
|
497
|
-
], o.prototype, "displayValueAs", 2);
|
|
498
|
-
n([
|
|
499
|
-
r({ type: String })
|
|
500
|
-
], o.prototype, "tagPlacement", 2);
|
|
501
|
-
n([
|
|
502
|
-
c()
|
|
503
|
-
], o.prototype, "_options", 2);
|
|
504
|
-
n([
|
|
505
|
-
c()
|
|
506
|
-
], o.prototype, "_value", 2);
|
|
507
|
-
n([
|
|
508
|
-
c()
|
|
509
|
-
], o.prototype, "_isOptionsOpen", 2);
|
|
510
|
-
n([
|
|
511
|
-
c()
|
|
512
|
-
], o.prototype, "_userInfoMessage", 2);
|
|
513
|
-
n([
|
|
514
|
-
c()
|
|
515
|
-
], o.prototype, "_addValueText", 2);
|
|
516
|
-
n([
|
|
517
|
-
c()
|
|
518
|
-
], o.prototype, "_maxIsReached", 2);
|
|
519
|
-
n([
|
|
520
|
-
c()
|
|
521
|
-
], o.prototype, "_search", 2);
|
|
522
|
-
n([
|
|
523
|
-
c()
|
|
524
|
-
], o.prototype, "_inputFocus", 2);
|
|
525
|
-
n([
|
|
526
|
-
c()
|
|
527
|
-
], o.prototype, "_editingSingleValue", 2);
|
|
528
|
-
o = n([
|
|
529
|
-
w("pkt-combobox")
|
|
530
|
-
], o);
|
|
531
|
-
export {
|
|
532
|
-
o as P
|
|
533
|
-
};
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
"use strict";const s=require("./element-CMTfByxQ.cjs"),p=require("./state-BNgpvY-A.cjs"),c=require("./if-defined-hKKmbsI8.cjs"),u=require("./repeat-C-FJ2vfy.cjs"),h=require("./class-map-Bokp1SoS.cjs"),d=require("./utils-byXsEz1u.cjs");var b=Object.defineProperty,f=Object.getOwnPropertyDescriptor,l=(r,e,t,i)=>{for(var n=i>1?void 0:i?f(e,t):e,o=r.length-1,a;o>=0;o--)(a=r[o])&&(n=(i?a(e,t,n):a(n))||n);return i&&n&&b(e,t,n),n};exports.PktListbox=class extends s.PktElement{constructor(){super(...arguments),this.id=d.uuidish(),this.label=null,this.options=[],this.isOpen=!1,this.disabled=!1,this.includeSearch=!1,this.isMultiSelect=!1,this.allowUserInput=!1,this.maxIsReached=!1,this.customUserInput=null,this.searchPlaceholder=null,this.searchValue=null,this.maxLength=0,this.userMessage=null,this._selectedOptions=0,this._filteredOptions=[]}connectedCallback(){super.connectedCallback(),this.includeSearch&&!this.searchValue&&(this.searchValue=""),this.options.length>0&&this.filterOptions(),this.setAttribute("tabindex","-1"),this.addEventListener("focus",this.focusFirstOrSelectedOption)}updated(e){(e.has("options")||e.has("searchValue"))&&this.filterOptions(),super.updated(e)}attributeChangedCallback(e,t,i){(e==="options"||e==="searchValue"||e==="search-value")&&this.filterOptions(),super.attributeChangedCallback(e,t,i)}render(){return s.b`
|
|
2
|
-
<div
|
|
3
|
-
class=${h.e({"pkt-listbox":!0,"pkt-listbox__open":this.isOpen,"pkt-txt-16-light":!0})}
|
|
4
|
-
role="listbox"
|
|
5
|
-
aria-multiselectable=${c.o(this.isMultiSelect?"true":void 0)}
|
|
6
|
-
aria-label=${c.o(this.label)}
|
|
7
|
-
>
|
|
8
|
-
<div class="pkt-listbox__banners">
|
|
9
|
-
${this.renderMaximumReachedBanner()} ${this.renderUserMessage()}
|
|
10
|
-
${this.renderNewOptionBanner()} ${this.renderSearch()}
|
|
11
|
-
</div>
|
|
12
|
-
<ul class="pkt-listbox__options" role="presentation">
|
|
13
|
-
${this.renderList()}
|
|
14
|
-
</ul>
|
|
15
|
-
</div>
|
|
16
|
-
`}renderCheckboxOrCheckIcon(e,t){return this.isMultiSelect?s.b`
|
|
17
|
-
<input
|
|
18
|
-
class="pkt-input-check__input-checkbox"
|
|
19
|
-
type="checkbox"
|
|
20
|
-
role="presentation"
|
|
21
|
-
tabindex="-1"
|
|
22
|
-
value=${e.value}
|
|
23
|
-
.checked=${e.selected}
|
|
24
|
-
aria-labelledby=${this.id+"-option-label-"+t}
|
|
25
|
-
?disabled=${this.disabled||e.disabled||this.maxIsReached&&!e.selected}
|
|
26
|
-
/>
|
|
27
|
-
`:e.selected?s.b`<pkt-icon name="check-big"></pkt-icon>`:s.A}renderList(){return s.b`
|
|
28
|
-
${u.c(this._filteredOptions,e=>e.value,(e,t)=>s.b`
|
|
29
|
-
<li
|
|
30
|
-
@click=${()=>{this.toggleOption(e)}}
|
|
31
|
-
aria-selected=${e.selected?"true":"false"}
|
|
32
|
-
@keydown=${this.handleOptionKeydown}
|
|
33
|
-
class=${h.e({"pkt-listbox__option":!0,"pkt-listbox__option--selected":!!(!this.isMultiSelect&&e.selected),"pkt-listbox__option--checkBox":this.isMultiSelect})}
|
|
34
|
-
tabindex="${this.disabled||e.disabled?"-1":"0"}"
|
|
35
|
-
data-index=${t}
|
|
36
|
-
data-value=${e.value}
|
|
37
|
-
data-selected=${e.selected?"true":"false"}
|
|
38
|
-
?data-disabled=${this.disabled||e.disabled||this.maxIsReached&&!e.selected}
|
|
39
|
-
role="option"
|
|
40
|
-
id=${`${this.id}-${t}`}
|
|
41
|
-
>
|
|
42
|
-
${this.renderCheckboxOrCheckIcon(e,t)}
|
|
43
|
-
<span class="pkt-listbox__option-label" id=${this.id+"-option-label-"+t}>
|
|
44
|
-
${e.prefix?s.b`<span class="pkt-listbox__option-prefix">${e.prefix}</span>`:s.A}
|
|
45
|
-
${e.label||e.value}
|
|
46
|
-
</span>
|
|
47
|
-
${e.description?s.b`<span class="pkt-listbox__option-description pkt-txt-14-light"
|
|
48
|
-
>${e.description}</span
|
|
49
|
-
>`:s.A}
|
|
50
|
-
</li>
|
|
51
|
-
`)}
|
|
52
|
-
`}renderNewOptionBanner(){return this.allowUserInput&&this.customUserInput?s.b`
|
|
53
|
-
<div
|
|
54
|
-
class="pkt-listbox__banner pkt-listbox__banner--new-option pkt-listbox__option"
|
|
55
|
-
data-type="new-option"
|
|
56
|
-
data-value=${this.customUserInput}
|
|
57
|
-
data-selected="false"
|
|
58
|
-
tabindex="0"
|
|
59
|
-
@click=${()=>this.toggleOption({value:this.customUserInput||""})}
|
|
60
|
-
@keydown=${this.handleOptionKeydown}
|
|
61
|
-
>
|
|
62
|
-
<pkt-icon class="pkt-listbox__banner-icon" name="plus-sign" size="large"></pkt-icon>
|
|
63
|
-
Legg til “${this.customUserInput}”
|
|
64
|
-
</div>
|
|
65
|
-
`:s.A}renderMaximumReachedBanner(){return this._selectedOptions=this.options.filter(e=>e.selected).length,this.isMultiSelect&&this._selectedOptions>0&&this.maxLength>0?s.b`
|
|
66
|
-
<div class="pkt-listbox__banner pkt-listbox__banner--maximum-reached">
|
|
67
|
-
${this._selectedOptions} av maks ${this.maxLength} mulige er valgt.
|
|
68
|
-
</div>
|
|
69
|
-
`:s.A}renderUserMessage(){return this.userMessage?s.b`<div class="pkt-listbox__banner pkt-listbox__banner--user-message">
|
|
70
|
-
<pkt-icon
|
|
71
|
-
class="pkt-listbox__banner-icon"
|
|
72
|
-
name="exclamation-mark-circle"
|
|
73
|
-
size="large"
|
|
74
|
-
></pkt-icon>
|
|
75
|
-
${this.userMessage}
|
|
76
|
-
</div>`:s.A}renderSearch(){return this.includeSearch?s.b`
|
|
77
|
-
<div class="pkt-listbox__search">
|
|
78
|
-
<span class="pkt-listbox__search-icon">
|
|
79
|
-
<pkt-icon name="magnifying-glass-small" size="large"></pkt-icon>
|
|
80
|
-
</span>
|
|
81
|
-
<input
|
|
82
|
-
class="pkt-txt-16-light"
|
|
83
|
-
type="text"
|
|
84
|
-
aria-label="Søk i listen"
|
|
85
|
-
form=""
|
|
86
|
-
placeholder=${this.searchPlaceholder||s.strings.forms.search.placeholder}
|
|
87
|
-
@input=${this.handleSearchInput}
|
|
88
|
-
@keydown=${this.handleSearchKeydown}
|
|
89
|
-
.value=${this.searchValue}
|
|
90
|
-
data-type="searchbox"
|
|
91
|
-
?disabled=${this.disabled}
|
|
92
|
-
?readonly=${this.disabled}
|
|
93
|
-
role="searchbox"
|
|
94
|
-
/>
|
|
95
|
-
</div>
|
|
96
|
-
`:s.A}handleSearchInput(e){this.searchValue=e.target.value,this.dispatchEvent(new CustomEvent("search",{detail:this.searchValue,bubbles:!1}))}handleSearchKeydown(e){switch(e.key){case"Enter":e.preventDefault();break;case"ArrowUp":case"Escape":this.closeOptions(),e.preventDefault();break;case"ArrowDown":case"Tab":this.focusFirstOrSelectedOption();break}}handleOptionKeydown(e){const t=e.currentTarget,i=t.dataset.value,n=t.dataset.type,o=t.dataset.selected==="true";if(!(!this.getOptionElements().length&&(!this.customUserInput||!this.allowUserInput&&this.customUserInput)&&n!=="new-option"&&n!=="searchbox"))switch(e.key){case" ":case"Enter":this.toggleOption(t),e.preventDefault();break;case"Backspace":i&&(o?this.toggleOption(t):this.closeOptions()),e.preventDefault();break;case"Escape":case"Tab":this.closeOptions();break;case"ArrowDown":e.altKey?this.focusLastOption():n==="searchbox"||n==="new-option"?this.focusFirstOption():this.focusNextOption(t),e.preventDefault();break;case"ArrowUp":if(e.altKey)this.focusFirstOption();else if(t.dataset.index==="0"&&this.includeSearch){const a=this.querySelector('[role="searchbox"]');a&&a.focus()}else if(t.dataset.index==="0"&&this.customUserInput){const a=this.querySelector('[data-type="new-option"]');a&&a.focus()}else this.focusPreviousOption(t);e.preventDefault();break;case"Home":this.focusFirstOption(),e.preventDefault();break;case"End":this.focusLastOption(),e.preventDefault();break;default:(e.metaKey||e.ctrlKey)&&e.key==="a"&&(this.selectAll(),e.preventDefault()),this.isLetterOrSpace(e.key)&&(this.handleTypeAhead(e.key),e.preventDefault());break}}focusAndScrollIntoView(e){e.scrollIntoView({block:"nearest"}),window.setTimeout(()=>e.focus(),0)}focusNextOption(e){const t=e.nextElementSibling;t&&this.focusAndScrollIntoView(t)}focusPreviousOption(e){const t=e.previousElementSibling;if(e.dataset.index==="0"&&this.includeSearch){const i=this.querySelector('[role="searchbox"]');i&&this.focusAndScrollIntoView(i)}else t&&this.focusAndScrollIntoView(t)}focusFirstOption(){const e=this.getOptionElements()[0];e&&this.focusAndScrollIntoView(e)}focusLastOption(){const e=this.getOptionElements().pop();e&&this.focusAndScrollIntoView(e)}focusFirstOrSelectedOption(){if(this.disabled)return;const e=this.getOptionElements().find(t=>t.dataset.selected==="true");if(this.allowUserInput&&this.customUserInput){const t=this.querySelector('[data-type="new-option"]');this.focusAndScrollIntoView(t)}else if(e)this.focusAndScrollIntoView(e);else if(this.includeSearch&&!(document.activeElement instanceof HTMLInputElement)){const t=this.querySelector('[role="searchbox"]');window.setTimeout(()=>t.focus(),0)}else this.focusFirstOption()}toggleOption(e){const t=e instanceof HTMLElement?e.dataset.disabled:e.disabled;if(this.disabled||t)return;const i=e instanceof HTMLElement?e.dataset.value:e.value;this.dispatchEvent(new CustomEvent("option-toggle",{detail:i,bubbles:!1}))}selectAll(){this.dispatchEvent(new CustomEvent("select-all",{bubbles:!1}))}closeOptions(){this.dispatchEvent(new CustomEvent("close-options",{bubbles:!1}))}filterOptions(){this.searchValue?this._filteredOptions=this.options.filter(e=>{var i;return(e.fulltext||e.label+e.value+(e.prefix||"")).toLowerCase().includes(((i=this.searchValue)==null?void 0:i.toLowerCase())||"")}):this._filteredOptions=[...this.options]}isLetterOrSpace(e){return/^[\p{L} ]$/u.test(e)}handleTypeAhead(e){this.typeAheadString+=e.toLowerCase(),this.typeAheadTimeout&&clearTimeout(this.typeAheadTimeout),this.typeAheadTimeout=window.setTimeout(()=>{this.typeAheadString=""},500);const i=this.getOptionElements().find(n=>{var o;return(o=n.textContent)==null?void 0:o.trim().toLowerCase().startsWith(this.typeAheadString)});i&&this.focusAndScrollIntoView(i)}getOptionElements(){return this._filteredOptions.length?Array.from(this.querySelectorAll('[role="option"]:not([data-disabled])')||[]):[]}};l([s.n({type:String})],exports.PktListbox.prototype,"id",2);l([s.n({type:String})],exports.PktListbox.prototype,"label",2);l([s.n({type:Array})],exports.PktListbox.prototype,"options",2);l([s.n({type:Boolean,reflect:!0})],exports.PktListbox.prototype,"isOpen",2);l([s.n({type:Boolean})],exports.PktListbox.prototype,"disabled",2);l([s.n({type:Boolean})],exports.PktListbox.prototype,"includeSearch",2);l([s.n({type:Boolean})],exports.PktListbox.prototype,"isMultiSelect",2);l([s.n({type:Boolean})],exports.PktListbox.prototype,"allowUserInput",2);l([s.n({type:Boolean})],exports.PktListbox.prototype,"maxIsReached",2);l([s.n({type:String})],exports.PktListbox.prototype,"customUserInput",2);l([s.n({type:String})],exports.PktListbox.prototype,"searchPlaceholder",2);l([s.n({type:String})],exports.PktListbox.prototype,"searchValue",2);l([s.n({type:Number})],exports.PktListbox.prototype,"maxLength",2);l([s.n({type:String})],exports.PktListbox.prototype,"userMessage",2);l([p.r()],exports.PktListbox.prototype,"_filteredOptions",2);exports.PktListbox=l([s.t("pkt-listbox")],exports.PktListbox);
|