@design.estate/dees-catalog 24.6.1 → 24.6.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.
@@ -1,4 +1,16 @@
1
1
  import { html } from '@design.estate/dees-element';
2
+ /**
3
+ * What the empty field shows: its `placeholder`, else a form its typing reads, with the time when it
4
+ * takes one. Not `dateFormat`: the field writes in that format but reads only the forms of
5
+ * `parseDateFields` (`YYYY-MM-DD`, `DD.MM.YYYY`, `MM/DD/YYYY`).
6
+ */
7
+ const placeholderOf = (component) => {
8
+ if (component.placeholder)
9
+ return component.placeholder;
10
+ if (!component.enableTime)
11
+ return 'YYYY-MM-DD';
12
+ return `YYYY-MM-DD ${component.timeFormat === '12h' ? 'h:mm AM/PM' : 'HH:mm'}`;
13
+ };
2
14
  export const renderDatepicker = (component) => {
3
15
  return html `
4
16
  <div class="input-wrapper">
@@ -13,12 +25,13 @@ export const renderDatepicker = (component) => {
13
25
  aria-describedby="date-description date-validation"
14
26
  class="date-input field-control ${component.isOpened ? 'open' : ''}"
15
27
  .value=${component.draftText ?? component.formatDate(component.value)}
16
- .placeholder=${component.placeholder}
28
+ .placeholder=${placeholderOf(component)}
17
29
  ?disabled=${component.disabled}
18
30
  ?required=${component.required}
19
31
  @click=${component.toggleCalendar}
20
32
  @keydown=${component.handleKeydown}
21
33
  @input=${component.handleManualInput}
34
+ @compositionend=${component.handleCompositionEnd}
22
35
  @blur=${component.handleInputBlur}
23
36
  style="padding-right: ${component.value || component.draftText ? 'calc(var(--dees-input-action-size) + 40px)' : '40px'}"
24
37
  />
@@ -38,4 +51,4 @@ export const renderDatepicker = (component) => {
38
51
  </div>
39
52
  `;
40
53
  };
41
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVtcGxhdGUuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi90c193ZWIvZWxlbWVudHMvMDBncm91cC1pbnB1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TLENBQUMsQ0FBQyxDQUFDLHNCQUFzQixDQUFDOzs7ZUFHeEksQ0FBQyxDQUFDLENBQUMsRUFBRTs7Ozs7eUNBS3FCLFNBQVMsQ0FBQyxpQkFBaUIsRUFBRTs2RUFDTyxTQUFTLENBQUMsY0FBYzs7O09BRzlGLENBQUM7QUFFUixDQUFDLENBQUMifQ==
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@design.estate/dees-catalog",
3
- "version": "24.6.1",
3
+ "version": "24.6.2",
4
4
  "private": false,
5
5
  "description": "A comprehensive library that provides dynamic web components for building sophisticated and modern web applications using JavaScript and TypeScript.",
6
6
  "main": "dist_ts_web/index.js",
package/readme.md CHANGED
@@ -1818,13 +1818,14 @@ both bubbling and composed, so a Lit template or a composite input listens with
1818
1818
  `@input` and `@change` as on a native control:
1819
1819
 
1820
1820
  - `input` as the value changes: each keystroke of a text field, each edit of an
1821
- editor (code, richtext, wysiwyg), each pick of a choice.
1821
+ editor (code, richtext, wysiwyg), each edit of a datepicker's text that changes its
1822
+ value, each pick of a choice.
1822
1823
  - `change` when the reader commits it: a text field (text, textarea, phone, IBAN)
1823
1824
  when the reader leaves it with a changed value or presses Enter in a single-line
1824
- one, as the native field does; an editor when the reader leaves it after editing;
1825
- every other input — checkbox, toggle, dropdown, radiogroup, multitoggle,
1826
- quantityselector, datepicker, tags, typelist, list, fileupload, profilepicture — at
1827
- once, right after its `input`.
1825
+ one, as the native field does, and so a date typed into a datepicker; an editor
1826
+ when the reader leaves it after editing; every other input — checkbox, toggle,
1827
+ dropdown, radiogroup, multitoggle, quantityselector, a date picked in a datepicker,
1828
+ tags, typelist, list, fileupload, profilepicture — at once, right after its `input`.
1828
1829
 
1829
1830
  The event's target is the input: read `event.target.value` (or `getValue()`). The
1830
1831
  events an input dispatches itself also carry the value as `detail.value`; the `input`
@@ -2346,13 +2347,39 @@ Profile picture input with cropping, zoom, and image processing.
2346
2347
 
2347
2348
  #### `DeesInputDatepicker`
2348
2349
  Date and time picker component with calendar interface and manual typing support.
2349
- Use `changeSubject` for field updates, or collect `.value` through `dees-form`.
2350
- Typing validates a draft; **blur or Enter commits** a valid date. Invalid calendar
2351
- fields (including non-leap February 29 and February 31) never roll into another
2352
- month. Invalid draft text remains visible with an accessible message, and the last
2353
- committed value remains unchanged without a successful `changeSubject` emission.
2354
- `checkValidity()` and `reportValidity()` include draft validity, so `dees-form`
2355
- cannot submit a stale date while its displayed draft is invalid.
2350
+ Listen to `change` (or `changeSubject`) for a committed date, to `input` for the value
2351
+ as the reader types, or collect `.value` through `dees-form`. `input` and `change`
2352
+ carry the field's `value` as `detail.value`; `validation-change` carries `valid` and
2353
+ `message`.
2354
+
2355
+ | What the reader does | What the field reports |
2356
+ | --- | --- |
2357
+ | An edit of the text that changes the value | `value` is set at once, then `input`; `validation-change` first when the text's validity changes. No `change`, no `changeSubject`. |
2358
+ | An edit that leaves the value as it is | only `validation-change`, when the text's validity changes |
2359
+ | Enter, or leaving the field | `changeSubject`, then `change`, once, when the value differs from the one before the typing began; nothing when it is the same |
2360
+ | A day, a time box, Today or Clear in the calendar, or the field's Clear | at once: `changeSubject`, `input`, then `change`, when the value differs from the one before the typing (the value, when nothing is typed); only `input` when it takes a typed value back to that one |
2361
+ | Code sets `value` to another value, or calls `setValue()` or `reset()` | nothing; typed text is replaced, and the value set is the one the next typing starts from |
2362
+
2363
+ While the reader types, `value` is always what Enter would leave: the moment the text
2364
+ names, nothing for emptied text, and for text the field does not take (no date yet, an
2365
+ invalid calendar day, a day outside the bounds or in `disabledDates`) the value from
2366
+ before the typing, so a date taken on the way (`2026-02-3`, 3 February, on the way to
2367
+ `2026-02-31`) is taken back with another `input`. A host that saves on `change` or
2368
+ `changeSubject` saves once, the date typed; one that wants a live Save state binds
2369
+ `.value`, `@input` (`detail.value`) and `@validation-change` (`detail.valid`). Bounds
2370
+ set while text is typed read it again at once: that reports `input` when the value moves, and `change`
2371
+ still waits for Enter or leaving the field. The text stays as typed until Enter or
2372
+ leaving the field writes it in `dateFormat`; text the field does not take stays
2373
+ visible with an accessible message. An IME composition's text is read when the
2374
+ composition ends; Enter while composing commits nothing. Invalid calendar fields
2375
+ (including non-leap February 29 and February 31) never roll into another month. While
2376
+ the calendar is open, it selects a typed moment and shows its month and time; partial
2377
+ text leaves its month. `checkValidity()` and `reportValidity()` include draft
2378
+ validity, so `dees-form` cannot submit a stale date while its displayed draft is
2379
+ invalid. The empty field shows a form it reads: `YYYY-MM-DD`, with ` HH:mm` (or
2380
+ ` h:mm AM/PM` with `timeFormat="12h"`) when it takes a time, whatever `dateFormat`,
2381
+ unless `placeholder` is set. The field reads `YYYY-MM-DD`, `DD.MM.YYYY` and
2382
+ `MM/DD/YYYY`, with a time after a space; `dateFormat` is how it writes a date.
2356
2383
 
2357
2384
  `minDate` and `maxDate` are inclusive calendar-day bounds on the field's clock. `disabledDates`
2358
2385
  uses the same calendar-day comparison for typing, day buttons and Today. With
@@ -2379,8 +2406,9 @@ the field keeps its zone and says why. The calendar offers the field's zone firs
2379
2406
  its list does not name it; a zone name the runtime does not know is passed over for the
2380
2407
  next, with a warning. A time the clock skips when it goes forward is refused ("This
2381
2408
  time doesn't exist that day."), typed or picked. A time it reads twice when it goes
2382
- back is the pass the bounds take, of those the pass of a value in that same hour, so an
2383
- edited time stays in its pass, else the earlier; bounds with their time compare as instants,
2409
+ back is the pass the bounds take, of those the pass of a value in that same hour (while
2410
+ the reader types, the value from before the typing), so an edited time stays in its
2411
+ pass, else the earlier; bounds with their time compare as instants,
2384
2412
  so a from/to pair keeps its end at or after its start in that hour too.
2385
2413
 
2386
2414
  A date-only value (`2026-10-27`) is that calendar day in every zone, without a
@@ -2394,7 +2422,6 @@ dialogs.
2394
2422
  <dees-input-datepicker
2395
2423
  key="eventDate"
2396
2424
  label="Event Date"
2397
- placeholder="YYYY-MM-DD"
2398
2425
  value="2025-01-15T14:30:00Z" // ISO string format
2399
2426
  dateFormat="YYYY-MM-DD" // Display format (default: YYYY-MM-DD)
2400
2427
  .enableTime=${true} // Enable time selection
@@ -3,6 +3,6 @@
3
3
  */
4
4
  export const commitinfo = {
5
5
  name: '@design.estate/dees-catalog',
6
- version: '24.6.1',
6
+ version: '24.6.2',
7
7
  description: 'A comprehensive library that provides dynamic web components for building sophisticated and modern web applications using JavaScript and TypeScript.'
8
8
  }
@@ -70,8 +70,13 @@ export class DeesInputDatepicker extends DeesInputBase<DeesInputDatepicker> {
70
70
  @property({ type: Number, reflect: true })
71
71
  accessor weekStartsOn: 0 | 1 | undefined;
72
72
 
73
+ /**
74
+ * What the empty field shows. Empty (the default), a form its typing reads: `YYYY-MM-DD`, with
75
+ * ` HH:mm` when it takes a time, or ` h:mm AM/PM` with `timeFormat="12h"`. The hint never follows
76
+ * `dateFormat`, which is how the field writes a date, not one it reads.
77
+ */
73
78
  @property({ type: String, reflect: true })
74
- accessor placeholder: string = 'YYYY-MM-DD';
79
+ accessor placeholder: string = '';
75
80
 
76
81
  @property({ type: Boolean, reflect: true })
77
82
  accessor enableTimezone: boolean = false;
@@ -101,7 +106,10 @@ export class DeesInputDatepicker extends DeesInputBase<DeesInputDatepicker> {
101
106
  @state()
102
107
  accessor selectedMinute: number = 0;
103
108
 
104
- /** Uncommitted text stays visible even when it cannot be represented by value. */
109
+ /**
110
+ * The text the reader is typing, until Enter, leaving the field or a pick writes it as the field
111
+ * does; text the field cannot take stays as typed.
112
+ */
105
113
  @state()
106
114
  accessor draftText: string | null = null;
107
115
 
@@ -112,6 +120,18 @@ export class DeesInputDatepicker extends DeesInputBase<DeesInputDatepicker> {
112
120
 
113
121
  private lastCommittedValue: string | undefined;
114
122
 
123
+ /**
124
+ * The value the field held when the reader began typing: Enter or leaving the field reports a
125
+ * typed value with `change` only when it differs from it, and text the field does not take
126
+ * returns the value to it.
127
+ */
128
+ private draftBase = '';
129
+
130
+ /** The value the reader last committed: while they type, the one from before the typing. */
131
+ private get committedValue(): string {
132
+ return this.draftText === null ? this.value : this.draftBase;
133
+ }
134
+
115
135
  /** The zone the field's readings were taken in, to read them again when it changes. */
116
136
  private readingTimeZone: string | undefined;
117
137
 
@@ -134,7 +154,7 @@ export class DeesInputDatepicker extends DeesInputBase<DeesInputDatepicker> {
134
154
  public willUpdate(changed: Map<PropertyKey, unknown>): void {
135
155
  super.willUpdate(changed);
136
156
  if (changed.has('value') && this.value !== this.lastCommittedValue || this.clockTimeZone !== this.readingTimeZone) {
137
- this.syncValue(this.value);
157
+ this.takeValue(this.value);
138
158
  }
139
159
  }
140
160
 
@@ -142,7 +162,9 @@ export class DeesInputDatepicker extends DeesInputBase<DeesInputDatepicker> {
142
162
  super.updated(changed);
143
163
  if (changed.has('disabled') && this.disabled) this.closePopup();
144
164
  if (['value', 'minDate', 'maxDate', 'disabledDates', 'required', 'disabled', 'timezone'].some(key => changed.has(key))) {
145
- this.updateValidation(this.currentValidationMessage());
165
+ // Typed text is read again under the new bounds at once, so the value stays what Enter would leave.
166
+ if (this.draftText !== null && !this.disabled) this.takeEdit();
167
+ else this.updateValidation(this.currentValidationMessage());
146
168
  }
147
169
  if (this.popupInstance) {
148
170
  this.popupInstance.minDate = this.minDate;
@@ -165,15 +187,21 @@ export class DeesInputDatepicker extends DeesInputBase<DeesInputDatepicker> {
165
187
  }
166
188
  }
167
189
 
168
- private syncValue(value: string | null): void {
169
- this.value = value ?? '';
170
- this.lastCommittedValue = this.value;
171
- this.draftText = null;
190
+ /**
191
+ * Takes `value` as the field's value, and its day and time as the calendar's selection. The text
192
+ * then shows the value as the field writes it and the calendar turns to its month; while the reader
193
+ * types (`keepText`), their text stays as typed and the calendar keeps the month it shows.
194
+ */
195
+ private takeValue(value: string, keepText = false): void {
196
+ this.value = value;
197
+ this.lastCommittedValue = value;
172
198
  this.readingTimeZone = this.clockTimeZone;
173
- this.selectedDate = parseDateValue(this.value, this.readingTimeZone);
174
- this.viewDate = new Date(this.selectedDate ?? readClock(new Date(), this.readingTimeZone));
199
+ this.selectedDate = parseDateValue(value, this.readingTimeZone);
175
200
  this.selectedHour = this.selectedDate?.getUTCHours() ?? 0;
176
201
  this.selectedMinute = this.selectedDate?.getUTCMinutes() ?? 0;
202
+ if (keepText) return;
203
+ this.draftText = null;
204
+ this.viewDate = new Date(this.selectedDate ?? readClock(new Date(), this.readingTimeZone));
177
205
  }
178
206
 
179
207
  /** A value as the field writes it, on its clock or, with `timeZone`, on the clock of that zone. */
@@ -289,7 +317,7 @@ export class DeesInputDatepicker extends DeesInputBase<DeesInputDatepicker> {
289
317
 
290
318
  private handleDateSelected = (event: Event): void => {
291
319
  if (this.disabled) return;
292
- this.commitDate((event as CustomEvent<Date>).detail, true);
320
+ this.commitDate((event as CustomEvent<Date>).detail);
293
321
  };
294
322
 
295
323
  private handleDateCleared = (): void => {
@@ -313,7 +341,7 @@ export class DeesInputDatepicker extends DeesInputBase<DeesInputDatepicker> {
313
341
  return;
314
342
  }
315
343
  this.timezone = timeZone;
316
- if (reading) this.commitDate(reading, true);
344
+ if (reading) this.commitDate(reading);
317
345
  };
318
346
 
319
347
  /**
@@ -334,8 +362,8 @@ export class DeesInputDatepicker extends DeesInputBase<DeesInputDatepicker> {
334
362
 
335
363
  /**
336
364
  * Which of the two moments a reading in an hour the clock reads twice names, as the clock's offset
337
- * then: one the bounds take, and of those the one the field's value is in when the value sits in
338
- * that same hour, so a time edited there stays in its pass; else the earlier. Undefined for a
365
+ * then: one the bounds take, and of those the one the field's committed value is in when that value
366
+ * sits in the same hour, so a time edited there stays in its pass; else the earlier. Undefined for a
339
367
  * reading the clock shows once.
340
368
  */
341
369
  private passOf(reading: Date | null, timeZone = this.clockTimeZone): number | undefined {
@@ -349,53 +377,87 @@ export class DeesInputDatepicker extends DeesInputBase<DeesInputDatepicker> {
349
377
  }
350
378
 
351
379
  /**
352
- * The pass of an hour the clock reads twice the field's value is in: its day and the clock's
380
+ * The pass of an hour the clock reads twice the field's committed value is in (while the reader
381
+ * types, the value from before the typing, as Enter has always read it): its day and the clock's
353
382
  * offset. Undefined for a value the clock shows once, whose offset says nothing of another reading.
354
383
  */
355
384
  private valuePass(timeZone: string): { day: number; offset: number } | undefined {
356
385
  const offset = this.valueOffset(timeZone);
357
386
  if (offset === undefined) return undefined;
358
- const reading = readClock(new Date(this.value), timeZone);
387
+ const reading = readClock(new Date(this.committedValue), timeZone);
359
388
  return clockInstants(reading, timeZone).length === 2 ? { day: calendarDayKey(reading), offset } : undefined;
360
389
  }
361
390
 
362
- /** The clock's offset at the field's value, when the value says its instant. */
391
+ /** The clock's offset at the field's committed value, when the value says its instant. */
363
392
  private valueOffset(timeZone = this.clockTimeZone): number | undefined {
364
- if (!namesInstant(this.value)) return undefined;
365
- const instant = new Date(this.value);
393
+ const value = this.committedValue;
394
+ if (!namesInstant(value)) return undefined;
395
+ const instant = new Date(value);
366
396
  return Number.isNaN(instant.getTime()) ? undefined : clockOffset(instant, timeZone);
367
397
  }
368
398
 
369
- private commitDate(date: Date, normalizeDraft: boolean): boolean {
399
+ /** Commits a moment picked in the calendar, set in its time boxes or by Today, or kept in a zone chosen. */
400
+ private commitDate(date: Date): void {
370
401
  const offset = this.passOf(date);
371
402
  const message = dateValidationMessage(date, this.constraintsIn(this.clockTimeZone, offset), this.t);
372
- if (message) { this.updateValidation(message); return false; }
373
- const value = this.formatValueWithTimezone(date, offset);
374
- const changed = value !== this.value;
375
- this.lastCommittedValue = value;
376
- this.value = value;
377
- this.readingTimeZone = this.clockTimeZone;
378
- this.selectedDate = new Date(date);
379
- this.selectedHour = date.getUTCHours();
380
- this.selectedMinute = date.getUTCMinutes();
381
- this.viewDate = new Date(date);
382
- if (normalizeDraft) this.draftText = null;
383
- this.updateValidation('');
384
- if (changed) {
385
- this.changeSubject.next(this);
386
- this.reportValueCommit();
387
- }
388
- return true;
403
+ if (message) { this.updateValidation(message); return; }
404
+ this.commitValue(this.formatValueWithTimezone(date, offset), { pick: true });
389
405
  }
390
406
 
407
+ /** Clears the value, from the field's button or the calendar's. */
391
408
  private commitClear(): void {
392
- const changed = Boolean(this.value);
393
- this.syncValue('');
409
+ this.commitValue('', { pick: true });
410
+ }
411
+
412
+ /**
413
+ * Commits a value: a pick, Clear, Enter or leaving the field. `changeSubject` and `change` report it
414
+ * once, when it differs from the value before the typing. `input` comes first for a pick that
415
+ * changes it, as every pick reports `input` then `change`, and for a commit that changes the value
416
+ * `input` last reported. Text the field does not take stays as typed (`keepText`).
417
+ */
418
+ private commitValue(value: string, { pick = false, keepText = false } = {}): void {
419
+ const before = this.committedValue;
420
+ const reported = this.value;
421
+ this.takeValue(value, keepText);
394
422
  this.updateValidation(this.currentValidationMessage());
395
- if (changed) {
396
- this.changeSubject.next(this);
397
- this.reportValueCommit();
423
+ const changed = value !== before;
424
+ if (changed) this.changeSubject.next(this);
425
+ if (value !== reported || (pick && changed)) this.dispatchValueEvent('input');
426
+ if (changed) this.dispatchValueEvent('change');
427
+ }
428
+
429
+ /**
430
+ * What the typed text leaves the field holding, as Enter takes it: the moment it names, nothing for
431
+ * no text, and for text the field does not take (`refused`) the value from before the typing.
432
+ */
433
+ private readDraft(): { value: string; reading: Date | null; refused: boolean } {
434
+ const text = this.draftText?.trim() ?? '';
435
+ if (!text) return { value: '', reading: null, refused: false };
436
+ const reading = this.manualMessage(text) ? null : this.parseManualDate(text);
437
+ if (!reading) return { value: this.draftBase, reading: null, refused: true };
438
+ return { value: this.formatValueWithTimezone(reading, this.passOf(reading)), reading, refused: false };
439
+ }
440
+
441
+ /**
442
+ * Takes an edit of the text: the value becomes the one Enter would leave and `input` reports it,
443
+ * the text stays as typed, and the calendar turns to a moment it names. `change` waits for Enter or
444
+ * leaving the field.
445
+ */
446
+ private takeEdit(): void {
447
+ const { value, reading } = this.readDraft();
448
+ const edited = value !== this.value;
449
+ if (edited) {
450
+ this.takeValue(value, true);
451
+ if (reading) this.viewDate = new Date(reading);
398
452
  }
453
+ this.updateValidation(this.currentValidationMessage());
454
+ if (edited) this.dispatchValueEvent('input');
455
+ }
456
+
457
+ /** Enter or leaving the field: commits the typed text and writes it as the field does; text it does not take stays. */
458
+ private commitDraft(): void {
459
+ const { value, refused } = this.readDraft();
460
+ this.commitValue(value, { keepText: refused });
399
461
  }
400
462
 
401
463
  private handleCloseRequest = (): void => {
@@ -423,7 +485,7 @@ export class DeesInputDatepicker extends DeesInputBase<DeesInputDatepicker> {
423
485
  if (this.disabled || e.isComposing) return;
424
486
  if (e.key === 'Enter') {
425
487
  e.preventDefault();
426
- if (this.draftText !== null) this.commitManualInput(true);
488
+ if (this.draftText !== null) this.commitDraft();
427
489
  else void this.toggleCalendar();
428
490
  } else if (e.key === 'ArrowDown' && e.altKey) {
429
491
  e.preventDefault();
@@ -451,22 +513,28 @@ export class DeesInputDatepicker extends DeesInputBase<DeesInputDatepicker> {
451
513
  if (!this.disabled) this.commitClear();
452
514
  }
453
515
 
516
+ /**
517
+ * Each edit sets the value Enter would leave and reports it with `input`, without rewriting the
518
+ * text under the caret: a moment the field takes, nothing for emptied text, and the value from
519
+ * before the typing for text it does not take, which says why. An edit inside an IME composition
520
+ * waits for the composition to end.
521
+ */
454
522
  public handleManualInput(e: InputEvent): void {
455
523
  if (this.disabled) return;
524
+ if (this.draftText === null) this.draftBase = this.value;
456
525
  this.draftText = (e.target as HTMLInputElement).value;
457
- if (!e.isComposing) this.updateValidation(this.currentValidationMessage());
526
+ if (!e.isComposing) this.takeEdit();
458
527
  }
459
528
 
460
- public handleInputBlur(_event: FocusEvent): void {
461
- if (!this.disabled && this.draftText !== null) this.commitManualInput(true);
529
+ /** The text an IME composition leaves is an edit; an engine may send no `input` after the composition ends. */
530
+ public handleCompositionEnd(e: CompositionEvent): void {
531
+ if (this.disabled || this.draftText === null) return;
532
+ this.draftText = (e.target as HTMLInputElement).value;
533
+ this.takeEdit();
462
534
  }
463
535
 
464
- private commitManualInput(normalizeDraft: boolean): void {
465
- const text = this.draftText?.trim() ?? '';
466
- if (!text) { this.commitClear(); return; }
467
- const message = this.manualMessage(text);
468
- if (message) { this.updateValidation(message); return; }
469
- this.commitDate(this.parseManualDate(text)!, normalizeDraft);
536
+ public handleInputBlur(_event: FocusEvent): void {
537
+ if (!this.disabled && this.draftText !== null) this.commitDraft();
470
538
  }
471
539
 
472
540
  /** The fields of typed text: the day, and the hour and minute when it names a time. */
@@ -550,7 +618,7 @@ export class DeesInputDatepicker extends DeesInputBase<DeesInputDatepicker> {
550
618
  }
551
619
 
552
620
  public setValue(value: string | null): void {
553
- this.syncValue(value);
621
+ this.takeValue(value ?? '');
554
622
  this.updateValidation(this.currentValidationMessage());
555
623
  }
556
624
 
@@ -1,3 +1,23 @@
1
+ import { html } from '@design.estate/dees-element';
1
2
  import { focusedInputDemo } from '../../../demos/inputs.js';
3
+ import { demoCode, demoOutput, demoSection, showDemoResult } from '../../../demos/templates.js';
4
+ import type { DeesInputDatepicker } from './component.js';
2
5
 
3
- export const demoFunc = () => focusedInputDemo('datepicker');
6
+ /** What a host holds after each report of the field: the report, its value, and why typed text is not taken. */
7
+ const showReport = (event: Event) => {
8
+ const field = event.currentTarget as DeesInputDatepicker;
9
+ const value = field.value || '(empty)';
10
+ const reason = field.checkValidity() ? '' : `${field.validationText} `;
11
+ showDemoResult(field, `${event.type}: ${reason}value: ${value}`);
12
+ };
13
+
14
+ export const demoFunc = () => focusedInputDemo('datepicker', demoSection(
15
+ 'Typed dates',
16
+ 'A typed date the field takes is its value as it is typed, reported by input, so a Save button can follow it; change follows once, on Enter or leaving the field. Text it does not take says why and leaves the value from before the typing.',
17
+ html`
18
+ <div class="dees-demo-grid">
19
+ <dees-input-datepicker label="Renewal date" value="2026-12-31" minDate="2026-11-01" @input=${showReport} @change=${showReport} @validation-change=${showReport}></dees-input-datepicker>
20
+ <dees-input-datepicker label="Maintenance window" .enableTime=${true} timeFormat="12h" @input=${showReport} @change=${showReport} @validation-change=${showReport}></dees-input-datepicker>
21
+ </div>${demoOutput('Type a date to see what the field reports.')}
22
+ ${demoCode('<dees-input-datepicker label="Renewal date" .value=${renewal} @input=${(event) => (draft = event.detail.value)} @validation-change=${(event) => (valid = event.detail.valid)} @change=${(event) => save(event.detail.value)}></dees-input-datepicker>')}`,
23
+ ));
@@ -1,6 +1,17 @@
1
1
  import { html, type TemplateResult } from '@design.estate/dees-element';
2
2
  import type { DeesInputDatepicker } from './component.js';
3
3
 
4
+ /**
5
+ * What the empty field shows: its `placeholder`, else a form its typing reads, with the time when it
6
+ * takes one. Not `dateFormat`: the field writes in that format but reads only the forms of
7
+ * `parseDateFields` (`YYYY-MM-DD`, `DD.MM.YYYY`, `MM/DD/YYYY`).
8
+ */
9
+ const placeholderOf = (component: DeesInputDatepicker): string => {
10
+ if (component.placeholder) return component.placeholder;
11
+ if (!component.enableTime) return 'YYYY-MM-DD';
12
+ return `YYYY-MM-DD ${component.timeFormat === '12h' ? 'h:mm AM/PM' : 'HH:mm'}`;
13
+ };
14
+
4
15
  export const renderDatepicker = (component: DeesInputDatepicker): TemplateResult => {
5
16
  return html`
6
17
  <div class="input-wrapper">
@@ -15,12 +26,13 @@ export const renderDatepicker = (component: DeesInputDatepicker): TemplateResult
15
26
  aria-describedby="date-description date-validation"
16
27
  class="date-input field-control ${component.isOpened ? 'open' : ''}"
17
28
  .value=${component.draftText ?? component.formatDate(component.value)}
18
- .placeholder=${component.placeholder}
29
+ .placeholder=${placeholderOf(component)}
19
30
  ?disabled=${component.disabled}
20
31
  ?required=${component.required}
21
32
  @click=${component.toggleCalendar}
22
33
  @keydown=${component.handleKeydown}
23
34
  @input=${component.handleManualInput}
35
+ @compositionend=${component.handleCompositionEnd}
24
36
  @blur=${component.handleInputBlur}
25
37
  style="padding-right: ${component.value || component.draftText ? 'calc(var(--dees-input-action-size) + 40px)' : '40px'}"
26
38
  />