@oslokommune/punkt-elements 18.6.0 → 18.6.1

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 (50) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/{checkbox-D6j7amKX.cjs → checkbox-BxDlOeQR.cjs} +1 -1
  3. package/dist/{checkbox-DcvKYDU2.js → checkbox-U3KfKBLv.js} +1 -1
  4. package/dist/{combobox-CiT2YvLb.js → combobox-8YJJthxD.js} +1 -1
  5. package/dist/{combobox-BT1LB0gl.cjs → combobox-CjQiFSKd.cjs} +1 -1
  6. package/dist/components/datepicker/datepicker-base.d.ts +4 -0
  7. package/dist/components/datepicker/datepicker.d.ts +3 -1
  8. package/dist/{datepicker-CqWg6K2N.js → datepicker-9zom2dyI.js} +57 -28
  9. package/dist/{datepicker-DIgQrvbZ.cjs → datepicker-CN_9JAxo.cjs} +22 -5
  10. package/dist/{header-DybJSDQQ.cjs → header-D_UJ70pO.cjs} +1 -1
  11. package/dist/{header-DU10rGhU.js → header-NPxBtRhJ.js} +1 -1
  12. package/dist/{input-element-uajHIWAO.cjs → input-element-BaXrl0h5.cjs} +1 -1
  13. package/dist/{input-element-zXKo9jpe.js → input-element-DQri-M3O.js} +2 -2
  14. package/dist/pkt-checkbox.cjs +1 -1
  15. package/dist/pkt-checkbox.js +1 -1
  16. package/dist/pkt-combobox.cjs +1 -1
  17. package/dist/pkt-combobox.js +1 -1
  18. package/dist/pkt-datepicker.cjs +1 -1
  19. package/dist/pkt-datepicker.js +1 -1
  20. package/dist/pkt-header.cjs +1 -1
  21. package/dist/pkt-header.js +1 -1
  22. package/dist/pkt-index.cjs +1 -1
  23. package/dist/pkt-index.js +9 -9
  24. package/dist/pkt-radiobutton.cjs +1 -1
  25. package/dist/pkt-radiobutton.js +1 -1
  26. package/dist/pkt-select.cjs +1 -1
  27. package/dist/pkt-select.js +1 -1
  28. package/dist/pkt-textarea.cjs +1 -1
  29. package/dist/pkt-textarea.js +1 -1
  30. package/dist/pkt-textinput.cjs +1 -1
  31. package/dist/pkt-textinput.js +1 -1
  32. package/dist/pkt-timepicker.cjs +1 -1
  33. package/dist/pkt-timepicker.js +1 -1
  34. package/dist/{radiobutton-BuOLykKo.cjs → radiobutton-DbHXj09u.cjs} +1 -1
  35. package/dist/{radiobutton-Dr5OQ0IY.js → radiobutton-Dm-IW6aF.js} +1 -1
  36. package/dist/{select-Cd_saUE7.js → select-B6ZUZ3tj.js} +1 -1
  37. package/dist/{select-Cc7c9dRd.cjs → select-ZlTO1P9_.cjs} +1 -1
  38. package/dist/{textarea-xTcafucE.cjs → textarea-BHISs7EC.cjs} +1 -1
  39. package/dist/{textarea-MJvpE_yV.js → textarea-CTlA6EGR.js} +1 -1
  40. package/dist/{textinput-B4VnZzsa.cjs → textinput-THsTffFY.cjs} +1 -1
  41. package/dist/{textinput-Cr7Z9ilH.js → textinput-kp1242Ci.js} +1 -1
  42. package/dist/{timepicker-srjt12dI.js → timepicker-BBaAVpH_.js} +1 -1
  43. package/dist/{timepicker-85ViMBd6.cjs → timepicker-Cwy8K6Af.cjs} +1 -1
  44. package/package.json +2 -2
  45. package/src/components/datepicker/datepicker-base.ts +14 -0
  46. package/src/components/datepicker/datepicker-multiple.ts +3 -0
  47. package/src/components/datepicker/datepicker-range.ts +6 -0
  48. package/src/components/datepicker/datepicker-single.ts +3 -1
  49. package/src/components/datepicker/datepicker.accessibility.test.ts +24 -3
  50. package/src/components/datepicker/datepicker.ts +63 -63
@@ -58,7 +58,6 @@ export class PktDatepicker extends PktInputElement<Props> {
58
58
  * Element attributes and properties
59
59
  */
60
60
  private _valueProperty: string = ''
61
- private _valueProcessing = false
62
61
  datepickerPopupRef: Ref<PktDatepickerPopup> = createRef()
63
62
 
64
63
  @property({ type: String, reflect: true })
@@ -68,8 +67,9 @@ export class PktDatepicker extends PktInputElement<Props> {
68
67
 
69
68
  set value(newValue: string | string[]) {
70
69
  const oldValue = this._valueProperty
71
- this._valueProperty = Array.isArray(newValue) ? newValue.join(',') : newValue || ''
72
- this.valueChanged(this._valueProperty, oldValue)
70
+ const raw = Array.isArray(newValue) ? newValue.join(',') : newValue || ''
71
+ if (raw === oldValue) return
72
+ this._valueProperty = raw
73
73
  this.requestUpdate('value', oldValue)
74
74
  }
75
75
 
@@ -152,45 +152,43 @@ export class PktDatepicker extends PktInputElement<Props> {
152
152
  }
153
153
 
154
154
  valueChanged(newValue: string | null, oldValue: string | null): void {
155
- if (this._valueProcessing || newValue === oldValue) return
156
- this._valueProcessing = true
157
- try {
158
- const parsedValue = valueToArray(newValue)
159
-
160
- // For multiple dates, filter out invalid ones to prevent accumulating bad dates
161
- // For single/range dates, preserve user input for validation feedback
162
- const filteredValue =
163
- this.multiple && parsedValue.length > 1
164
- ? valueUtils.filterSelectableDates(
165
- parsedValue,
166
- this.min,
167
- this.max,
168
- this.excludedates,
169
- this.excludeweekdays,
170
- )
171
- : parsedValue
172
-
173
- if (this.range && !valueUtils.validateRangeOrder(filteredValue)) {
174
- this._value = []
175
- this._valueProperty = ''
176
- super.valueChanged('', oldValue)
177
- return
178
- }
179
-
180
- this._value = filteredValue
181
-
182
- const parsedValueString = arrayToCsv(filteredValue)
183
- if (this._valueProperty !== parsedValueString) {
184
- this._valueProperty = parsedValueString
185
- }
186
-
187
- // In range mode, don't dispatch events until both dates are selected
188
- if (this.range && filteredValue.length < 2) return
189
-
190
- super.valueChanged(parsedValueString, oldValue)
191
- } finally {
192
- this._valueProcessing = false
155
+ if (newValue === oldValue) return
156
+ this.value = newValue ?? ''
157
+ this.deriveValue(oldValue)
158
+ }
159
+
160
+ private deriveValue(oldValue: string | null): void {
161
+ const parsedValue = valueToArray(this._valueProperty)
162
+
163
+ // For multiple dates, filter out invalid ones to prevent accumulating bad dates
164
+ // For single/range dates, preserve user input for validation feedback
165
+ const filteredValue =
166
+ this.multiple && parsedValue.length > 1
167
+ ? valueUtils.filterSelectableDates(
168
+ parsedValue,
169
+ this.min,
170
+ this.max,
171
+ this.excludedates,
172
+ this.excludeweekdays,
173
+ )
174
+ : parsedValue
175
+
176
+ if (this.range && !valueUtils.validateRangeOrder(filteredValue)) {
177
+ this._valueProperty = ''
178
+ super.valueChanged('', oldValue)
179
+ this._value = []
180
+ return
193
181
  }
182
+
183
+ this._valueProperty = arrayToCsv(filteredValue)
184
+
185
+ // Én dato er ingen fullført periode. Tom er en fullført endring.
186
+ if (!(this.range && filteredValue.length === 1)) {
187
+ super.valueChanged(this._valueProperty, oldValue)
188
+ }
189
+
190
+ // Etter super, som utleder _value fra strengen og gjør '' til [''].
191
+ this._value = filteredValue
194
192
  }
195
193
 
196
194
  attributeChangedCallback(name: string, _old: string | null, value: string | null): void {
@@ -204,30 +202,26 @@ export class PktDatepicker extends PktInputElement<Props> {
204
202
  super.attributeChangedCallback(name, _old, value)
205
203
  }
206
204
 
207
- updated(changedProperties: PropertyValues): void {
208
- // Re-process value only when multiple/range also changed in the same update cycle,
209
- // since attribute initialization may process value before multiple/range are set.
210
- // When value is set via JS setter after init, multiple/range are already correct
211
- // and the setter's valueChanged() call is sufficient.
212
- if (
213
- changedProperties.has('value') &&
214
- (changedProperties.has('multiple') || changedProperties.has('range'))
215
- ) {
216
- const newValue = Array.isArray(this.value) ? this.value.join(',') : this.value
205
+ private static readonly DERIVED_FROM = [
206
+ 'value',
207
+ 'multiple',
208
+ 'range',
209
+ 'min',
210
+ 'max',
211
+ 'excludedates',
212
+ 'excludeweekdays',
213
+ ]
214
+
215
+ protected willUpdate(changedProperties: PropertyValues): void {
216
+ super.willUpdate(changedProperties)
217
+
218
+ if (PktDatepicker.DERIVED_FROM.some((prop) => changedProperties.has(prop))) {
217
219
  const oldValue = changedProperties.get('value')
218
- const oldValueStr = Array.isArray(oldValue) ? oldValue.join(',') : oldValue
219
- this.valueChanged(newValue, oldValueStr)
220
- }
221
- if (changedProperties.has('multiple')) {
222
- if (this.multiple && !Array.isArray(this._value)) {
223
- this._value = valueToArray(this.value)
224
- } else if (!this.multiple && Array.isArray(this._value)) {
225
- this._value = this._value.filter(Boolean)
226
- }
227
- if (!this.multiple && !this.range && Array.isArray(this._value)) {
228
- this._value = [this._value[0] ?? '']
229
- }
220
+ this.deriveValue(Array.isArray(oldValue) ? oldValue.join(',') : (oldValue ?? null))
230
221
  }
222
+ }
223
+
224
+ updated(changedProperties: PropertyValues): void {
231
225
  // Ytre boks, samme klasser og rolle som Reacts ytre div
232
226
  this.classList.add('pkt-datepicker')
233
227
  this.classList.toggle('pkt-datepicker--fullwidth', this.fullwidth)
@@ -311,6 +305,8 @@ export class PktDatepicker extends PktInputElement<Props> {
311
305
  .inputClasses=${this.inputClasses}
312
306
  .inputSize=${this.inputSize}
313
307
  .internals=${this.internals}
308
+ .hasError=${this.hasError}
309
+ .hasHelptext=${Boolean(this.helptext || this.helptextDropdown)}
314
310
  .strings=${this.strings}
315
311
  @toggle-calendar=${(e: CustomEvent) => this.toggleCalendar(e.detail)}
316
312
  @input-change=${() => this.onInput()}
@@ -348,6 +344,8 @@ export class PktDatepicker extends PktInputElement<Props> {
348
344
  .inputClasses=${this.inputClasses}
349
345
  .inputSize=${this.inputSize}
350
346
  .internals=${this.internals}
347
+ .hasError=${this.hasError}
348
+ .hasHelptext=${Boolean(this.helptext || this.helptextDropdown)}
351
349
  .strings=${this.strings}
352
350
  @toggle-calendar=${(e: CustomEvent) => this.toggleCalendar(e.detail)}
353
351
  @input-change=${() => this.onInput()}
@@ -434,6 +432,8 @@ export class PktDatepicker extends PktInputElement<Props> {
434
432
  .inputClasses=${this.inputClasses}
435
433
  .inputSize=${this.inputSize}
436
434
  .internals=${this.internals}
435
+ .hasError=${this.hasError}
436
+ .hasHelptext=${Boolean(this.helptext || this.helptextDropdown)}
437
437
  .strings=${this.strings}
438
438
  @toggle-calendar=${(e: CustomEvent) => this.toggleCalendar(e.detail)}
439
439
  @input-change=${() => this.onInput()}