@design.estate/dees-catalog 24.4.0 → 24.5.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 (31) hide show
  1. package/dist_bundle/bundle.js +60 -174
  2. package/dist_bundle/bundle.js.map +1 -1
  3. package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{chunk-7CM7S6EQ.js → chunk-LRGVCS7F.js} +2 -2
  4. package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{chunk-R6EBIDCM.js → chunk-PKH6IGY6.js} +347 -4
  5. package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{chunk-R6EBIDCM.js.map → chunk-PKH6IGY6.js.map} +1 -1
  6. package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{dees-modal-Z3DSEMNI.js → dees-modal-ORXOZADW.js} +2 -2
  7. package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{dees-workspace-terminal-KPB3RVGL.js → dees-workspace-terminal-MUU2HDU3.js} +3 -3
  8. package/dist_ts_web/00_commitinfo_data.js +1 -1
  9. package/dist_ts_web/elements/00group-input/dees-input-multitoggle/dees-input-multitoggle.d.ts +8 -1
  10. package/dist_ts_web/elements/00group-input/dees-input-multitoggle/dees-input-multitoggle.demo.js +7 -1
  11. package/dist_ts_web/elements/00group-input/dees-input-multitoggle/dees-input-multitoggle.js +18 -5
  12. package/dist_ts_web/elements/00group-input/dees-input-tags/dees-input-tags.d.ts +4 -13
  13. package/dist_ts_web/elements/00group-input/dees-input-tags/dees-input-tags.js +29 -174
  14. package/dist_ts_web/elements/00group-input/dees-input-text/dees-input-text.d.ts +41 -0
  15. package/dist_ts_web/elements/00group-input/dees-input-text/dees-input-text.demo.js +16 -1
  16. package/dist_ts_web/elements/00group-input/dees-input-text/dees-input-text.js +103 -3
  17. package/dist_ts_web/elements/00group-input/suggestion-list.d.ts +102 -0
  18. package/dist_ts_web/elements/00group-input/suggestion-list.js +300 -0
  19. package/package.json +1 -1
  20. package/readme.md +27 -1
  21. package/scripts/token-baseline.json +1 -1
  22. package/ts_web/00_commitinfo_data.ts +1 -1
  23. package/ts_web/elements/00group-input/dees-input-multitoggle/dees-input-multitoggle.demo.ts +6 -0
  24. package/ts_web/elements/00group-input/dees-input-multitoggle/dees-input-multitoggle.ts +24 -7
  25. package/ts_web/elements/00group-input/dees-input-tags/dees-input-tags.ts +27 -171
  26. package/ts_web/elements/00group-input/dees-input-text/dees-input-text.demo.ts +17 -0
  27. package/ts_web/elements/00group-input/dees-input-text/dees-input-text.ts +106 -1
  28. package/ts_web/elements/00group-input/suggestion-list.ts +323 -0
  29. /package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{chunk-7CM7S6EQ.js.map → chunk-LRGVCS7F.js.map} +0 -0
  30. /package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{dees-modal-Z3DSEMNI.js.map → dees-modal-ORXOZADW.js.map} +0 -0
  31. /package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{dees-workspace-terminal-KPB3RVGL.js.map → dees-workspace-terminal-MUU2HDU3.js.map} +0 -0
@@ -11,8 +11,8 @@ import { DeesInputBase } from '../dees-input-base/dees-input-base.js';
11
11
  import '../../00group-utility/dees-icon/dees-icon.js';
12
12
  import { demoFunc } from './dees-input-tags.demo.js';
13
13
  import { themeDefaultStyles } from '../../00theme.js';
14
- import { listenForScrollAround, placeAnchored, visibleRect } from '../../00anchorplacement.js';
15
- import { OverlayScrollbarController, overlayScrollbarStyles } from '../../00scrollbars.js';
14
+ import { overlayScrollbarStyles } from '../../00scrollbars.js';
15
+ import { inputSuggestion, SuggestionListController, suggestionListStyles } from '../suggestion-list.js';
16
16
  import { dcLocalize } from '../../../i18n/localize.js';
17
17
 
18
18
  /**
@@ -52,29 +52,24 @@ export class DeesInputTags extends DeesInputBase<DeesInputTags> {
52
52
  @state()
53
53
  accessor inputValue: string = '';
54
54
 
55
- @state()
56
- accessor showSuggestions: boolean = false;
57
-
58
- @state()
59
- accessor highlightedSuggestionIndex: number = -1;
60
-
61
55
  @property({ type: String, reflect: true })
62
56
  accessor validationText: string = '';
63
57
 
64
- /** Ends the listeners that keep the open suggestions beside the field. */
65
- private suggestionsTracking?: AbortController;
66
-
67
- /** The suggestions' scrollbar, shown while they scroll. */
68
- private readonly scrollbars = new OverlayScrollbarController(
69
- this,
70
- () => this.shadowRoot?.querySelector<HTMLElement>('.suggestions-list'),
71
- );
58
+ /** The suggestions under the field, as a combobox list. */
59
+ private readonly suggestionList = new SuggestionListController(this, {
60
+ anchor: () => this.shadowRoot?.querySelector<HTMLElement>('.tags-container'),
61
+ pick: (index) => {
62
+ const suggestion = this.filteredSuggestions[index];
63
+ if (suggestion) this.addTag(suggestion);
64
+ },
65
+ });
72
66
 
73
67
  public static styles = [
74
68
  themeDefaultStyles,
75
69
  ...DeesInputBase.baseStyles,
76
70
  cssManager.defaultStyles,
77
71
  overlayScrollbarStyles,
72
+ suggestionListStyles,
78
73
  css`
79
74
  :host {
80
75
  display: block;
@@ -182,58 +177,6 @@ export class DeesInputTags extends DeesInputBase<DeesInputTags> {
182
177
  cursor: not-allowed;
183
178
  }
184
179
 
185
- /* Suggestions: a popover in the top layer, placed below the field by placeSuggestions.
186
- The list scrolls inside it, the frame its scrollbar is placed in. */
187
- .suggestions-dropdown {
188
- position: fixed;
189
- inset: auto;
190
- margin: 0;
191
- padding: 0;
192
- color: inherit;
193
- background: var(--dees-material-regular-bg-opaque);
194
- border: var(--dees-line-width-hairline) solid var(--dees-color-border-default);
195
- border-radius: var(--dees-radius-lg);
196
- corner-shape: var(--dees-corner-shape);
197
- box-shadow: var(--dees-shadow-lg);
198
- overflow: hidden;
199
- }
200
-
201
- .suggestions-list {
202
- max-height: calc(200px - 2 * var(--dees-line-width-hairline));
203
- overflow-y: auto;
204
- }
205
-
206
- @supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
207
- .suggestions-dropdown {
208
- background: var(--dees-material-regular-bg-opaque);
209
- }
210
- }
211
-
212
- @media (prefers-reduced-transparency: reduce) {
213
- .suggestions-dropdown {
214
- background: var(--dees-material-regular-bg-opaque);
215
- -webkit-backdrop-filter: none;
216
- backdrop-filter: none;
217
- }
218
- }
219
-
220
- .suggestion {
221
- padding: 6px 10px;
222
- cursor: pointer;
223
- transition: background-color var(--dees-transition-fast) var(--dees-ease-standard);
224
- font-size: 14px;
225
- color: var(--dees-color-text-primary);
226
- }
227
-
228
- .suggestion:hover {
229
- background: var(--dees-color-hover);
230
- }
231
-
232
- .suggestion.highlighted {
233
- background: var(--dees-color-active);
234
- color: var(--dees-color-text-primary);
235
- }
236
-
237
180
  /* Validation styles */
238
181
  .validation-message {
239
182
  color: var(--dees-color-accent-error);
@@ -244,13 +187,16 @@ export class DeesInputTags extends DeesInputBase<DeesInputTags> {
244
187
  `,
245
188
  ];
246
189
 
247
- public render(): TemplateResult {
248
- const filteredSuggestions = this.suggestions.filter(
249
- suggestion =>
190
+ /** The suggestions not yet a tag that hold the typed text. */
191
+ private get filteredSuggestions(): string[] {
192
+ return this.suggestions.filter(
193
+ suggestion =>
250
194
  !this.value.includes(suggestion) &&
251
195
  suggestion.toLowerCase().includes(this.inputValue.toLowerCase())
252
196
  );
197
+ }
253
198
 
199
+ public render(): TemplateResult {
254
200
  return html`
255
201
  <div class="input-wrapper">
256
202
  ${this.renderLabel()}
@@ -287,22 +233,7 @@ export class DeesInputTags extends DeesInputBase<DeesInputTags> {
287
233
  ` : ''}
288
234
  </div>
289
235
 
290
- ${this.showSuggestions && filteredSuggestions.length > 0 ? html`
291
- <div class="suggestions-dropdown" popover="manual"><div class="suggestions-list">
292
- ${filteredSuggestions.map((suggestion, index) => html`
293
- <div
294
- class="suggestion ${index === this.highlightedSuggestionIndex ? 'highlighted' : ''}"
295
- @mousedown=${(e: Event) => {
296
- e.preventDefault(); // Prevent blur
297
- this.addTag(suggestion);
298
- }}
299
- @mouseenter=${() => this.highlightedSuggestionIndex = index}
300
- >
301
- ${suggestion}
302
- </div>
303
- `)}
304
- </div></div>
305
- ` : ''}
236
+ ${this.suggestionList.render(this.filteredSuggestions.map(inputSuggestion), this.label)}
306
237
 
307
238
  ${this.validationText ? html`
308
239
  <div class="validation-message">${this.validationText}</div>
@@ -315,61 +246,12 @@ export class DeesInputTags extends DeesInputBase<DeesInputTags> {
315
246
 
316
247
  updated(changedProperties: Map<string, any>) {
317
248
  super.updated(changedProperties);
318
- const list = this.shadowRoot!.querySelector<HTMLElement>('.suggestions-dropdown');
319
- if (!list) {
320
- this.suggestionsTracking?.abort();
321
- this.suggestionsTracking = undefined;
322
- return;
323
- }
324
- if (!this.suggestionsTracking) {
325
- const field = this.shadowRoot!.querySelector<HTMLElement>('.tags-container')!;
326
- const tracking = new AbortController();
327
- this.suggestionsTracking = tracking;
328
- listenForScrollAround(field, this.placeSuggestions, tracking.signal);
329
- window.addEventListener('resize', this.placeSuggestions, { passive: true, signal: tracking.signal });
330
- // Tags wrap onto another line as they are added, and the field grows with them.
331
- const observer = new ResizeObserver(this.placeSuggestions);
332
- observer.observe(field);
333
- tracking.signal.addEventListener('abort', () => observer.disconnect());
249
+ const input = this.shadowRoot!.querySelector<HTMLInputElement>('.tag-input');
250
+ if (input) {
251
+ this.suggestionList.applyComboboxAttributes(input, this.filteredSuggestions.length, this.suggestions.length > 0);
334
252
  }
335
- this.placeSuggestions();
336
- }
337
-
338
- public async disconnectedCallback(): Promise<void> {
339
- this.suggestionsTracking?.abort();
340
- this.suggestionsTracking = undefined;
341
- await super.disconnectedCallback();
342
253
  }
343
254
 
344
- /**
345
- * The open suggestions stand in the top layer, below the field or above it without room there,
346
- * so no scroll container or clipping ancestor around the field cuts them off. They follow the
347
- * field as it scrolls or grows and step out of view while none of it shows.
348
- */
349
- private placeSuggestions = () => {
350
- const list = this.shadowRoot?.querySelector<HTMLElement>('.suggestions-dropdown');
351
- const field = this.shadowRoot?.querySelector<HTMLElement>('.tags-container');
352
- if (!list || !field) return;
353
- const shown = visibleRect(field);
354
- if (!shown) {
355
- if (list.matches(':popover-open')) list.hidePopover();
356
- return;
357
- }
358
- if (!list.matches(':popover-open')) list.showPopover();
359
- const box = field.getBoundingClientRect();
360
- list.style.width = `${box.width}px`;
361
- const placed = placeAnchored({
362
- anchor: { left: box.left, right: box.right, top: shown.top, bottom: shown.bottom },
363
- width: box.width,
364
- height: list.offsetHeight,
365
- placement: 'bottom',
366
- flip: true,
367
- gap: 4,
368
- });
369
- list.style.left = `${placed.left}px`;
370
- list.style.top = `${placed.top}px`;
371
- };
372
-
373
255
  private handleContainerClick(e: Event) {
374
256
  if (this.disabled) return;
375
257
 
@@ -406,56 +288,31 @@ export class DeesInputTags extends DeesInputBase<DeesInputTags> {
406
288
 
407
289
  private handleKeyDown(e: KeyboardEvent) {
408
290
  if (this.disabled || e.isComposing) return;
409
- const input = e.target as HTMLInputElement;
410
-
291
+ if (this.suggestionList.handleKeydown(e, this.filteredSuggestions.length)) return;
292
+
411
293
  if (e.key === 'Enter') {
412
294
  e.preventDefault();
413
- if (this.highlightedSuggestionIndex >= 0 && this.showSuggestions) {
414
- const filteredSuggestions = this.suggestions.filter(
415
- suggestion =>
416
- !this.value.includes(suggestion) &&
417
- suggestion.toLowerCase().includes(this.inputValue.toLowerCase())
418
- );
419
- if (filteredSuggestions[this.highlightedSuggestionIndex]) {
420
- this.addTag(filteredSuggestions[this.highlightedSuggestionIndex]);
421
- }
422
- } else if (this.inputValue.trim()) {
295
+ if (this.inputValue.trim()) {
423
296
  this.addTag(this.inputValue.trim());
424
297
  }
425
298
  } else if (e.key === 'Backspace' && !this.inputValue && this.value.length > 0) {
426
299
  // Remove last tag when backspace is pressed on empty input
427
300
  this.removeTag(e, this.value[this.value.length - 1]);
428
- } else if (e.key === 'ArrowDown' && this.showSuggestions) {
429
- e.preventDefault();
430
- const filteredCount = this.suggestions.filter(
431
- s => !this.value.includes(s) && s.toLowerCase().includes(this.inputValue.toLowerCase())
432
- ).length;
433
- this.highlightedSuggestionIndex = Math.min(
434
- this.highlightedSuggestionIndex + 1,
435
- filteredCount - 1
436
- );
437
- } else if (e.key === 'ArrowUp' && this.showSuggestions) {
438
- e.preventDefault();
439
- this.highlightedSuggestionIndex = Math.max(this.highlightedSuggestionIndex - 1, 0);
440
301
  } else if (e.key === 'Tab') {
441
302
  // before the focus moves on, so a host that reads the value on Tab (a table cell) has the text
442
303
  this.addPendingInput();
443
- } else if (e.key === 'Escape') {
444
- this.showSuggestions = false;
445
- this.highlightedSuggestionIndex = -1;
446
304
  }
447
305
  }
448
306
 
449
307
  private handleFocus() {
450
308
  if (this.suggestions.length > 0) {
451
- this.showSuggestions = true;
309
+ this.suggestionList.show();
452
310
  }
453
311
  }
454
312
 
455
313
  private handleBlur(e: FocusEvent) {
456
314
  // Suggestions prevent pointer-down blur; no delayed state change is needed.
457
- this.showSuggestions = false;
458
- this.highlightedSuggestionIndex = -1;
315
+ this.suggestionList.hide();
459
316
  // The window losing the focus blurs the text but leaves it the active element: the reader has
460
317
  // not left the field and comes back to what they were typing.
461
318
  const input = e.target as HTMLInputElement;
@@ -493,8 +350,7 @@ export class DeesInputTags extends DeesInputBase<DeesInputTags> {
493
350
  if (this.maxTags && this.value.length >= this.maxTags) return;
494
351
 
495
352
  this.value = [...this.value, tag];
496
- this.showSuggestions = false;
497
- this.highlightedSuggestionIndex = -1;
353
+ this.suggestionList.hide();
498
354
  this.clearInput();
499
355
 
500
356
  this.emitChange();
@@ -1,5 +1,19 @@
1
1
  import { html } from '@design.estate/dees-element';
2
2
  import { demoPage, demoSection, demoOutput, demoCode, showDemoResult } from '../../../demos/templates.js';
3
+ import type { DeesInputText, IInputSuggestion } from './dees-input-text.js';
4
+
5
+ /** What a server would answer for a typed path: the paths that continue it. */
6
+ const serverPaths = ['/home/', '/home/alex/', '/home/alex/projects/', '/home/alex/projects/catalog/', '/srv/', '/srv/www/', '/srv/www/site/', '/var/', '/var/log/', '/var/log/nginx/'];
7
+ const completePath = (event: Event) => {
8
+ const field = event.currentTarget as DeesInputText;
9
+ const typed = String(field.value ?? '');
10
+ field.suggestions = serverPaths.filter((path) => path.startsWith(typed) && path !== typed);
11
+ };
12
+ const regions: IInputSuggestion[] = [
13
+ { value: 'eu-central-1', label: 'Frankfurt', description: 'eu-central-1' },
14
+ { value: 'eu-west-1', label: 'Ireland', description: 'eu-west-1' },
15
+ { value: 'us-east-1', label: 'Virginia', description: 'us-east-1' },
16
+ ];
3
17
 
4
18
  export const demoFunc = () => demoPage('Text input', 'A compact editor field and a quiet grouped value, with accessible labels, password controls, and validation feedback.', html`
5
19
  ${demoSection('Everyday entry', 'Labels and descriptions explain what belongs in each field.', html`
@@ -13,6 +27,9 @@ export const demoFunc = () => demoPage('Text input', 'A compact editor field and
13
27
  ${demoSection('Password visibility', 'A dedicated button reveals or conceals the value and follows the disabled state.', html`
14
28
  <div class="dees-demo-grid"><dees-input-text label="Password" value="catalog-preview" .isPasswordBool=${true} autocomplete="new-password"></dees-input-text><dees-input-text label="Visible password" value="catalog-preview" .isPasswordBool=${true} .showPasswordBool=${true}></dees-input-text></div>
15
29
  ${demoCode('<dees-input-text label="Password" .isPasswordBool=${true}></dees-input-text>')}`)}
30
+ ${demoSection('Suggestions', 'The field offers values in a list under it. Arrow keys move through them, Enter or a click picks one, Escape closes the list. The host sends the list for what is typed; the field filters nothing.', html`
31
+ <div class="dees-demo-grid"><dees-input-text label="Working directory" placeholder="/home/" .suggestions=${serverPaths} @input=${completePath} @suggestion-select=${(event: CustomEvent) => showDemoResult(event.currentTarget as Element, event.detail.value)}></dees-input-text><dees-input-text label="Region" .suggestions=${regions} @suggestion-select=${(event: CustomEvent) => showDemoResult(event.currentTarget as Element, event.detail.value)}></dees-input-text></div>${demoOutput('Pick a suggestion to see its value.')}
32
+ ${demoCode('<dees-input-text label="Working directory" .suggestions=${paths} @input=${complete} @suggestion-select=${picked}></dees-input-text>')}`)}
16
33
  ${demoSection('Live value', 'Native input events cross the shadow boundary. The result is rendered as text.', html`
17
34
  <dees-input-text class="dees-demo-field" label="Try a workspace name" @input=${(event: Event) => showDemoResult(event.currentTarget as Element, (event.composedPath()[0] as HTMLInputElement).value)}></dees-input-text>${demoOutput()}`)}
18
35
  `);
@@ -1,5 +1,6 @@
1
1
  import { DeesInputBase } from '../dees-input-base/dees-input-base.js';
2
2
  import { textInputContextMenuItems } from '../text-input-contextmenu.js';
3
+ import { inputSuggestion, SuggestionListController, suggestionListStyles, type TInputSuggestion } from '../suggestion-list.js';
3
4
  import { demoFunc } from './dees-input-text.demo.js';
4
5
 
5
6
  import {
@@ -12,6 +13,7 @@ import {
12
13
  css,
13
14
  } from '@design.estate/dees-element';
14
15
  import { insetInlineStyles, themeDefaultStyles } from '../../00theme.js';
16
+ import { overlayScrollbarStyles } from '../../00scrollbars.js';
15
17
  import '../../00group-overlay/dees-contextmenu/dees-contextmenu.js';
16
18
  import { dcLocalize } from '../../../i18n/localize.js';
17
19
 
@@ -21,6 +23,14 @@ declare global {
21
23
  }
22
24
  }
23
25
 
26
+ export type { IInputSuggestion, TInputSuggestion } from '../suggestion-list.js';
27
+
28
+ /** The detail of `suggestion-select`: the value the pick set, and the suggestion as the host gave it. */
29
+ export interface IInputTextSuggestionSelectDetail {
30
+ value: string;
31
+ suggestion: TInputSuggestion;
32
+ }
33
+
24
34
  /** Native input types this field maps to. Anything richer has its own element. */
25
35
  export type TTextInputType = 'text' | 'number' | 'date' | 'email' | 'url' | 'tel' | 'password';
26
36
 
@@ -135,6 +145,34 @@ export class DeesInputText extends DeesInputBase {
135
145
  @property({ type: Number, reflect: true })
136
146
  accessor maxLength = -1;
137
147
 
148
+ /**
149
+ * Values to offer in a list under the field while it has the focus, as a WAI-ARIA combobox: the
150
+ * arrow keys move through them, Enter or a press picks one, Escape closes the list and Tab leaves
151
+ * the field without a pick. A suggestion is the value itself or `{ value, label?, description? }`.
152
+ * The field shows the list as the host gives it and filters nothing: a host that completes the
153
+ * typed text (a path on a server, say) answers `input` with the list for it. A pick sets the
154
+ * value, reports `input` and `change` as typing and leaving the field would, and fires
155
+ * `suggestion-select` with `{ value, suggestion }`.
156
+ *
157
+ * `null`, the default, makes no combobox: the field is a plain text field. An array, even an
158
+ * empty one, makes the field a combobox whose list shows while the array has entries.
159
+ */
160
+ @property({ attribute: false })
161
+ accessor suggestions: TInputSuggestion[] | null = null;
162
+
163
+ /** The suggestions under the field. */
164
+ private readonly suggestionList = new SuggestionListController(this, {
165
+ anchor: () => this.shadowRoot?.querySelector<HTMLElement>('input'),
166
+ pick: (index) => this.pickSuggestion(index),
167
+ });
168
+
169
+ /**
170
+ * The text a pick committed, until the reader edits again. The browser keeps its own `change`
171
+ * baseline, which a value set by script does not move: after typing and a pick it fires `change`
172
+ * again on leaving the field, for the commit the pick already reported.
173
+ */
174
+ private pickedText: string | null = null;
175
+
138
176
  private validTimeout: ReturnType<typeof setTimeout> | undefined;
139
177
 
140
178
  public static styles = [
@@ -142,6 +180,8 @@ export class DeesInputText extends DeesInputBase {
142
180
  ...DeesInputBase.baseStyles,
143
181
  cssManager.defaultStyles,
144
182
  insetInlineStyles('--text-inset-inline'),
183
+ overlayScrollbarStyles,
184
+ suggestionListStyles,
145
185
  css`
146
186
  /* TODO: Migrate hardcoded values to --dees-* CSS variables */
147
187
  * {
@@ -373,7 +413,10 @@ export class DeesInputText extends DeesInputBase {
373
413
  type="${this.nativeInputType}"
374
414
  .value=${this.valueAsText}
375
415
  @input="${this.updateValue}"
376
- @change=${this.forwardNativeChange}
416
+ @change=${this.handleNativeChange}
417
+ @keydown=${this.handleSuggestionKeydown}
418
+ @focus=${this.handleSuggestionFocus}
419
+ @blur=${this.handleSuggestionBlur}
377
420
  .disabled=${this.disabled}
378
421
  ?required=${this.required}
379
422
  aria-label=${this.label}
@@ -393,6 +436,7 @@ export class DeesInputText extends DeesInputBase {
393
436
  <div class="validIcon ${this.validConfirmed ? 'show' : ''}">
394
437
  <dees-icon .icon=${'lucide:Check'}></dees-icon>
395
438
  </div>
439
+ ${this.suggestions ? this.suggestionList.render(this.suggestions.map(inputSuggestion), this.label) : ''}
396
440
  </div>
397
441
  ${this.validationText || this.description ? html`<div class="field-messages">
398
442
  ${this.validationText
@@ -436,6 +480,8 @@ export class DeesInputText extends DeesInputBase {
436
480
 
437
481
  public willUpdate(changedProperties: Map<PropertyKey, unknown>): void {
438
482
  super.willUpdate(changedProperties);
483
+ // A new list highlights nothing: the option at the old index is another suggestion now.
484
+ if (changedProperties.has('suggestions')) this.suggestionList.highlight(-1);
439
485
  if (!changedProperties.has('value') && !changedProperties.has('type')) return;
440
486
  const normalized = this.normalizeValue(this.value);
441
487
  if (normalized !== this.value) this.value = normalized;
@@ -466,6 +512,7 @@ export class DeesInputText extends DeesInputBase {
466
512
  } else {
467
513
  input.removeAttribute('maxlength');
468
514
  }
515
+ this.suggestionList.applyComboboxAttributes(input, this.suggestions?.length ?? 0, this.suggestions !== null);
469
516
  }
470
517
 
471
518
  firstUpdated() {
@@ -486,6 +533,18 @@ export class DeesInputText extends DeesInputBase {
486
533
  public async updateValue(eventArg: Event) {
487
534
  const target = eventArg.target as HTMLInputElement;
488
535
  this.value = this.normalizeValue(target.value);
536
+ this.pickedText = null;
537
+ if (this.suggestions) {
538
+ // Typing opens a list Escape or a pick closed, and highlights nothing in it.
539
+ this.suggestionList.show();
540
+ this.suggestionList.highlight(-1);
541
+ }
542
+ this.runValidationFunction();
543
+ this.changeSubject.next(this);
544
+ }
545
+
546
+ /** Runs `validationFunction` on the value, as each edit of the reader does. */
547
+ private runValidationFunction(): void {
489
548
  if (this.validationFunction) {
490
549
  const result = this.validationFunction(this.valueAsText);
491
550
  this.validationState = result.valid ? 'valid' : 'invalid';
@@ -502,7 +561,53 @@ export class DeesInputText extends DeesInputBase {
502
561
  this.validConfirmed = false;
503
562
  }
504
563
  }
564
+ }
565
+
566
+ /** Reports the native field's `change`, unless it repeats the commit of a pick. */
567
+ private handleNativeChange = (eventArg: Event): void => {
568
+ const repeatsPick = this.pickedText !== null && this.pickedText === this.valueAsText;
569
+ this.pickedText = null;
570
+ if (repeatsPick) {
571
+ eventArg.stopPropagation();
572
+ return;
573
+ }
574
+ this.forwardNativeChange(eventArg);
575
+ };
576
+
577
+ private handleSuggestionKeydown = (eventArg: KeyboardEvent): void => {
578
+ if (!this.suggestions || this.disabled) return;
579
+ // ArrowDown opens a list Escape or a pick closed, and moves to its first option.
580
+ if (eventArg.key === 'ArrowDown' && !eventArg.isComposing && this.suggestions.length) this.suggestionList.show();
581
+ this.suggestionList.handleKeydown(eventArg, this.suggestions.length);
582
+ };
583
+
584
+ private handleSuggestionFocus = (): void => {
585
+ if (this.suggestions) this.suggestionList.show();
586
+ };
587
+
588
+ private handleSuggestionBlur = (): void => {
589
+ this.suggestionList.hide();
590
+ };
591
+
592
+ /**
593
+ * Sets the value of the suggestion at `indexArg`, as the reader's own edit: `validationFunction`
594
+ * runs, `input` and `change` report it, and `suggestion-select` names the suggestion. The list
595
+ * closes; typing or ArrowDown opens it again.
596
+ */
597
+ private pickSuggestion(indexArg: number): void {
598
+ const suggestion = this.suggestions?.[indexArg];
599
+ if (suggestion === undefined || this.disabled) return;
600
+ const value = inputSuggestion(suggestion).value;
601
+ this.value = this.normalizeValue(value);
602
+ const input = this.shadowRoot?.querySelector('input');
603
+ if (input) input.value = this.valueAsText;
604
+ this.pickedText = this.valueAsText;
605
+ this.suggestionList.hide();
606
+ this.runValidationFunction();
505
607
  this.changeSubject.next(this);
608
+ this.reportValueCommit();
609
+ const detail: IInputTextSuggestionSelectDetail = { value, suggestion };
610
+ this.dispatchEvent(new CustomEvent('suggestion-select', { detail, bubbles: true, composed: true }));
506
611
  }
507
612
 
508
613
  public getContextMenuItems() {