@oslokommune/punkt-elements 13.5.12 → 13.5.13
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 +17 -0
- package/dist/index.d.ts +3 -1
- package/dist/pkt-index.cjs +1 -1
- package/dist/pkt-index.js +1 -1
- package/dist/pkt-select.cjs +1 -1
- package/dist/pkt-select.js +1 -1
- package/dist/select-Be--DBcR.cjs +49 -0
- package/dist/select-VpX_cjMM.js +173 -0
- package/package.json +2 -2
- package/src/components/select/select.ts +47 -17
- package/dist/select-CD6Zn8YH.cjs +0 -49
- package/dist/select-dcaJHvmR.js +0 -157
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,23 @@ og skriver commits ca etter [Conventional Commits](https://conventionalcommits.o
|
|
|
5
5
|
|
|
6
6
|
---
|
|
7
7
|
|
|
8
|
+
## [13.5.13](https://github.com/oslokommune/punkt/compare/13.5.12...13.5.13) (2025-09-12)
|
|
9
|
+
|
|
10
|
+
### ⚠ BREAKING CHANGES
|
|
11
|
+
Ingen
|
|
12
|
+
|
|
13
|
+
### Features
|
|
14
|
+
Ingen
|
|
15
|
+
|
|
16
|
+
### Bug Fixes
|
|
17
|
+
Ingen
|
|
18
|
+
|
|
19
|
+
### Chores
|
|
20
|
+
Ingen
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
|
|
8
25
|
## [13.5.11](https://github.com/oslokommune/punkt/compare/13.5.10...13.5.11) (2025-09-11)
|
|
9
26
|
|
|
10
27
|
### ⚠ BREAKING CHANGES
|
package/dist/index.d.ts
CHANGED
|
@@ -1046,11 +1046,13 @@ export { PktRadioButton as PktRadiobutton }
|
|
|
1046
1046
|
export declare class PktSelect extends PktInputElement implements IPktSelect {
|
|
1047
1047
|
private inputRef;
|
|
1048
1048
|
private helptextSlot;
|
|
1049
|
-
|
|
1049
|
+
private _optionsProp;
|
|
1050
1050
|
value: string;
|
|
1051
1051
|
private _options;
|
|
1052
1052
|
selectedIndex: number | null;
|
|
1053
1053
|
selectedOptions: HTMLCollectionOf<HTMLOptionElement> | undefined;
|
|
1054
|
+
get options(): TSelectOption[];
|
|
1055
|
+
set options(value: TSelectOption[]);
|
|
1054
1056
|
constructor();
|
|
1055
1057
|
connectedCallback(): void;
|
|
1056
1058
|
add(item: HTMLOptionElement, before?: HTMLOptionElement | number): void;
|
package/dist/pkt-index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const P=require("./alert-7rUOhlNi.cjs"),l=require("./accordionitem-Csh7iSVG.cjs"),d=require("./backlink-JbBNi3qg.cjs"),b=require("./button-B8rdtaHB.cjs"),k=require("./calendar-32W9p9uc.cjs"),m=require("./card-DBlFf1ry.cjs"),g=require("./combobox-D84REr9N.cjs"),h=require("./consent-hYeFWNFr.cjs"),f=require("./checkbox-Gn7Wtk9h.cjs"),t=require("./element-6DBpyGQm.cjs"),y=require("./pkt-slot-controller-BzddBp7z.cjs"),s=require("./ref-iJtiv3o2.cjs"),O=require("./class-map-BBG2gMX4.cjs"),j=require("./datepicker-DonUad47.cjs"),q=require("./helptext-CzQX6YVE.cjs"),x=require("./heading-CNycsyMj.cjs"),C=require("./icon-B_ryAy4Q.cjs"),v=require("./input-wrapper-CZ-a00V7.cjs"),S=require("./link-Cjl0xwSq.cjs"),$=require("./linkcard-DqIvb54H.cjs"),L=require("./loader-DNidjwH-.cjs"),_=require("./messagebox-CjPtPPrW.cjs"),A=require("./modal-CRtxhCaP.cjs"),B=require("./progressbar-DhMBXkww.cjs"),p=require("./radiobutton-CdT6v1oq.cjs"),T=require("./tag-Bbs0U_Au.cjs"),I=require("./textarea-CPXsMFUq.cjs"),M=require("./textinput-aNI5kibM.cjs"),R=require("./select-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const P=require("./alert-7rUOhlNi.cjs"),l=require("./accordionitem-Csh7iSVG.cjs"),d=require("./backlink-JbBNi3qg.cjs"),b=require("./button-B8rdtaHB.cjs"),k=require("./calendar-32W9p9uc.cjs"),m=require("./card-DBlFf1ry.cjs"),g=require("./combobox-D84REr9N.cjs"),h=require("./consent-hYeFWNFr.cjs"),f=require("./checkbox-Gn7Wtk9h.cjs"),t=require("./element-6DBpyGQm.cjs"),y=require("./pkt-slot-controller-BzddBp7z.cjs"),s=require("./ref-iJtiv3o2.cjs"),O=require("./class-map-BBG2gMX4.cjs"),j=require("./datepicker-DonUad47.cjs"),q=require("./helptext-CzQX6YVE.cjs"),x=require("./heading-CNycsyMj.cjs"),C=require("./icon-B_ryAy4Q.cjs"),v=require("./input-wrapper-CZ-a00V7.cjs"),S=require("./link-Cjl0xwSq.cjs"),$=require("./linkcard-DqIvb54H.cjs"),L=require("./loader-DNidjwH-.cjs"),_=require("./messagebox-CjPtPPrW.cjs"),A=require("./modal-CRtxhCaP.cjs"),B=require("./progressbar-DhMBXkww.cjs"),p=require("./radiobutton-CdT6v1oq.cjs"),T=require("./tag-Bbs0U_Au.cjs"),I=require("./textarea-CPXsMFUq.cjs"),M=require("./textinput-aNI5kibM.cjs"),R=require("./select-Be--DBcR.cjs");var H=Object.defineProperty,w=Object.getOwnPropertyDescriptor,o=(a,e,r,i)=>{for(var n=i>1?void 0:i?w(e,r):e,u=a.length-1,c;u>=0;u--)(c=a[u])&&(n=(i?c(e,r,n):c(n))||n);return i&&n&&H(e,r,n),n};exports.PktComponent=class extends t.PktElement{constructor(){super(),this.string="",this.strings=[],this.darkmode=!1,this._list=[],this.defaultSlot=s.e(),this.namedSlot=s.e(),this.slotController=new y.PktSlotController(this,this.defaultSlot,this.namedSlot)}connectedCallback(){this.strings.length&&this.strings.forEach(e=>{this._list.push(e.toUpperCase())}),super.connectedCallback()}render(){const e={"pkt-component":!0,"pkt-component--has-list":this.strings.length>0,"pkt-darkmode":this.darkmode};return t.x`
|
|
2
2
|
<div class="${O.e(e)}">
|
|
3
3
|
<h1 class="pkt-txt-28">${this.string}</h1>
|
|
4
4
|
|
package/dist/pkt-index.js
CHANGED
|
@@ -27,7 +27,7 @@ import { P as ht, P as ct } from "./radiobutton-CWxiIVfA.js";
|
|
|
27
27
|
import { P as ut } from "./tag-DyXzTY68.js";
|
|
28
28
|
import { P as vt } from "./textarea-BZL8Mkm0.js";
|
|
29
29
|
import { P as bt } from "./textinput-DjPhmmkB.js";
|
|
30
|
-
import { P as $t } from "./select-
|
|
30
|
+
import { P as $t } from "./select-VpX_cjMM.js";
|
|
31
31
|
var g = Object.defineProperty, v = Object.getOwnPropertyDescriptor, s = (t, e, i, a) => {
|
|
32
32
|
for (var r = a > 1 ? void 0 : a ? v(e, i) : e, p = t.length - 1, l; p >= 0; p--)
|
|
33
33
|
(l = t[p]) && (r = (a ? l(e, i, r) : l(r)) || r);
|
package/dist/pkt-select.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./select-
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./select-Be--DBcR.cjs"),t=e.PktSelect;Object.defineProperty(exports,"PktSelect",{enumerable:!0,get:()=>e.PktSelect});exports.default=t;
|
package/dist/pkt-select.js
CHANGED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";const h=require("./element-6DBpyGQm.cjs"),u=require("./state-DPobt-Yz.cjs"),r=require("./ref-iJtiv3o2.cjs"),o=require("./if-defined-Cni-RHLS.cjs"),d=require("./input-element-C4xJoM-X.cjs"),c=require("./pkt-options-controller-CiuBG6Lt.cjs"),v=require("./pkt-slot-controller-BzddBp7z.cjs");require("./input-wrapper-CZ-a00V7.cjs");var f=Object.defineProperty,_=Object.getOwnPropertyDescriptor,a=(p,t,e,s)=>{for(var i=s>1?void 0:s?_(t,e):t,l=p.length-1,n;l>=0;l--)(n=p[l])&&(i=(s?n(t,e,i):n(i))||i);return s&&i&&f(t,e,i),i};exports.PktSelect=class extends d.PktInputElement{constructor(){super(),this.inputRef=r.e(),this.helptextSlot=r.e(),this._optionsProp=[],this.value="",this._options=[],this.selectedIndex=-1,this.selectedOptions=void 0,this.optionsController=new c.PktOptionsSlotController(this),this.slotController=new v.PktSlotController(this,this.helptextSlot),this.slotController.skipOptions=!0}get options(){return this._options.map(t=>({...t,selected:t.value===this.value}))}set options(t){this._optionsProp=t,this.requestUpdate("_optionsProp",this._options)}connectedCallback(){super.connectedCallback();const t=this._optionsProp.length>0,e=this.optionsController.nodes.length&&this.optionsController.nodes.length>0;!t&&e?this.optionsController.nodes.forEach(s=>{const i={value:s.hasAttribute("value")?s.getAttribute("value")??"":s.textContent??"",label:s.textContent||s.getAttribute("value")||"",disabled:s.hasAttribute("disabled"),selected:s.hasAttribute("selected"),hidden:s.hasAttribute("data-hidden")};s.getAttribute("selected")&&!this.value&&(this.value=i.value),this._options.push(i)}):(this._options=this._optionsProp,this._options.forEach(s=>{s.selected&&!this.value&&(this.value=s.value)}))}add(t,e){const s={value:t.value||t.text,label:t.text||t.value,selected:t.selected,disabled:t.disabled};if(e===void 0)this._options.push(s);else if(typeof e=="number")this._options.splice(e,0,s);else{const i=e.value||e.text,l=this._options.findIndex(n=>n.value===i);l>=0?this._options.splice(l,0,s):this._options.push(s)}t.selected&&(this.value=t.value||t.text,this.selectedIndex=this._options.findIndex(i=>i.value===this.value)),this.requestUpdate()}remove(t){var e;typeof t=="number"&&(this.selectedIndex===t&&(this.value=((e=this._options[0])==null?void 0:e.value)||""),this._options.splice(t,1),this.requestUpdate())}item(t){var e;return(e=this.inputRef.value)==null?void 0:e.item(t)}namedItem(t){var e;return(e=this.inputRef.value)==null?void 0:e.namedItem(t)}showPicker(){this.inputRef.value&&"showPicker"in this.inputRef.value&&this.inputRef.value.showPicker()}attributeChangedCallback(t,e,s){var i,l;t==="options"&&(this._options=s?JSON.parse(s):[]),t==="value"&&this.value!==e&&(this.selectedIndex=this.touched?this.returnNumberOrNull((i=this.inputRef.value)==null?void 0:i.selectedIndex):this._options.findIndex(n=>n.value===s),this.selectedOptions=(l=this.inputRef.value)==null?void 0:l.selectedOptions,this.valueChanged(s,e)),super.attributeChangedCallback(t,e,s)}update(t){var e,s;super.update(t),t.has("_optionsProp")&&this._optionsProp.length>0&&(this._options=this._optionsProp,this.requestUpdate("_options"),!this.value&&this._options.length>0&&(this.value=this._options[0].value,this.selectedIndex=0)),t.has("value")&&this.value!==t.get("value")&&(this.selectedIndex=this.touched?this.returnNumberOrNull((e=this.inputRef.value)==null?void 0:e.selectedIndex):this._options.findIndex(i=>i.value===this.value),this.selectedOptions=(s=this.inputRef.value)==null?void 0:s.selectedOptions,this.valueChanged(this.value,t.get("value"))),t.has("id")&&!this.name&&this.id&&(this.name=this.id)}firstUpdated(t){var e;super.firstUpdated(t),this._optionsProp.length&&(this._options=this._optionsProp),!this.value&&this._options.length>0?(this.value=this._options[0].value,this.selectedIndex=0):this.selectedIndex=this._options.findIndex(s=>s.value===this.value),this.selectedOptions=(e=this.inputRef.value)==null?void 0:e.selectedOptions}render(){const t=`pkt-input ${this.fullwidth?"pkt-input--fullwidth":""}`;return h.x`
|
|
2
|
+
<pkt-input-wrapper
|
|
3
|
+
?counter=${this.counter}
|
|
4
|
+
?disabled=${this.disabled}
|
|
5
|
+
?hasError=${this.hasError}
|
|
6
|
+
?hasFieldset=${this.hasFieldset}
|
|
7
|
+
?inline=${this.inline}
|
|
8
|
+
?optionalTag=${this.optionalTag}
|
|
9
|
+
?requiredTag=${this.requiredTag}
|
|
10
|
+
?useWrapper=${this.useWrapper}
|
|
11
|
+
ariaDescribedBy=${o.o(this.ariaDescribedBy)}
|
|
12
|
+
class="pkt-select"
|
|
13
|
+
errorMessage=${o.o(this.errorMessage)}
|
|
14
|
+
forId=${this.id+"-input"}
|
|
15
|
+
helptext=${o.o(this.helptext)}
|
|
16
|
+
helptextDropdown=${o.o(this.helptextDropdown)}
|
|
17
|
+
helptextDropdownButton=${o.o(this.helptextDropdownButton)}
|
|
18
|
+
label=${o.o(this.label)}
|
|
19
|
+
optionalText=${o.o(this.optionalText)}
|
|
20
|
+
requiredText=${o.o(this.requiredText)}
|
|
21
|
+
tagText=${o.o(this.tagText)}
|
|
22
|
+
>
|
|
23
|
+
<select
|
|
24
|
+
class=${t}
|
|
25
|
+
aria-invalid=${this.hasError}
|
|
26
|
+
aria-errormessage=${`${this.id}-error`}
|
|
27
|
+
aria-labelledby=${o.o(this.ariaLabelledby)}
|
|
28
|
+
?disabled=${this.disabled}
|
|
29
|
+
id=${this.id+"-input"}
|
|
30
|
+
name=${(this.name||this.id)+"-input"}
|
|
31
|
+
value=${this.value}
|
|
32
|
+
@change=${e=>{this.touched=!0,this.value=e.target.value,e.stopImmediatePropagation()}}
|
|
33
|
+
@input=${e=>{this.onInput(),e.stopImmediatePropagation()}}
|
|
34
|
+
@focus=${e=>{this.onFocus(),e.stopImmediatePropagation()}}
|
|
35
|
+
@blur=${e=>{this.onBlur(),e.stopImmediatePropagation()}}
|
|
36
|
+
${r.n(this.inputRef)}
|
|
37
|
+
>
|
|
38
|
+
${this._options.length>0?this._options.map(e=>h.x`<option
|
|
39
|
+
value=${e.value}
|
|
40
|
+
?selected=${this.value==e.value||e.selected}
|
|
41
|
+
?disabled=${e.disabled}
|
|
42
|
+
?hidden=${e.hidden}
|
|
43
|
+
>
|
|
44
|
+
${e.label}
|
|
45
|
+
</option>`):""}
|
|
46
|
+
</select>
|
|
47
|
+
<div class="pkt-contents" ${r.n(this.helptextSlot)} name="helptext" slot="helptext"></div>
|
|
48
|
+
</pkt-input-wrapper>
|
|
49
|
+
`}returnNumberOrNull(t){return t==null||isNaN(t)?null:t}};a([h.n({type:Array,attribute:"options"})],exports.PktSelect.prototype,"_optionsProp",2);a([h.n({type:String})],exports.PktSelect.prototype,"value",2);a([u.r()],exports.PktSelect.prototype,"_options",2);exports.PktSelect=a([h.t("pkt-select")],exports.PktSelect);
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { x as r, n as c, a as v } from "./element-CgEWt74-.js";
|
|
2
|
+
import { r as f } from "./state-Bo2bck5_.js";
|
|
3
|
+
import { e as u, n as d } from "./ref-BBYSqgeW.js";
|
|
4
|
+
import { o as l } from "./if-defined-CmuO4Vz9.js";
|
|
5
|
+
import { P as _ } from "./input-element-NnrDmp4r.js";
|
|
6
|
+
import { P as x } from "./pkt-options-controller-CZO1nxZ8.js";
|
|
7
|
+
import { P as b } from "./pkt-slot-controller-BPGj-LC5.js";
|
|
8
|
+
import "./input-wrapper-Dr__Sxql.js";
|
|
9
|
+
var $ = Object.defineProperty, m = Object.getOwnPropertyDescriptor, a = (t, e, s, i) => {
|
|
10
|
+
for (var o = i > 1 ? void 0 : i ? m(e, s) : e, n = t.length - 1, p; n >= 0; n--)
|
|
11
|
+
(p = t[n]) && (o = (i ? p(e, s, o) : p(o)) || o);
|
|
12
|
+
return i && o && $(e, s, o), o;
|
|
13
|
+
};
|
|
14
|
+
let h = class extends _ {
|
|
15
|
+
constructor() {
|
|
16
|
+
super(), this.inputRef = u(), this.helptextSlot = u(), this._optionsProp = [], this.value = "", this._options = [], this.selectedIndex = -1, this.selectedOptions = void 0, this.optionsController = new x(this), this.slotController = new b(this, this.helptextSlot), this.slotController.skipOptions = !0;
|
|
17
|
+
}
|
|
18
|
+
// Getter and setter for options to expose the actual parsed options
|
|
19
|
+
get options() {
|
|
20
|
+
return this._options.map((t) => ({
|
|
21
|
+
...t,
|
|
22
|
+
selected: t.value === this.value
|
|
23
|
+
}));
|
|
24
|
+
}
|
|
25
|
+
set options(t) {
|
|
26
|
+
this._optionsProp = t, this.requestUpdate("_optionsProp", this._options);
|
|
27
|
+
}
|
|
28
|
+
connectedCallback() {
|
|
29
|
+
super.connectedCallback();
|
|
30
|
+
const t = this._optionsProp.length > 0, e = this.optionsController.nodes.length && this.optionsController.nodes.length > 0;
|
|
31
|
+
!t && e ? this.optionsController.nodes.forEach((s) => {
|
|
32
|
+
const i = {
|
|
33
|
+
value: s.hasAttribute("value") ? s.getAttribute("value") ?? "" : s.textContent ?? "",
|
|
34
|
+
label: s.textContent || s.getAttribute("value") || "",
|
|
35
|
+
disabled: s.hasAttribute("disabled"),
|
|
36
|
+
selected: s.hasAttribute("selected"),
|
|
37
|
+
hidden: s.hasAttribute("data-hidden")
|
|
38
|
+
};
|
|
39
|
+
s.getAttribute("selected") && !this.value && (this.value = i.value), this._options.push(i);
|
|
40
|
+
}) : (this._options = this._optionsProp, this._options.forEach((s) => {
|
|
41
|
+
s.selected && !this.value && (this.value = s.value);
|
|
42
|
+
}));
|
|
43
|
+
}
|
|
44
|
+
// Support native Select method `add`
|
|
45
|
+
add(t, e) {
|
|
46
|
+
const s = {
|
|
47
|
+
value: t.value || t.text,
|
|
48
|
+
label: t.text || t.value,
|
|
49
|
+
selected: t.selected,
|
|
50
|
+
disabled: t.disabled
|
|
51
|
+
};
|
|
52
|
+
if (e === void 0)
|
|
53
|
+
this._options.push(s);
|
|
54
|
+
else if (typeof e == "number")
|
|
55
|
+
this._options.splice(e, 0, s);
|
|
56
|
+
else {
|
|
57
|
+
const i = e.value || e.text, o = this._options.findIndex((n) => n.value === i);
|
|
58
|
+
o >= 0 ? this._options.splice(o, 0, s) : this._options.push(s);
|
|
59
|
+
}
|
|
60
|
+
t.selected && (this.value = t.value || t.text, this.selectedIndex = this._options.findIndex((i) => i.value === this.value)), this.requestUpdate();
|
|
61
|
+
}
|
|
62
|
+
// Support native Select method `remove`
|
|
63
|
+
remove(t) {
|
|
64
|
+
var e;
|
|
65
|
+
typeof t == "number" && (this.selectedIndex === t && (this.value = ((e = this._options[0]) == null ? void 0 : e.value) || ""), this._options.splice(t, 1), this.requestUpdate());
|
|
66
|
+
}
|
|
67
|
+
// Support native Select method `item`
|
|
68
|
+
item(t) {
|
|
69
|
+
var e;
|
|
70
|
+
return (e = this.inputRef.value) == null ? void 0 : e.item(t);
|
|
71
|
+
}
|
|
72
|
+
// Support native Select method `namedItem`
|
|
73
|
+
namedItem(t) {
|
|
74
|
+
var e;
|
|
75
|
+
return (e = this.inputRef.value) == null ? void 0 : e.namedItem(t);
|
|
76
|
+
}
|
|
77
|
+
// Support native Select method `showPicker`
|
|
78
|
+
showPicker() {
|
|
79
|
+
this.inputRef.value && "showPicker" in this.inputRef.value && this.inputRef.value.showPicker();
|
|
80
|
+
}
|
|
81
|
+
attributeChangedCallback(t, e, s) {
|
|
82
|
+
var i, o;
|
|
83
|
+
t === "options" && (this._options = s ? JSON.parse(s) : []), t === "value" && this.value !== e && (this.selectedIndex = this.touched ? this.returnNumberOrNull((i = this.inputRef.value) == null ? void 0 : i.selectedIndex) : this._options.findIndex((n) => n.value === s), this.selectedOptions = (o = this.inputRef.value) == null ? void 0 : o.selectedOptions, this.valueChanged(s, e)), super.attributeChangedCallback(t, e, s);
|
|
84
|
+
}
|
|
85
|
+
update(t) {
|
|
86
|
+
var e, s;
|
|
87
|
+
super.update(t), t.has("_optionsProp") && this._optionsProp.length > 0 && (this._options = this._optionsProp, this.requestUpdate("_options"), !this.value && this._options.length > 0 && (this.value = this._options[0].value, this.selectedIndex = 0)), t.has("value") && this.value !== t.get("value") && (this.selectedIndex = this.touched ? this.returnNumberOrNull((e = this.inputRef.value) == null ? void 0 : e.selectedIndex) : this._options.findIndex((i) => i.value === this.value), this.selectedOptions = (s = this.inputRef.value) == null ? void 0 : s.selectedOptions, this.valueChanged(this.value, t.get("value"))), t.has("id") && !this.name && this.id && (this.name = this.id);
|
|
88
|
+
}
|
|
89
|
+
firstUpdated(t) {
|
|
90
|
+
var e;
|
|
91
|
+
super.firstUpdated(t), this._optionsProp.length && (this._options = this._optionsProp), !this.value && this._options.length > 0 ? (this.value = this._options[0].value, this.selectedIndex = 0) : this.selectedIndex = this._options.findIndex((s) => s.value === this.value), this.selectedOptions = (e = this.inputRef.value) == null ? void 0 : e.selectedOptions;
|
|
92
|
+
}
|
|
93
|
+
render() {
|
|
94
|
+
const t = `pkt-input ${this.fullwidth ? "pkt-input--fullwidth" : ""}`;
|
|
95
|
+
return r`
|
|
96
|
+
<pkt-input-wrapper
|
|
97
|
+
?counter=${this.counter}
|
|
98
|
+
?disabled=${this.disabled}
|
|
99
|
+
?hasError=${this.hasError}
|
|
100
|
+
?hasFieldset=${this.hasFieldset}
|
|
101
|
+
?inline=${this.inline}
|
|
102
|
+
?optionalTag=${this.optionalTag}
|
|
103
|
+
?requiredTag=${this.requiredTag}
|
|
104
|
+
?useWrapper=${this.useWrapper}
|
|
105
|
+
ariaDescribedBy=${l(this.ariaDescribedBy)}
|
|
106
|
+
class="pkt-select"
|
|
107
|
+
errorMessage=${l(this.errorMessage)}
|
|
108
|
+
forId=${this.id + "-input"}
|
|
109
|
+
helptext=${l(this.helptext)}
|
|
110
|
+
helptextDropdown=${l(this.helptextDropdown)}
|
|
111
|
+
helptextDropdownButton=${l(this.helptextDropdownButton)}
|
|
112
|
+
label=${l(this.label)}
|
|
113
|
+
optionalText=${l(this.optionalText)}
|
|
114
|
+
requiredText=${l(this.requiredText)}
|
|
115
|
+
tagText=${l(this.tagText)}
|
|
116
|
+
>
|
|
117
|
+
<select
|
|
118
|
+
class=${t}
|
|
119
|
+
aria-invalid=${this.hasError}
|
|
120
|
+
aria-errormessage=${`${this.id}-error`}
|
|
121
|
+
aria-labelledby=${l(this.ariaLabelledby)}
|
|
122
|
+
?disabled=${this.disabled}
|
|
123
|
+
id=${this.id + "-input"}
|
|
124
|
+
name=${(this.name || this.id) + "-input"}
|
|
125
|
+
value=${this.value}
|
|
126
|
+
@change=${(e) => {
|
|
127
|
+
this.touched = !0, this.value = e.target.value, e.stopImmediatePropagation();
|
|
128
|
+
}}
|
|
129
|
+
@input=${(e) => {
|
|
130
|
+
this.onInput(), e.stopImmediatePropagation();
|
|
131
|
+
}}
|
|
132
|
+
@focus=${(e) => {
|
|
133
|
+
this.onFocus(), e.stopImmediatePropagation();
|
|
134
|
+
}}
|
|
135
|
+
@blur=${(e) => {
|
|
136
|
+
this.onBlur(), e.stopImmediatePropagation();
|
|
137
|
+
}}
|
|
138
|
+
${d(this.inputRef)}
|
|
139
|
+
>
|
|
140
|
+
${this._options.length > 0 ? this._options.map(
|
|
141
|
+
(e) => r`<option
|
|
142
|
+
value=${e.value}
|
|
143
|
+
?selected=${this.value == e.value || e.selected}
|
|
144
|
+
?disabled=${e.disabled}
|
|
145
|
+
?hidden=${e.hidden}
|
|
146
|
+
>
|
|
147
|
+
${e.label}
|
|
148
|
+
</option>`
|
|
149
|
+
) : ""}
|
|
150
|
+
</select>
|
|
151
|
+
<div class="pkt-contents" ${d(this.helptextSlot)} name="helptext" slot="helptext"></div>
|
|
152
|
+
</pkt-input-wrapper>
|
|
153
|
+
`;
|
|
154
|
+
}
|
|
155
|
+
returnNumberOrNull(t) {
|
|
156
|
+
return t == null || isNaN(t) ? null : t;
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
a([
|
|
160
|
+
c({ type: Array, attribute: "options" })
|
|
161
|
+
], h.prototype, "_optionsProp", 2);
|
|
162
|
+
a([
|
|
163
|
+
c({ type: String })
|
|
164
|
+
], h.prototype, "value", 2);
|
|
165
|
+
a([
|
|
166
|
+
f()
|
|
167
|
+
], h.prototype, "_options", 2);
|
|
168
|
+
h = a([
|
|
169
|
+
v("pkt-select")
|
|
170
|
+
], h);
|
|
171
|
+
export {
|
|
172
|
+
h as P
|
|
173
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oslokommune/punkt-elements",
|
|
3
|
-
"version": "13.5.
|
|
3
|
+
"version": "13.5.13",
|
|
4
4
|
"description": "Komponentbiblioteket til Punkt, et designsystem laget av Oslo Origo",
|
|
5
5
|
"homepage": "https://punkt.oslo.kommune.no",
|
|
6
6
|
"author": "Team Designsystem, Oslo Origo",
|
|
@@ -73,5 +73,5 @@
|
|
|
73
73
|
"url": "https://github.com/oslokommune/punkt/issues"
|
|
74
74
|
},
|
|
75
75
|
"license": "MIT",
|
|
76
|
-
"gitHead": "
|
|
76
|
+
"gitHead": "1a1aad782fd8d6b632557869c3c4cd9ad2f663cf"
|
|
77
77
|
}
|
|
@@ -43,7 +43,7 @@ export class PktSelect extends PktInputElement implements IPktSelect {
|
|
|
43
43
|
private inputRef: Ref<HTMLSelectElement> = createRef()
|
|
44
44
|
private helptextSlot: Ref<HTMLElement> = createRef()
|
|
45
45
|
|
|
46
|
-
@property({ type: Array })
|
|
46
|
+
@property({ type: Array, attribute: 'options' }) private _optionsProp: TSelectOption[] = []
|
|
47
47
|
@property({ type: String }) value: string = ''
|
|
48
48
|
|
|
49
49
|
@state() private _options: TSelectOption[] = []
|
|
@@ -51,6 +51,19 @@ export class PktSelect extends PktInputElement implements IPktSelect {
|
|
|
51
51
|
public selectedIndex: number | null = -1
|
|
52
52
|
public selectedOptions: HTMLCollectionOf<HTMLOptionElement> | undefined = undefined
|
|
53
53
|
|
|
54
|
+
// Getter and setter for options to expose the actual parsed options
|
|
55
|
+
public get options(): TSelectOption[] {
|
|
56
|
+
return this._options.map((option) => ({
|
|
57
|
+
...option,
|
|
58
|
+
selected: option.value === this.value,
|
|
59
|
+
}))
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
public set options(value: TSelectOption[]) {
|
|
63
|
+
this._optionsProp = value
|
|
64
|
+
this.requestUpdate('_optionsProp', this._options)
|
|
65
|
+
}
|
|
66
|
+
|
|
54
67
|
constructor() {
|
|
55
68
|
super()
|
|
56
69
|
this.optionsController = new PktOptionsSlotController(this)
|
|
@@ -58,11 +71,10 @@ export class PktSelect extends PktInputElement implements IPktSelect {
|
|
|
58
71
|
this.slotController.skipOptions = true
|
|
59
72
|
}
|
|
60
73
|
|
|
61
|
-
// Used for initilization
|
|
62
74
|
connectedCallback(): void {
|
|
63
75
|
super.connectedCallback()
|
|
64
76
|
|
|
65
|
-
const optionsReceivedFromProps = this.
|
|
77
|
+
const optionsReceivedFromProps = this._optionsProp.length > 0
|
|
66
78
|
const checkIfOptionNodesInSlot =
|
|
67
79
|
this.optionsController.nodes.length && this.optionsController.nodes.length > 0
|
|
68
80
|
|
|
@@ -83,7 +95,7 @@ export class PktSelect extends PktInputElement implements IPktSelect {
|
|
|
83
95
|
this._options.push(option)
|
|
84
96
|
})
|
|
85
97
|
} else {
|
|
86
|
-
this._options = this.
|
|
98
|
+
this._options = this._optionsProp
|
|
87
99
|
this._options.forEach((option) => {
|
|
88
100
|
if (option.selected && !this.value) {
|
|
89
101
|
this.value = option.value
|
|
@@ -94,17 +106,32 @@ export class PktSelect extends PktInputElement implements IPktSelect {
|
|
|
94
106
|
|
|
95
107
|
// Support native Select method `add`
|
|
96
108
|
public add(item: HTMLOptionElement, before?: HTMLOptionElement | number) {
|
|
97
|
-
|
|
98
|
-
this._options.push({
|
|
109
|
+
const newOption = {
|
|
99
110
|
value: item.value || item.text,
|
|
100
111
|
label: item.text || item.value,
|
|
101
112
|
selected: item.selected,
|
|
102
113
|
disabled: item.disabled,
|
|
103
|
-
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Add to our internal options array at the correct position
|
|
117
|
+
if (before === undefined) {
|
|
118
|
+
this._options.push(newOption)
|
|
119
|
+
} else if (typeof before === 'number') {
|
|
120
|
+
this._options.splice(before, 0, newOption)
|
|
121
|
+
} else {
|
|
122
|
+
// If before is an HTMLOptionElement, find its index in our options
|
|
123
|
+
const beforeValue = before.value || before.text
|
|
124
|
+
const beforeIndex = this._options.findIndex((opt) => opt.value === beforeValue)
|
|
125
|
+
if (beforeIndex >= 0) {
|
|
126
|
+
this._options.splice(beforeIndex, 0, newOption)
|
|
127
|
+
} else {
|
|
128
|
+
this._options.push(newOption)
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
104
132
|
if (item.selected) {
|
|
105
133
|
this.value = item.value || item.text
|
|
106
|
-
this.selectedIndex = this.
|
|
107
|
-
this.selectedOptions = this.inputRef.value?.selectedOptions
|
|
134
|
+
this.selectedIndex = this._options.findIndex((opt) => opt.value === this.value)
|
|
108
135
|
}
|
|
109
136
|
this.requestUpdate()
|
|
110
137
|
}
|
|
@@ -115,7 +142,8 @@ export class PktSelect extends PktInputElement implements IPktSelect {
|
|
|
115
142
|
if (this.selectedIndex === item) {
|
|
116
143
|
this.value = this._options[0]?.value || ''
|
|
117
144
|
}
|
|
118
|
-
this.
|
|
145
|
+
this._options.splice(item, 1)
|
|
146
|
+
this.requestUpdate()
|
|
119
147
|
}
|
|
120
148
|
}
|
|
121
149
|
|
|
@@ -131,7 +159,9 @@ export class PktSelect extends PktInputElement implements IPktSelect {
|
|
|
131
159
|
|
|
132
160
|
// Support native Select method `showPicker`
|
|
133
161
|
public showPicker() {
|
|
134
|
-
this.inputRef.value
|
|
162
|
+
if (this.inputRef.value && 'showPicker' in this.inputRef.value) {
|
|
163
|
+
;(this.inputRef.value as any).showPicker()
|
|
164
|
+
}
|
|
135
165
|
}
|
|
136
166
|
|
|
137
167
|
public attributeChangedCallback(name: string, _old: string, value: string): void {
|
|
@@ -141,7 +171,7 @@ export class PktSelect extends PktInputElement implements IPktSelect {
|
|
|
141
171
|
if (name === 'value' && this.value !== _old) {
|
|
142
172
|
this.selectedIndex = this.touched
|
|
143
173
|
? this.returnNumberOrNull(this.inputRef.value?.selectedIndex)
|
|
144
|
-
: this.
|
|
174
|
+
: this._options.findIndex((option) => option.value === value)
|
|
145
175
|
this.selectedOptions = this.inputRef.value?.selectedOptions
|
|
146
176
|
this.valueChanged(value, _old)
|
|
147
177
|
}
|
|
@@ -150,8 +180,8 @@ export class PktSelect extends PktInputElement implements IPktSelect {
|
|
|
150
180
|
|
|
151
181
|
update(changedProperties: PropertyValues) {
|
|
152
182
|
super.update(changedProperties)
|
|
153
|
-
if (changedProperties.has('
|
|
154
|
-
this._options = this.
|
|
183
|
+
if (changedProperties.has('_optionsProp') && this._optionsProp.length > 0) {
|
|
184
|
+
this._options = this._optionsProp
|
|
155
185
|
this.requestUpdate('_options')
|
|
156
186
|
|
|
157
187
|
// If no value is set and we have options, set to first option
|
|
@@ -163,7 +193,7 @@ export class PktSelect extends PktInputElement implements IPktSelect {
|
|
|
163
193
|
if (changedProperties.has('value') && this.value !== changedProperties.get('value')) {
|
|
164
194
|
this.selectedIndex = this.touched
|
|
165
195
|
? this.returnNumberOrNull(this.inputRef.value?.selectedIndex)
|
|
166
|
-
: this.
|
|
196
|
+
: this._options.findIndex((option) => option.value === this.value)
|
|
167
197
|
this.selectedOptions = this.inputRef.value?.selectedOptions
|
|
168
198
|
this.valueChanged(this.value, changedProperties.get('value'))
|
|
169
199
|
}
|
|
@@ -174,8 +204,8 @@ export class PktSelect extends PktInputElement implements IPktSelect {
|
|
|
174
204
|
|
|
175
205
|
protected firstUpdated(_changedProperties: PropertyValues): void {
|
|
176
206
|
super.firstUpdated(_changedProperties)
|
|
177
|
-
if (this.
|
|
178
|
-
this._options = this.
|
|
207
|
+
if (this._optionsProp.length) {
|
|
208
|
+
this._options = this._optionsProp
|
|
179
209
|
}
|
|
180
210
|
// If no options are selected, set value and selectedIndex to the first option
|
|
181
211
|
if (!this.value && this._options.length > 0) {
|
package/dist/select-CD6Zn8YH.cjs
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"use strict";const h=require("./element-6DBpyGQm.cjs"),p=require("./state-DPobt-Yz.cjs"),r=require("./ref-iJtiv3o2.cjs"),l=require("./if-defined-Cni-RHLS.cjs"),d=require("./input-element-C4xJoM-X.cjs"),c=require("./pkt-options-controller-CiuBG6Lt.cjs"),v=require("./pkt-slot-controller-BzddBp7z.cjs");require("./input-wrapper-CZ-a00V7.cjs");var f=Object.defineProperty,b=Object.getOwnPropertyDescriptor,a=(u,t,e,s)=>{for(var i=s>1?void 0:s?b(t,e):t,o=u.length-1,n;o>=0;o--)(n=u[o])&&(i=(s?n(t,e,i):n(i))||i);return s&&i&&f(t,e,i),i};exports.PktSelect=class extends d.PktInputElement{constructor(){super(),this.inputRef=r.e(),this.helptextSlot=r.e(),this.options=[],this.value="",this._options=[],this.selectedIndex=-1,this.selectedOptions=void 0,this.optionsController=new c.PktOptionsSlotController(this),this.slotController=new v.PktSlotController(this,this.helptextSlot),this.slotController.skipOptions=!0}connectedCallback(){super.connectedCallback();const t=this.options.length>0,e=this.optionsController.nodes.length&&this.optionsController.nodes.length>0;!t&&e?this.optionsController.nodes.forEach(s=>{const i={value:s.hasAttribute("value")?s.getAttribute("value")??"":s.textContent??"",label:s.textContent||s.getAttribute("value")||"",disabled:s.hasAttribute("disabled"),selected:s.hasAttribute("selected"),hidden:s.hasAttribute("data-hidden")};s.getAttribute("selected")&&!this.value&&(this.value=i.value),this._options.push(i)}):(this._options=this.options,this._options.forEach(s=>{s.selected&&!this.value&&(this.value=s.value)}))}add(t,e){var s,i,o;(s=this.inputRef.value)==null||s.add(t,e),this._options.push({value:t.value||t.text,label:t.text||t.value,selected:t.selected,disabled:t.disabled}),t.selected&&(this.value=t.value||t.text,this.selectedIndex=this.returnNumberOrNull((i=this.inputRef.value)==null?void 0:i.selectedIndex),this.selectedOptions=(o=this.inputRef.value)==null?void 0:o.selectedOptions),this.requestUpdate()}remove(t){var e,s;typeof t=="number"&&(this.selectedIndex===t&&(this.value=((e=this._options[0])==null?void 0:e.value)||""),(s=this.inputRef.value)==null||s.remove(t))}item(t){var e;return(e=this.inputRef.value)==null?void 0:e.item(t)}namedItem(t){var e;return(e=this.inputRef.value)==null?void 0:e.namedItem(t)}showPicker(){var t;(t=this.inputRef.value)==null||t.showPicker()}attributeChangedCallback(t,e,s){var i,o;t==="options"&&(this._options=s?JSON.parse(s):[]),t==="value"&&this.value!==e&&(this.selectedIndex=this.touched?this.returnNumberOrNull((i=this.inputRef.value)==null?void 0:i.selectedIndex):this.options.findIndex(n=>n.value===s),this.selectedOptions=(o=this.inputRef.value)==null?void 0:o.selectedOptions,this.valueChanged(s,e)),super.attributeChangedCallback(t,e,s)}update(t){var e,s;super.update(t),t.has("options")&&(this._options=this.options,this.requestUpdate("_options"),!this.value&&this._options.length>0&&(this.value=this._options[0].value,this.selectedIndex=0)),t.has("value")&&this.value!==t.get("value")&&(this.selectedIndex=this.touched?this.returnNumberOrNull((e=this.inputRef.value)==null?void 0:e.selectedIndex):this.options.findIndex(i=>i.value===this.value),this.selectedOptions=(s=this.inputRef.value)==null?void 0:s.selectedOptions,this.valueChanged(this.value,t.get("value"))),t.has("id")&&!this.name&&this.id&&(this.name=this.id)}firstUpdated(t){var e;super.firstUpdated(t),this.options.length&&(this._options=this.options),!this.value&&this._options.length>0?(this.value=this._options[0].value,this.selectedIndex=0):this.selectedIndex=this._options.findIndex(s=>s.value===this.value),this.selectedOptions=(e=this.inputRef.value)==null?void 0:e.selectedOptions}render(){const t=`pkt-input ${this.fullwidth?"pkt-input--fullwidth":""}`;return h.x`
|
|
2
|
-
<pkt-input-wrapper
|
|
3
|
-
?counter=${this.counter}
|
|
4
|
-
?disabled=${this.disabled}
|
|
5
|
-
?hasError=${this.hasError}
|
|
6
|
-
?hasFieldset=${this.hasFieldset}
|
|
7
|
-
?inline=${this.inline}
|
|
8
|
-
?optionalTag=${this.optionalTag}
|
|
9
|
-
?requiredTag=${this.requiredTag}
|
|
10
|
-
?useWrapper=${this.useWrapper}
|
|
11
|
-
ariaDescribedBy=${l.o(this.ariaDescribedBy)}
|
|
12
|
-
class="pkt-select"
|
|
13
|
-
errorMessage=${l.o(this.errorMessage)}
|
|
14
|
-
forId=${this.id+"-input"}
|
|
15
|
-
helptext=${l.o(this.helptext)}
|
|
16
|
-
helptextDropdown=${l.o(this.helptextDropdown)}
|
|
17
|
-
helptextDropdownButton=${l.o(this.helptextDropdownButton)}
|
|
18
|
-
label=${l.o(this.label)}
|
|
19
|
-
optionalText=${l.o(this.optionalText)}
|
|
20
|
-
requiredText=${l.o(this.requiredText)}
|
|
21
|
-
tagText=${l.o(this.tagText)}
|
|
22
|
-
>
|
|
23
|
-
<select
|
|
24
|
-
class=${t}
|
|
25
|
-
aria-invalid=${this.hasError}
|
|
26
|
-
aria-errormessage=${`${this.id}-error`}
|
|
27
|
-
aria-labelledby=${l.o(this.ariaLabelledby)}
|
|
28
|
-
?disabled=${this.disabled}
|
|
29
|
-
id=${this.id+"-input"}
|
|
30
|
-
name=${(this.name||this.id)+"-input"}
|
|
31
|
-
value=${this.value}
|
|
32
|
-
@change=${e=>{this.touched=!0,this.value=e.target.value,e.stopImmediatePropagation()}}
|
|
33
|
-
@input=${e=>{this.onInput(),e.stopImmediatePropagation()}}
|
|
34
|
-
@focus=${e=>{this.onFocus(),e.stopImmediatePropagation()}}
|
|
35
|
-
@blur=${e=>{this.onBlur(),e.stopImmediatePropagation()}}
|
|
36
|
-
${r.n(this.inputRef)}
|
|
37
|
-
>
|
|
38
|
-
${this._options.length>0?this._options.map(e=>h.x`<option
|
|
39
|
-
value=${e.value}
|
|
40
|
-
?selected=${this.value==e.value||e.selected}
|
|
41
|
-
?disabled=${e.disabled}
|
|
42
|
-
?hidden=${e.hidden}
|
|
43
|
-
>
|
|
44
|
-
${e.label}
|
|
45
|
-
</option>`):""}
|
|
46
|
-
</select>
|
|
47
|
-
<div class="pkt-contents" ${r.n(this.helptextSlot)} name="helptext" slot="helptext"></div>
|
|
48
|
-
</pkt-input-wrapper>
|
|
49
|
-
`}returnNumberOrNull(t){return t==null||isNaN(t)?null:t}};a([h.n({type:Array})],exports.PktSelect.prototype,"options",2);a([h.n({type:String})],exports.PktSelect.prototype,"value",2);a([p.r()],exports.PktSelect.prototype,"_options",2);exports.PktSelect=a([h.t("pkt-select")],exports.PktSelect);
|
package/dist/select-dcaJHvmR.js
DELETED
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
import { x as p, n as c, a as v } from "./element-CgEWt74-.js";
|
|
2
|
-
import { r as f } from "./state-Bo2bck5_.js";
|
|
3
|
-
import { e as u, n as d } from "./ref-BBYSqgeW.js";
|
|
4
|
-
import { o } from "./if-defined-CmuO4Vz9.js";
|
|
5
|
-
import { P as b } from "./input-element-NnrDmp4r.js";
|
|
6
|
-
import { P as $ } from "./pkt-options-controller-CZO1nxZ8.js";
|
|
7
|
-
import { P as x } from "./pkt-slot-controller-BPGj-LC5.js";
|
|
8
|
-
import "./input-wrapper-Dr__Sxql.js";
|
|
9
|
-
var m = Object.defineProperty, g = Object.getOwnPropertyDescriptor, n = (t, e, s, i) => {
|
|
10
|
-
for (var l = i > 1 ? void 0 : i ? g(e, s) : e, h = t.length - 1, r; h >= 0; h--)
|
|
11
|
-
(r = t[h]) && (l = (i ? r(e, s, l) : r(l)) || l);
|
|
12
|
-
return i && l && m(e, s, l), l;
|
|
13
|
-
};
|
|
14
|
-
let a = class extends b {
|
|
15
|
-
constructor() {
|
|
16
|
-
super(), this.inputRef = u(), this.helptextSlot = u(), this.options = [], this.value = "", this._options = [], this.selectedIndex = -1, this.selectedOptions = void 0, this.optionsController = new $(this), this.slotController = new x(this, this.helptextSlot), this.slotController.skipOptions = !0;
|
|
17
|
-
}
|
|
18
|
-
// Used for initilization
|
|
19
|
-
connectedCallback() {
|
|
20
|
-
super.connectedCallback();
|
|
21
|
-
const t = this.options.length > 0, e = this.optionsController.nodes.length && this.optionsController.nodes.length > 0;
|
|
22
|
-
!t && e ? this.optionsController.nodes.forEach((s) => {
|
|
23
|
-
const i = {
|
|
24
|
-
value: s.hasAttribute("value") ? s.getAttribute("value") ?? "" : s.textContent ?? "",
|
|
25
|
-
label: s.textContent || s.getAttribute("value") || "",
|
|
26
|
-
disabled: s.hasAttribute("disabled"),
|
|
27
|
-
selected: s.hasAttribute("selected"),
|
|
28
|
-
hidden: s.hasAttribute("data-hidden")
|
|
29
|
-
};
|
|
30
|
-
s.getAttribute("selected") && !this.value && (this.value = i.value), this._options.push(i);
|
|
31
|
-
}) : (this._options = this.options, this._options.forEach((s) => {
|
|
32
|
-
s.selected && !this.value && (this.value = s.value);
|
|
33
|
-
}));
|
|
34
|
-
}
|
|
35
|
-
// Support native Select method `add`
|
|
36
|
-
add(t, e) {
|
|
37
|
-
var s, i, l;
|
|
38
|
-
(s = this.inputRef.value) == null || s.add(t, e), this._options.push({
|
|
39
|
-
value: t.value || t.text,
|
|
40
|
-
label: t.text || t.value,
|
|
41
|
-
selected: t.selected,
|
|
42
|
-
disabled: t.disabled
|
|
43
|
-
}), t.selected && (this.value = t.value || t.text, this.selectedIndex = this.returnNumberOrNull((i = this.inputRef.value) == null ? void 0 : i.selectedIndex), this.selectedOptions = (l = this.inputRef.value) == null ? void 0 : l.selectedOptions), this.requestUpdate();
|
|
44
|
-
}
|
|
45
|
-
// Support native Select method `remove`
|
|
46
|
-
remove(t) {
|
|
47
|
-
var e, s;
|
|
48
|
-
typeof t == "number" && (this.selectedIndex === t && (this.value = ((e = this._options[0]) == null ? void 0 : e.value) || ""), (s = this.inputRef.value) == null || s.remove(t));
|
|
49
|
-
}
|
|
50
|
-
// Support native Select method `item`
|
|
51
|
-
item(t) {
|
|
52
|
-
var e;
|
|
53
|
-
return (e = this.inputRef.value) == null ? void 0 : e.item(t);
|
|
54
|
-
}
|
|
55
|
-
// Support native Select method `namedItem`
|
|
56
|
-
namedItem(t) {
|
|
57
|
-
var e;
|
|
58
|
-
return (e = this.inputRef.value) == null ? void 0 : e.namedItem(t);
|
|
59
|
-
}
|
|
60
|
-
// Support native Select method `showPicker`
|
|
61
|
-
showPicker() {
|
|
62
|
-
var t;
|
|
63
|
-
(t = this.inputRef.value) == null || t.showPicker();
|
|
64
|
-
}
|
|
65
|
-
attributeChangedCallback(t, e, s) {
|
|
66
|
-
var i, l;
|
|
67
|
-
t === "options" && (this._options = s ? JSON.parse(s) : []), t === "value" && this.value !== e && (this.selectedIndex = this.touched ? this.returnNumberOrNull((i = this.inputRef.value) == null ? void 0 : i.selectedIndex) : this.options.findIndex((h) => h.value === s), this.selectedOptions = (l = this.inputRef.value) == null ? void 0 : l.selectedOptions, this.valueChanged(s, e)), super.attributeChangedCallback(t, e, s);
|
|
68
|
-
}
|
|
69
|
-
update(t) {
|
|
70
|
-
var e, s;
|
|
71
|
-
super.update(t), t.has("options") && (this._options = this.options, this.requestUpdate("_options"), !this.value && this._options.length > 0 && (this.value = this._options[0].value, this.selectedIndex = 0)), t.has("value") && this.value !== t.get("value") && (this.selectedIndex = this.touched ? this.returnNumberOrNull((e = this.inputRef.value) == null ? void 0 : e.selectedIndex) : this.options.findIndex((i) => i.value === this.value), this.selectedOptions = (s = this.inputRef.value) == null ? void 0 : s.selectedOptions, this.valueChanged(this.value, t.get("value"))), t.has("id") && !this.name && this.id && (this.name = this.id);
|
|
72
|
-
}
|
|
73
|
-
firstUpdated(t) {
|
|
74
|
-
var e;
|
|
75
|
-
super.firstUpdated(t), this.options.length && (this._options = this.options), !this.value && this._options.length > 0 ? (this.value = this._options[0].value, this.selectedIndex = 0) : this.selectedIndex = this._options.findIndex((s) => s.value === this.value), this.selectedOptions = (e = this.inputRef.value) == null ? void 0 : e.selectedOptions;
|
|
76
|
-
}
|
|
77
|
-
render() {
|
|
78
|
-
const t = `pkt-input ${this.fullwidth ? "pkt-input--fullwidth" : ""}`;
|
|
79
|
-
return p`
|
|
80
|
-
<pkt-input-wrapper
|
|
81
|
-
?counter=${this.counter}
|
|
82
|
-
?disabled=${this.disabled}
|
|
83
|
-
?hasError=${this.hasError}
|
|
84
|
-
?hasFieldset=${this.hasFieldset}
|
|
85
|
-
?inline=${this.inline}
|
|
86
|
-
?optionalTag=${this.optionalTag}
|
|
87
|
-
?requiredTag=${this.requiredTag}
|
|
88
|
-
?useWrapper=${this.useWrapper}
|
|
89
|
-
ariaDescribedBy=${o(this.ariaDescribedBy)}
|
|
90
|
-
class="pkt-select"
|
|
91
|
-
errorMessage=${o(this.errorMessage)}
|
|
92
|
-
forId=${this.id + "-input"}
|
|
93
|
-
helptext=${o(this.helptext)}
|
|
94
|
-
helptextDropdown=${o(this.helptextDropdown)}
|
|
95
|
-
helptextDropdownButton=${o(this.helptextDropdownButton)}
|
|
96
|
-
label=${o(this.label)}
|
|
97
|
-
optionalText=${o(this.optionalText)}
|
|
98
|
-
requiredText=${o(this.requiredText)}
|
|
99
|
-
tagText=${o(this.tagText)}
|
|
100
|
-
>
|
|
101
|
-
<select
|
|
102
|
-
class=${t}
|
|
103
|
-
aria-invalid=${this.hasError}
|
|
104
|
-
aria-errormessage=${`${this.id}-error`}
|
|
105
|
-
aria-labelledby=${o(this.ariaLabelledby)}
|
|
106
|
-
?disabled=${this.disabled}
|
|
107
|
-
id=${this.id + "-input"}
|
|
108
|
-
name=${(this.name || this.id) + "-input"}
|
|
109
|
-
value=${this.value}
|
|
110
|
-
@change=${(e) => {
|
|
111
|
-
this.touched = !0, this.value = e.target.value, e.stopImmediatePropagation();
|
|
112
|
-
}}
|
|
113
|
-
@input=${(e) => {
|
|
114
|
-
this.onInput(), e.stopImmediatePropagation();
|
|
115
|
-
}}
|
|
116
|
-
@focus=${(e) => {
|
|
117
|
-
this.onFocus(), e.stopImmediatePropagation();
|
|
118
|
-
}}
|
|
119
|
-
@blur=${(e) => {
|
|
120
|
-
this.onBlur(), e.stopImmediatePropagation();
|
|
121
|
-
}}
|
|
122
|
-
${d(this.inputRef)}
|
|
123
|
-
>
|
|
124
|
-
${this._options.length > 0 ? this._options.map(
|
|
125
|
-
(e) => p`<option
|
|
126
|
-
value=${e.value}
|
|
127
|
-
?selected=${this.value == e.value || e.selected}
|
|
128
|
-
?disabled=${e.disabled}
|
|
129
|
-
?hidden=${e.hidden}
|
|
130
|
-
>
|
|
131
|
-
${e.label}
|
|
132
|
-
</option>`
|
|
133
|
-
) : ""}
|
|
134
|
-
</select>
|
|
135
|
-
<div class="pkt-contents" ${d(this.helptextSlot)} name="helptext" slot="helptext"></div>
|
|
136
|
-
</pkt-input-wrapper>
|
|
137
|
-
`;
|
|
138
|
-
}
|
|
139
|
-
returnNumberOrNull(t) {
|
|
140
|
-
return t == null || isNaN(t) ? null : t;
|
|
141
|
-
}
|
|
142
|
-
};
|
|
143
|
-
n([
|
|
144
|
-
c({ type: Array })
|
|
145
|
-
], a.prototype, "options", 2);
|
|
146
|
-
n([
|
|
147
|
-
c({ type: String })
|
|
148
|
-
], a.prototype, "value", 2);
|
|
149
|
-
n([
|
|
150
|
-
f()
|
|
151
|
-
], a.prototype, "_options", 2);
|
|
152
|
-
a = n([
|
|
153
|
-
v("pkt-select")
|
|
154
|
-
], a);
|
|
155
|
-
export {
|
|
156
|
-
a as P
|
|
157
|
-
};
|