@politiet/sheriff-web-components 1.0.0-rc.8 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/dist/react-wrappers/SDSCheckboxGroupWrapper.d.ts +1 -1
  2. package/dist/react-wrappers/SDSCheckboxGroupWrapper.js +1 -1
  3. package/dist/react-wrappers/SDSCheckboxGroupWrapper.js.map +1 -1
  4. package/dist/react-wrappers/SDSRadioGroupWrapper.d.ts +1 -1
  5. package/dist/react-wrappers/SDSRadioGroupWrapper.js +1 -1
  6. package/dist/react-wrappers/SDSRadioGroupWrapper.js.map +1 -1
  7. package/dist/sds-checkbox/sds-checkbox.d.ts +6 -1
  8. package/dist/sds-checkbox/sds-checkbox.d.ts.map +1 -1
  9. package/dist/sds-checkbox/sds-checkbox.js +34 -4
  10. package/dist/sds-checkbox/sds-checkbox.js.map +1 -1
  11. package/dist/sds-checkbox-group/sds-checkbox-group.d.ts +2 -1
  12. package/dist/sds-checkbox-group/sds-checkbox-group.d.ts.map +1 -1
  13. package/dist/sds-checkbox-group/sds-checkbox-group.js +9 -7
  14. package/dist/sds-checkbox-group/sds-checkbox-group.js.map +1 -1
  15. package/dist/sds-chip/sds-chip.d.ts.map +1 -1
  16. package/dist/sds-chip/sds-chip.js +0 -1
  17. package/dist/sds-chip/sds-chip.js.map +1 -1
  18. package/dist/sds-icon/sds-icon-loader.js +2 -2
  19. package/dist/sds-icon/sds-icon-loader.js.map +1 -1
  20. package/dist/sds-radio/sds-radio.d.ts +5 -3
  21. package/dist/sds-radio/sds-radio.d.ts.map +1 -1
  22. package/dist/sds-radio/sds-radio.js +41 -19
  23. package/dist/sds-radio/sds-radio.js.map +1 -1
  24. package/dist/sds-radio-group/sds-radio-group.d.ts +2 -1
  25. package/dist/sds-radio-group/sds-radio-group.d.ts.map +1 -1
  26. package/dist/sds-radio-group/sds-radio-group.js +7 -7
  27. package/dist/sds-radio-group/sds-radio-group.js.map +1 -1
  28. package/dist/sds-switch/sds-switch.d.ts +1 -2
  29. package/dist/sds-switch/sds-switch.d.ts.map +1 -1
  30. package/dist/sds-switch/sds-switch.js +8 -15
  31. package/dist/sds-switch/sds-switch.js.map +1 -1
  32. package/dist/sds-textfield/sds-textfield.d.ts +28 -19
  33. package/dist/sds-textfield/sds-textfield.d.ts.map +1 -1
  34. package/dist/sds-textfield/sds-textfield.js +121 -85
  35. package/dist/sds-textfield/sds-textfield.js.map +1 -1
  36. package/dist/sheriff-web-components.js +220 -144
  37. package/package.json +3 -3
@@ -1041,6 +1041,7 @@ let SDSCheckbox = class extends r$2 {
1041
1041
  this.checked = false;
1042
1042
  this.disabled = false;
1043
1043
  this.error = false;
1044
+ this.required = false;
1044
1045
  this._initialChecked = false;
1045
1046
  this._handleChange = (event) => {
1046
1047
  event.stopImmediatePropagation();
@@ -1048,9 +1049,9 @@ let SDSCheckbox = class extends r$2 {
1048
1049
  const elem = event.target;
1049
1050
  this.checked = elem.checked;
1050
1051
  this.internals.setFormValue(elem.checked ? elem.value : "");
1052
+ this._validate();
1051
1053
  this.dispatchEvent(
1052
1054
  new CustomEvent("change", {
1053
- detail: { checked: this.checked, value: elem.value },
1054
1055
  bubbles: true,
1055
1056
  composed: true
1056
1057
  })
@@ -1061,7 +1062,6 @@ let SDSCheckbox = class extends r$2 {
1061
1062
  event.stopImmediatePropagation();
1062
1063
  this.dispatchEvent(
1063
1064
  new CustomEvent("focus", {
1064
- detail: { checked: this.checked },
1065
1065
  bubbles: true,
1066
1066
  composed: true
1067
1067
  })
@@ -1071,7 +1071,6 @@ let SDSCheckbox = class extends r$2 {
1071
1071
  event.stopImmediatePropagation();
1072
1072
  this.dispatchEvent(
1073
1073
  new CustomEvent("blur", {
1074
- detail: { checked: this.checked },
1075
1074
  bubbles: true,
1076
1075
  composed: true
1077
1076
  })
@@ -1088,11 +1087,28 @@ let SDSCheckbox = class extends r$2 {
1088
1087
  this.internals.setFormValue(this.value ? this.value : "");
1089
1088
  }
1090
1089
  }
1090
+ firstUpdated(_changedProperties) {
1091
+ super.firstUpdated(_changedProperties);
1092
+ if (this.control) {
1093
+ this.control.required = this.required;
1094
+ }
1095
+ this._validate();
1096
+ }
1091
1097
  formResetCallback() {
1092
1098
  this.checked = this._initialChecked;
1093
- this.control.checked = this._initialChecked;
1099
+ if (this.control) {
1100
+ this.control.checked = this._initialChecked;
1101
+ }
1094
1102
  const resetValue = this.checked && this.value ? this.value : "";
1095
1103
  this.internals.setFormValue(resetValue);
1104
+ this._validate();
1105
+ }
1106
+ _validate() {
1107
+ if (this.required && !this.checked) {
1108
+ this.internals.setValidity({ valueMissing: true }, this.control.validationMessage, this.control);
1109
+ } else {
1110
+ this.internals.setValidity({});
1111
+ }
1096
1112
  }
1097
1113
  focus() {
1098
1114
  if (!this.disabled) this.shadowRoot?.querySelector("input")?.focus();
@@ -1103,6 +1119,15 @@ let SDSCheckbox = class extends r$2 {
1103
1119
  click() {
1104
1120
  if (!this.disabled) this.shadowRoot?.querySelector("input")?.click();
1105
1121
  }
1122
+ updated(changedProperties) {
1123
+ super.updated(changedProperties);
1124
+ if (changedProperties.has("required") && this.control) {
1125
+ this.control.required = this.required;
1126
+ }
1127
+ if (changedProperties.has("checked")) {
1128
+ this._validate();
1129
+ }
1130
+ }
1106
1131
  render() {
1107
1132
  const checkboxClasses = {
1108
1133
  "sds-checkbox": true,
@@ -1122,6 +1147,7 @@ let SDSCheckbox = class extends r$2 {
1122
1147
  value="${o$1(this.value)}"
1123
1148
  ?checked="${this.checked}"
1124
1149
  ?disabled="${this.disabled}"
1150
+ ?required="${this.required}"
1125
1151
  @change="${this._handleChange}"
1126
1152
  @focus="${this._handleFocus}"
1127
1153
  @blur="${this._handleBlur}"
@@ -1153,6 +1179,9 @@ __decorateClass$g([
1153
1179
  __decorateClass$g([
1154
1180
  n2({ type: Boolean, reflect: true })
1155
1181
  ], SDSCheckbox.prototype, "error", 2);
1182
+ __decorateClass$g([
1183
+ n2({ type: Boolean, reflect: true })
1184
+ ], SDSCheckbox.prototype, "required", 2);
1156
1185
  __decorateClass$g([
1157
1186
  e$3("#control")
1158
1187
  ], SDSCheckbox.prototype, "control", 2);
@@ -1243,7 +1272,7 @@ const loadLocalIcons = (name) => import(`@politiet/sheriff-icons/dist/assets/${n
1243
1272
  }).catch((error) => {
1244
1273
  console.log(error);
1245
1274
  });
1246
- const loadCdnIcons = (name) => fetch(`https://unpkg.com/@politiet/sheriff-icons/dist/assets/${name}.svg`).then((response) => {
1275
+ const loadCdnIcons = (name) => fetch(`https://cdn.jsdelivr.net/npm/@politiet/sheriff-icons/dist/assets/${name}.svg`).then((response) => {
1247
1276
  if (!response.ok) {
1248
1277
  throw new TypeError(`Sheriff: unknown icon: '${name}'`);
1249
1278
  }
@@ -1269,7 +1298,7 @@ class SDSIconLoader {
1269
1298
  return;
1270
1299
  }
1271
1300
  if (!cached) {
1272
- cached = this.resolver(name).catch(() => "Loading icon failed").then((svg) => {
1301
+ cached = this.resolver(name).catch(() => "").then((svg) => {
1273
1302
  this.cache.set(name, svg);
1274
1303
  return svg;
1275
1304
  });
@@ -1389,21 +1418,23 @@ var __decorateClass$e = (decorators, target, key, kind) => {
1389
1418
  let SDSCheckboxGroup = class extends r$2 {
1390
1419
  constructor() {
1391
1420
  super(...arguments);
1392
- this.selectedValues = [];
1421
+ this._selectedValues = [];
1393
1422
  this._handleCheckboxChange = (event) => {
1394
1423
  const checkbox = event.target;
1395
1424
  const value = checkbox.value;
1396
1425
  const isChecked = checkbox.checked;
1397
- this.selectedValues = isChecked ? [...this.selectedValues, value] : this.selectedValues.filter((v2) => v2 !== value);
1426
+ this._selectedValues = isChecked ? [...this._selectedValues, value] : this._selectedValues.filter((v2) => v2 !== value);
1398
1427
  this.dispatchEvent(
1399
- new CustomEvent("change", {
1400
- detail: { selectedValues: this.selectedValues },
1428
+ new CustomEvent("sds-update", {
1401
1429
  bubbles: true,
1402
1430
  composed: true
1403
1431
  })
1404
1432
  );
1405
1433
  };
1406
1434
  }
1435
+ get value() {
1436
+ return { selectedValues: this._selectedValues };
1437
+ }
1407
1438
  render() {
1408
1439
  const groupClasses = {
1409
1440
  "sds-checkbox-group": true,
@@ -1440,7 +1471,7 @@ __decorateClass$e([
1440
1471
  ], SDSCheckboxGroup.prototype, "errorMessage", 2);
1441
1472
  __decorateClass$e([
1442
1473
  r2()
1443
- ], SDSCheckboxGroup.prototype, "selectedValues", 2);
1474
+ ], SDSCheckboxGroup.prototype, "_selectedValues", 2);
1444
1475
  SDSCheckboxGroup = __decorateClass$e([
1445
1476
  t$2("sds-checkbox-group")
1446
1477
  ], SDSCheckboxGroup);
@@ -1543,7 +1574,6 @@ let SDSChip = class extends r$2 {
1543
1574
  this.internals.setFormValue(this.checked && this.value ? this.value : "");
1544
1575
  this.dispatchEvent(
1545
1576
  new CustomEvent("change", {
1546
- detail: { value: this.value, isChecked: this.checked },
1547
1577
  bubbles: true,
1548
1578
  composed: true
1549
1579
  })
@@ -2751,6 +2781,7 @@ let SDSRadio = class extends r$2 {
2751
2781
  this.required = false;
2752
2782
  this.label = "";
2753
2783
  this.hideLabel = false;
2784
+ this.value = "on";
2754
2785
  this.checked = false;
2755
2786
  this.error = false;
2756
2787
  this._initialChecked = false;
@@ -2775,20 +2806,18 @@ let SDSRadio = class extends r$2 {
2775
2806
  }
2776
2807
  const targetRadio = radios[targetIndex];
2777
2808
  targetRadio?.focus();
2809
+ targetRadio?.click();
2778
2810
  event.preventDefault();
2779
2811
  };
2780
2812
  this._handleChange = (event) => {
2781
2813
  if (!this.disabled) {
2782
2814
  const elem = event.target;
2783
2815
  this.checked = elem.checked;
2784
- this._validate();
2785
- this.dispatchEvent(
2786
- new CustomEvent("change", {
2787
- detail: { checked: this.checked, value: this.value },
2788
- bubbles: true,
2789
- composed: true
2790
- })
2791
- );
2816
+ if (this.checked) {
2817
+ this._uncheckSiblings();
2818
+ }
2819
+ this._updateGroupValidation();
2820
+ this.dispatchEvent(new CustomEvent("change", { bubbles: true, composed: true }));
2792
2821
  }
2793
2822
  };
2794
2823
  this._handleFocus = (event) => {
@@ -2808,36 +2837,60 @@ let SDSRadio = class extends r$2 {
2808
2837
  if (!this._initialChecked) {
2809
2838
  this._initialChecked = this.checked;
2810
2839
  }
2811
- this._validate();
2812
2840
  this.addEventListener("keydown", this._handleKeydown);
2813
2841
  }
2814
2842
  disconnectedCallback() {
2815
2843
  super.disconnectedCallback();
2816
2844
  this.removeEventListener("keydown", this._handleKeydown);
2817
2845
  }
2846
+ firstUpdated(_changedProperties) {
2847
+ super.firstUpdated(_changedProperties);
2848
+ this._updateGroupValidation();
2849
+ }
2850
+ _getGroupRadios() {
2851
+ if (!this.name) return [this];
2852
+ const root = this.getRootNode();
2853
+ const radioGroup = Array.from(root.querySelectorAll(`sds-radio[name="${this.name}"]`));
2854
+ return radioGroup;
2855
+ }
2856
+ _updateGroupValidation() {
2857
+ const group = this._getGroupRadios();
2858
+ const isAnyChecked = group.some((radio) => radio.checked);
2859
+ const isAnyRequired = group.some((radio) => radio.required);
2860
+ group.forEach((radio) => {
2861
+ if (!radio.control) return;
2862
+ if (isAnyRequired) {
2863
+ isAnyChecked ? radio.internals.setValidity({}) : radio.internals.setValidity(
2864
+ { valueMissing: true },
2865
+ radio.control.validationMessage,
2866
+ radio.control
2867
+ );
2868
+ radio.internals.setValidity(
2869
+ isAnyChecked ? {} : { valueMissing: true },
2870
+ isAnyChecked ? "Error" : radio.control.validationMessage,
2871
+ ...radio.control ? [radio.control] : []
2872
+ );
2873
+ } else {
2874
+ radio.internals.setValidity({});
2875
+ }
2876
+ });
2877
+ }
2818
2878
  formResetCallback() {
2819
2879
  this.checked = this._initialChecked;
2820
2880
  this.control.checked = this._initialChecked;
2821
- this.internals.setFormValue(this.checked ? this.value ?? null : null);
2822
- this._validate();
2823
- }
2824
- _validate() {
2825
- if (this.required && !this.checked) {
2826
- this.setCustomValidity("This field is required.");
2827
- } else {
2828
- this.setCustomValidity("");
2829
- }
2881
+ this.internals.setFormValue(this.checked ? this.value ?? "on" : "on");
2882
+ this._updateGroupValidation();
2830
2883
  }
2831
2884
  updated(changedProperties) {
2832
- super.updated?.(changedProperties);
2885
+ super.updated(changedProperties);
2833
2886
  if (changedProperties.has("checked")) {
2834
- this._validate();
2835
2887
  if (this.checked) {
2836
2888
  this._uncheckSiblings();
2837
2889
  this.internals.setFormValue(this.value ?? null);
2838
2890
  } else {
2839
2891
  this.internals.setFormValue(null);
2840
2892
  }
2893
+ this._updateGroupValidation();
2841
2894
  }
2842
2895
  if (changedProperties.has("required") && this.control) {
2843
2896
  this.control.required = this.required;
@@ -2914,6 +2967,7 @@ let SDSRadio = class extends r$2 {
2914
2967
  value="${o$1(this.value)}"
2915
2968
  ?checked="${this.checked}"
2916
2969
  ?disabled="${this.disabled}"
2970
+ ?required="${this.required}"
2917
2971
  @change="${this._handleChange}"
2918
2972
  @focus="${this._handleFocus}"
2919
2973
  @blur="${this._handleBlur}"
@@ -3015,14 +3069,13 @@ var __decorateClass$3 = (decorators, target, key, kind) => {
3015
3069
  let SDSRadioGroup = class extends r$2 {
3016
3070
  constructor() {
3017
3071
  super(...arguments);
3018
- this.selectedValue = null;
3072
+ this._selectedValue = null;
3019
3073
  this._handleRadioChange = (event) => {
3020
3074
  const target = event.composedPath().find((el) => el instanceof HTMLElement && el.tagName === "SDS-RADIO");
3021
3075
  if (target) {
3022
- this.selectedValue = target.getAttribute("value") || null;
3076
+ this._selectedValue = target.getAttribute("value") || null;
3023
3077
  this.dispatchEvent(
3024
- new CustomEvent("change", {
3025
- detail: { selectedValue: this.selectedValue },
3078
+ new CustomEvent("sds-update", {
3026
3079
  bubbles: true,
3027
3080
  composed: true
3028
3081
  })
@@ -3030,6 +3083,9 @@ let SDSRadioGroup = class extends r$2 {
3030
3083
  }
3031
3084
  };
3032
3085
  }
3086
+ get value() {
3087
+ return { selectedValue: this._selectedValue };
3088
+ }
3033
3089
  render() {
3034
3090
  return x`
3035
3091
  <fieldset class="sds-radio-group">
@@ -3062,7 +3118,7 @@ __decorateClass$3([
3062
3118
  ], SDSRadioGroup.prototype, "errorMessage", 2);
3063
3119
  __decorateClass$3([
3064
3120
  r2()
3065
- ], SDSRadioGroup.prototype, "selectedValue", 2);
3121
+ ], SDSRadioGroup.prototype, "_selectedValue", 2);
3066
3122
  SDSRadioGroup = __decorateClass$3([
3067
3123
  t$2("sds-radio-group")
3068
3124
  ], SDSRadioGroup);
@@ -3205,7 +3261,6 @@ let SDSSwitch = class extends r$2 {
3205
3261
  this.disabled = false;
3206
3262
  this.label = "";
3207
3263
  this.hideLabel = false;
3208
- this.value = "";
3209
3264
  this.reverse = false;
3210
3265
  this.checked = false;
3211
3266
  this.size = "l";
@@ -3215,10 +3270,9 @@ let SDSSwitch = class extends r$2 {
3215
3270
  if (!this.disabled) {
3216
3271
  const elem = event.target;
3217
3272
  this.checked = elem.checked;
3218
- this.internals.setFormValue(this.checked ? this.value : "");
3273
+ this.internals.setFormValue(this.checked ? "on" : "off");
3219
3274
  this.dispatchEvent(
3220
3275
  new CustomEvent("change", {
3221
- detail: { checked: this.checked, value: this.value },
3222
3276
  bubbles: true,
3223
3277
  composed: true
3224
3278
  })
@@ -3230,7 +3284,6 @@ let SDSSwitch = class extends r$2 {
3230
3284
  if (!this.disabled) {
3231
3285
  this.dispatchEvent(
3232
3286
  new CustomEvent("focus", {
3233
- detail: { checked: this.checked, value: this.value },
3234
3287
  bubbles: true,
3235
3288
  composed: true
3236
3289
  })
@@ -3242,7 +3295,6 @@ let SDSSwitch = class extends r$2 {
3242
3295
  if (!this.disabled) {
3243
3296
  this.dispatchEvent(
3244
3297
  new CustomEvent("blur", {
3245
- detail: { checked: this.checked, value: this.value },
3246
3298
  bubbles: true,
3247
3299
  composed: true
3248
3300
  })
@@ -3255,24 +3307,25 @@ let SDSSwitch = class extends r$2 {
3255
3307
  connectedCallback() {
3256
3308
  super.connectedCallback();
3257
3309
  this._initialChecked = this.checked;
3258
- if (this.checked) {
3259
- this.internals.setFormValue(this.value ? this.value : "");
3260
- }
3310
+ this.internals.setFormValue(this.checked ? "on" : "off");
3261
3311
  }
3262
3312
  updated(changedProperties) {
3263
3313
  if (changedProperties.has("checked")) {
3264
3314
  this.control.checked = this.checked;
3265
- this.internals.setFormValue(this.checked ? this.value : "");
3315
+ this.internals.setFormValue(this.checked ? "on" : "off");
3266
3316
  }
3267
3317
  }
3268
3318
  formResetCallback() {
3269
3319
  this.checked = this._initialChecked;
3270
3320
  this.control.checked = this._initialChecked;
3271
- this.internals.setFormValue(this._initialChecked ? this.value : "");
3321
+ this.internals.setFormValue(this._initialChecked ? "on" : "off");
3272
3322
  }
3273
3323
  formStateRestoreCallback(state) {
3274
3324
  this.checked = state;
3275
3325
  }
3326
+ get value() {
3327
+ return this.checked ? "on" : "off";
3328
+ }
3276
3329
  render() {
3277
3330
  const switchClasses = {
3278
3331
  "sds-switch": true,
@@ -3288,7 +3341,6 @@ let SDSSwitch = class extends r$2 {
3288
3341
  type="checkbox"
3289
3342
  role="switch"
3290
3343
  ?checked="${this.checked}"
3291
- value="${o$1(this.value)}"
3292
3344
  name="${o$1(this.name)}"
3293
3345
  @change="${this._handleChange}"
3294
3346
  @focus="${this._handleFocus}"
@@ -3312,11 +3364,8 @@ __decorateClass$2([
3312
3364
  n2({ type: Boolean, reflect: true, attribute: "hide-label" })
3313
3365
  ], SDSSwitch.prototype, "hideLabel", 2);
3314
3366
  __decorateClass$2([
3315
- n2({ type: String, reflect: false })
3367
+ n2({ type: String, reflect: true })
3316
3368
  ], SDSSwitch.prototype, "name", 2);
3317
- __decorateClass$2([
3318
- n2({ type: String, reflect: false })
3319
- ], SDSSwitch.prototype, "value", 2);
3320
3369
  __decorateClass$2([
3321
3370
  n2({ type: Boolean, reflect: true })
3322
3371
  ], SDSSwitch.prototype, "reverse", 2);
@@ -3524,91 +3573,100 @@ let SDSTextField = class extends r$2 {
3524
3573
  this.type = "text";
3525
3574
  this.disabled = false;
3526
3575
  this.readOnly = false;
3527
- this.autocomplete = false;
3576
+ this.required = false;
3528
3577
  this.hasIcon = false;
3578
+ this._defaultValue = "";
3529
3579
  this.handleSlotChange = (e2) => {
3530
3580
  const slot = e2.target;
3531
3581
  this.hasIcon = slot.assignedNodes({ flatten: true }).length > 0;
3532
3582
  };
3533
- this._handleInput = (event) => {
3583
+ this._handleInputChange = (event) => {
3534
3584
  event.stopImmediatePropagation();
3535
3585
  if (!this.disabled) {
3536
- this.internals.setFormValue(event.target.value);
3537
- this.dispatchEvent(
3538
- new CustomEvent("input", {
3539
- detail: { value: event.target.value },
3540
- bubbles: true,
3541
- composed: true
3542
- })
3543
- );
3544
- }
3545
- };
3546
- this._handleChange = (event) => {
3547
- event.stopImmediatePropagation();
3548
- if (!this.disabled) {
3549
- this.internals.setFormValue(event.target.value);
3550
- this.dispatchEvent(
3551
- new CustomEvent("change", {
3552
- detail: { value: event.target.value },
3553
- bubbles: true,
3554
- composed: true
3555
- })
3556
- );
3586
+ const currentValue = event.target.value;
3587
+ this.value = currentValue;
3588
+ this.internals.setFormValue(currentValue === "" ? null : currentValue);
3589
+ this.updateValidity();
3590
+ this.dispatchEvent(new CustomEvent(event.type, { bubbles: true, composed: true }));
3557
3591
  }
3558
3592
  };
3559
3593
  this._handleSelect = (event) => {
3560
3594
  event.stopImmediatePropagation();
3561
3595
  if (!this.disabled) {
3562
- const target = event.target;
3563
- const selectedText = target.value.substring(target.selectionStart ?? 0, target.selectionEnd ?? 0);
3564
- this.dispatchEvent(
3565
- new CustomEvent("select", {
3566
- detail: { selectedText },
3567
- bubbles: true,
3568
- composed: true
3569
- })
3570
- );
3596
+ this.dispatchEvent(new CustomEvent("select", { bubbles: true, composed: true }));
3571
3597
  }
3572
3598
  };
3573
3599
  this._handleFocus = (event) => {
3574
3600
  event.stopImmediatePropagation();
3575
- this.dispatchEvent(
3576
- new CustomEvent("focus", {
3577
- detail: { value: event.target.value },
3578
- bubbles: true,
3579
- composed: true
3580
- })
3581
- );
3601
+ this.dispatchEvent(new CustomEvent("focus", { bubbles: true, composed: true }));
3582
3602
  };
3583
3603
  this._handleBlur = (event) => {
3584
3604
  event.stopImmediatePropagation();
3585
- this.dispatchEvent(
3586
- new CustomEvent("blur", {
3587
- detail: { value: event.target.value },
3588
- bubbles: true,
3589
- composed: true
3590
- })
3591
- );
3605
+ this.updateValidity();
3606
+ this.dispatchEvent(new CustomEvent("blur", { bubbles: true, composed: true }));
3592
3607
  };
3593
3608
  this.internals = this.attachInternals();
3594
3609
  this.attachShadow({ mode: "open", delegatesFocus: true });
3595
3610
  }
3611
+ connectedCallback() {
3612
+ super.connectedCallback();
3613
+ this._defaultValue = this.value ?? "";
3614
+ }
3615
+ updateValidity() {
3616
+ if (this.control.checkValidity()) {
3617
+ this.internals.setValidity({});
3618
+ } else {
3619
+ this.internals.setValidity({ customError: true }, this.control.validationMessage, this.control);
3620
+ }
3621
+ }
3596
3622
  formResetCallback() {
3597
- const resetValue = this.value ? this.value : "";
3598
- this.control.value = resetValue;
3599
- this.internals.setFormValue(resetValue);
3623
+ this.control.value = this._defaultValue;
3624
+ this.internals.setFormValue(this._defaultValue === "" ? null : this._defaultValue);
3625
+ this.value = this._defaultValue;
3626
+ this.updateValidity();
3600
3627
  }
3601
3628
  select() {
3602
- if (!this.disabled) this.shadowRoot?.querySelector("input")?.select();
3629
+ if (!this.disabled) this.control.select();
3603
3630
  }
3604
3631
  focus() {
3605
- if (!this.disabled) this.shadowRoot?.querySelector("input")?.focus();
3632
+ if (!this.disabled) this.control.focus();
3606
3633
  }
3607
3634
  blur() {
3608
- if (!this.disabled) this.shadowRoot?.querySelector("input")?.blur();
3635
+ if (!this.disabled) this.control.blur();
3609
3636
  }
3610
3637
  click() {
3611
- if (!this.disabled) this.shadowRoot?.querySelector("input")?.click();
3638
+ if (!this.disabled) this.control.click();
3639
+ }
3640
+ get selectionStart() {
3641
+ return this.control ? this.control.selectionStart : null;
3642
+ }
3643
+ set selectionStart(value) {
3644
+ if (this.control && value !== null) {
3645
+ this.control.selectionStart = value;
3646
+ }
3647
+ }
3648
+ get selectionEnd() {
3649
+ return this.control ? this.control.selectionEnd : null;
3650
+ }
3651
+ set selectionEnd(value) {
3652
+ if (this.control && value !== null) {
3653
+ this.control.selectionEnd = value;
3654
+ }
3655
+ }
3656
+ setSelectionRange(start, end, direction) {
3657
+ if (this.control) {
3658
+ this.control.setSelectionRange(start, end, direction);
3659
+ }
3660
+ }
3661
+ checkValidity() {
3662
+ return this.control.checkValidity();
3663
+ }
3664
+ reportValidity() {
3665
+ return this.control.reportValidity();
3666
+ }
3667
+ setCustomValidity(message) {
3668
+ this.control.setCustomValidity(message);
3669
+ this.updateValidity();
3612
3670
  }
3613
3671
  render() {
3614
3672
  const textfieldClasses = {
@@ -3618,71 +3676,89 @@ let SDSTextField = class extends r$2 {
3618
3676
  "sds-textfield--readonly": Boolean(this.readOnly),
3619
3677
  "sds-textfield--has-icon": this.hasIcon
3620
3678
  };
3621
- return x` <div class="${e$1(textfieldClasses)}">
3622
- ${this.label ? x`<label for="sds-textfield" class="sds-textfield__label">${this.label}</label>` : E}
3623
- ${this.helpText ? x`<p class="sds-textfield__help-text">${this.helpText}</p>` : E}
3624
- <div class="sds-textfield__input-container">
3625
- <input
3626
- class="sds-textfield__input"
3627
- type="${this.type}"
3628
- id="sds-textfield"
3629
- ?disabled="${this.disabled}"
3630
- ?readonly="${this.readOnly}"
3631
- placeholder="${o$1(this.placeholder)}"
3632
- value="${o$1(this.value)}"
3633
- name="${o$1(this.name)}"
3634
- autocomplete="${this.autocomplete ? "on" : "off"}"
3635
- @input="${this._handleInput}"
3636
- @change="${this._handleChange}"
3637
- @select="${this._handleSelect}"
3638
- @focus="${this._handleFocus}"
3639
- @blur="${this._handleBlur}"
3640
- />
3641
- <slot name="after" @slotchange="${this.handleSlotChange}" aria-hidden="true"></slot>
3679
+ return x`
3680
+ <div class="${e$1(textfieldClasses)}">
3681
+ ${this.label ? x`<label for="sds-textfield" class="sds-textfield__label">${this.label}</label>` : E}
3682
+ ${this.helpText ? x`<p class="sds-textfield__help-text">${this.helpText}</p>` : E}
3683
+ <div class="sds-textfield__input-container">
3684
+ <input
3685
+ class="sds-textfield__input"
3686
+ type="${this.type}"
3687
+ id="sds-textfield"
3688
+ ?disabled="${this.disabled}"
3689
+ ?readonly="${this.readOnly}"
3690
+ placeholder="${o$1(this.placeholder)}"
3691
+ value="${o$1(this.value)}"
3692
+ name="${o$1(this.name)}"
3693
+ autocomplete="${o$1(this.autocomplete)}"
3694
+ ?required="${this.required}"
3695
+ pattern="${o$1(this.pattern)}"
3696
+ minlength="${o$1(this.minlength)}"
3697
+ maxlength="${o$1(this.maxlength)}"
3698
+ @input="${this._handleInputChange}"
3699
+ @change="${this._handleInputChange}"
3700
+ @select="${this._handleSelect}"
3701
+ @focus="${this._handleFocus}"
3702
+ @blur="${this._handleBlur}"
3703
+ />
3704
+ <slot name="after" @slotchange="${this.handleSlotChange}" aria-hidden="true"></slot>
3705
+ </div>
3706
+ ${this.errorMessage ? x`<p class="sds-textfield__error-message">
3707
+ <sds-icon
3708
+ name="warning-material-filled"
3709
+ size="m"
3710
+ color="${!this.disabled ? `var(--sds-color-semantic-icon-critical)` : `var(--sds-color-semantic-icon-disabled)`}"
3711
+ ></sds-icon>
3712
+ ${this.errorMessage}
3713
+ </p>` : E}
3642
3714
  </div>
3643
- ${this.errorMessage ? x`<p class="sds-textfield__error-message">
3644
- <sds-icon
3645
- name="warning-material-filled"
3646
- size="m"
3647
- color="${!this.disabled ? `var(--sds-color-semantic-icon-critical)` : `var(--sds-color-semantic-icon-disabled)`}"
3648
- ></sds-icon
3649
- >${this.errorMessage}
3650
- </p>` : E}
3651
- </div>`;
3715
+ `;
3652
3716
  }
3653
3717
  };
3654
3718
  SDSTextField.styles = [styles];
3655
3719
  SDSTextField.formAssociated = true;
3656
3720
  __decorateClass([
3657
- n2({ type: String })
3721
+ n2({ type: String, reflect: true })
3658
3722
  ], SDSTextField.prototype, "type", 2);
3659
3723
  __decorateClass([
3660
3724
  n2({ type: String })
3661
3725
  ], SDSTextField.prototype, "value", 2);
3662
3726
  __decorateClass([
3663
- n2({ type: String })
3727
+ n2({ type: String, reflect: true })
3664
3728
  ], SDSTextField.prototype, "name", 2);
3665
3729
  __decorateClass([
3666
- n2({ type: String })
3730
+ n2({ type: String, reflect: true })
3667
3731
  ], SDSTextField.prototype, "label", 2);
3668
3732
  __decorateClass([
3669
- n2({ type: String })
3733
+ n2({ type: String, reflect: true })
3670
3734
  ], SDSTextField.prototype, "placeholder", 2);
3671
3735
  __decorateClass([
3672
- n2({ type: String, attribute: "help-text" })
3736
+ n2({ type: String, attribute: "help-text", reflect: true })
3673
3737
  ], SDSTextField.prototype, "helpText", 2);
3674
3738
  __decorateClass([
3675
- n2({ type: String, attribute: "error-message" })
3739
+ n2({ type: String, attribute: "error-message", reflect: true })
3676
3740
  ], SDSTextField.prototype, "errorMessage", 2);
3677
3741
  __decorateClass([
3678
- n2({ type: Boolean })
3742
+ n2({ type: Boolean, reflect: true })
3679
3743
  ], SDSTextField.prototype, "disabled", 2);
3680
3744
  __decorateClass([
3681
- n2({ type: Boolean, attribute: "readonly" })
3745
+ n2({ type: Boolean, attribute: "readonly", reflect: true })
3682
3746
  ], SDSTextField.prototype, "readOnly", 2);
3683
3747
  __decorateClass([
3684
- n2({ type: Boolean })
3748
+ n2({ type: String, reflect: true })
3685
3749
  ], SDSTextField.prototype, "autocomplete", 2);
3750
+ __decorateClass([
3751
+ n2({ type: Boolean, reflect: true })
3752
+ ], SDSTextField.prototype, "required", 2);
3753
+ __decorateClass([
3754
+ n2({ type: String, reflect: true })
3755
+ ], SDSTextField.prototype, "pattern", 2);
3756
+ __decorateClass([
3757
+ n2({ type: Number, reflect: true })
3758
+ ], SDSTextField.prototype, "minlength", 2);
3759
+ __decorateClass([
3760
+ n2({ type: Number, reflect: true })
3761
+ ], SDSTextField.prototype, "maxlength", 2);
3686
3762
  __decorateClass([
3687
3763
  r2()
3688
3764
  ], SDSTextField.prototype, "hasIcon", 2);