@melodicdev/components 3.0.0 → 3.1.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.
@@ -70,6 +70,8 @@ export declare class SelectComponent implements IElementRef, OnCreate, OnDestroy
70
70
  private readonly _positioner;
71
71
  private _lastCloseTime;
72
72
  private _syncingValues;
73
+ private _typeaheadBuffer;
74
+ private _typeaheadLastTime;
73
75
  onCreate(): void;
74
76
  onDestroy(): void;
75
77
  onPropertyChange(name: string): void;
@@ -112,6 +114,12 @@ export declare class SelectComponent implements IElementRef, OnCreate, OnDestroy
112
114
  private getDropdownEl;
113
115
  /** Handle keyboard navigation */
114
116
  private onKeyDown;
117
+ /** Native-select-style type-to-jump: accumulate printable characters and jump to the matching option */
118
+ private handleTypeahead;
119
+ /** Find the first enabled option whose label starts with query, searching forward from startIndex + 1 and wrapping */
120
+ private findTypeaheadMatch;
121
+ /** Keep the keyboard-focused option visible within the scrollable dropdown */
122
+ private scrollFocusedOptionIntoView;
115
123
  /** Move focus to next enabled option */
116
124
  private focusNextOption;
117
125
  /** Move focus to previous enabled option */
@@ -1 +1 @@
1
- {"version":3,"file":"select.component.d.ts","sourceRoot":"","sources":["../../../../src/components/forms/select/select.component.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAEzE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAqBtD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,qBAMa,eAAgB,YAAW,WAAW,EAAE,QAAQ,EAAE,SAAS;IAChE,UAAU,EAAG,WAAW,CAAC;IAEhC,iBAAiB;IACV,KAAK,SAAM;IAElB,yCAAyC;IAClC,WAAW,SAAsB;IAExC,mCAAmC;IAC5B,IAAI,SAAM;IAEjB,i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CAAC,mBAAmB;IAe3B,sCAAsC;IACtC,OAAO,CAAC,qBAAqB;IAI7B,qCAAqC;IACrC,OAAO,CAAC,oBAAoB;IAU5B,OAAO,CAAC,oBAAoB;IAoB5B,OAAO,CAAC,gBAAgB;IAIxB,OAAO,CAAC,YAAY;IAMpB,OAAO,CAAC,cAAc;CAOtB"}
@@ -26,6 +26,8 @@ registerAdapter((el) => el.tagName === 'ML-SELECT', {
26
26
  },
27
27
  setDisabled: (el, disabled) => { el.disabled = disabled; }
28
28
  });
29
+ /** Idle time after which the typeahead buffer resets (matches native select behavior) */
30
+ const TYPEAHEAD_RESET_MS = 700;
29
31
  /**
30
32
  * ml-select - Custom select/dropdown component
31
33
  *
@@ -99,6 +101,8 @@ let SelectComponent = class SelectComponent {
99
101
  }));
100
102
  this._lastCloseTime = 0;
101
103
  this._syncingValues = false;
104
+ this._typeaheadBuffer = '';
105
+ this._typeaheadLastTime = 0;
102
106
  /** Unique id for the option at the given display index */
103
107
  this.optionId = (index) => {
104
108
  return `${this.listboxId}-option-${index}`;
@@ -299,6 +303,7 @@ let SelectComponent = class SelectComponent {
299
303
  this.isOpen = false;
300
304
  this.focusedIndex = -1;
301
305
  this.search = '';
306
+ this._typeaheadBuffer = '';
302
307
  this._lastCloseTime = Date.now();
303
308
  this.stopPositioning();
304
309
  this.elementRef.dispatchEvent(new CustomEvent('ml:close', { bubbles: true, composed: true }));
@@ -363,21 +368,76 @@ let SelectComponent = class SelectComponent {
363
368
  event.preventDefault();
364
369
  if (this.isOpen) {
365
370
  this.focusedIndex = this.findFirstEnabledIndex();
371
+ this.scrollFocusedOptionIntoView();
366
372
  }
367
373
  break;
368
374
  case 'End':
369
375
  event.preventDefault();
370
376
  if (this.isOpen) {
371
377
  this.focusedIndex = this.findLastEnabledIndex();
378
+ this.scrollFocusedOptionIntoView();
372
379
  }
373
380
  break;
374
381
  case 'Tab':
375
382
  this.close();
376
383
  break;
377
384
  default:
385
+ if (!isSearchInput) {
386
+ this.handleTypeahead(event);
387
+ }
378
388
  break;
379
389
  }
380
390
  }
391
+ /** Native-select-style type-to-jump: accumulate printable characters and jump to the matching option */
392
+ handleTypeahead(event) {
393
+ if (event.key.length !== 1 || event.ctrlKey || event.metaKey || event.altKey)
394
+ return;
395
+ event.preventDefault();
396
+ const now = Date.now();
397
+ if (now - this._typeaheadLastTime > TYPEAHEAD_RESET_MS) {
398
+ this._typeaheadBuffer = '';
399
+ }
400
+ this._typeaheadLastTime = now;
401
+ this._typeaheadBuffer += event.key.toLowerCase();
402
+ // Repeated presses of the same letter cycle through its matches instead of matching "mm..."
403
+ const isRepeatedChar = this._typeaheadBuffer.length > 1 &&
404
+ this._typeaheadBuffer.split('').every((char) => char === this._typeaheadBuffer[0]);
405
+ const query = isRepeatedChar ? this._typeaheadBuffer[0] : this._typeaheadBuffer;
406
+ const options = this.getActiveOptions();
407
+ const startIndex = this.isOpen
408
+ ? this.focusedIndex
409
+ : options.findIndex((opt) => opt.value === this.value);
410
+ const matchIndex = this.findTypeaheadMatch(query, startIndex);
411
+ if (matchIndex < 0)
412
+ return;
413
+ if (this.isOpen) {
414
+ this.focusedIndex = matchIndex;
415
+ this.scrollFocusedOptionIntoView();
416
+ return;
417
+ }
418
+ if (this.multiple)
419
+ return;
420
+ this.selectOption(options[matchIndex]);
421
+ }
422
+ /** Find the first enabled option whose label starts with query, searching forward from startIndex + 1 and wrapping */
423
+ findTypeaheadMatch(query, startIndex) {
424
+ const options = this.getActiveOptions();
425
+ for (let offset = 1; offset <= options.length; offset++) {
426
+ const index = (startIndex + offset) % options.length;
427
+ const option = options[index];
428
+ if (!option.disabled && option.label.toLowerCase().startsWith(query)) {
429
+ return index;
430
+ }
431
+ }
432
+ return -1;
433
+ }
434
+ /** Keep the keyboard-focused option visible within the scrollable dropdown */
435
+ scrollFocusedOptionIntoView() {
436
+ if (this.focusedIndex < 0)
437
+ return;
438
+ const optionEl = this.elementRef.shadowRoot?.getElementById(this.optionId(this.focusedIndex));
439
+ optionEl?.scrollIntoView({ block: 'nearest' });
440
+ }
381
441
  /** Move focus to next enabled option */
382
442
  focusNextOption() {
383
443
  const startIndex = this.focusedIndex;
@@ -386,6 +446,7 @@ let SelectComponent = class SelectComponent {
386
446
  while (index < options.length) {
387
447
  if (!options[index].disabled) {
388
448
  this.focusedIndex = index;
449
+ this.scrollFocusedOptionIntoView();
389
450
  return;
390
451
  }
391
452
  index++;
@@ -399,6 +460,7 @@ let SelectComponent = class SelectComponent {
399
460
  while (index >= 0) {
400
461
  if (!options[index].disabled) {
401
462
  this.focusedIndex = index;
463
+ this.scrollFocusedOptionIntoView();
402
464
  return;
403
465
  }
404
466
  index--;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@melodicdev/components",
3
- "version": "3.0.0",
3
+ "version": "3.1.0",
4
4
  "description": "Themeable UI component library built on the Melodic Framework",
5
5
  "license": "MIT",
6
6
  "author": "Melodic Development",