@kirbydesign/extensions-angular 5.1.0 → 6.0.0-dev-d045bb2

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 (28) hide show
  1. package/fesm2022/kirbydesign-extensions-angular-combobox.mjs +897 -852
  2. package/fesm2022/kirbydesign-extensions-angular-combobox.mjs.map +1 -1
  3. package/fesm2022/kirbydesign-extensions-angular-image-banner.mjs +206 -128
  4. package/fesm2022/kirbydesign-extensions-angular-image-banner.mjs.map +1 -1
  5. package/fesm2022/kirbydesign-extensions-angular-localization.mjs +541 -411
  6. package/fesm2022/kirbydesign-extensions-angular-localization.mjs.map +1 -1
  7. package/fesm2022/kirbydesign-extensions-angular-sidebar-menu.mjs +1462 -603
  8. package/fesm2022/kirbydesign-extensions-angular-sidebar-menu.mjs.map +1 -1
  9. package/fesm2022/kirbydesign-extensions-angular-skeleton-loader.mjs +79 -40
  10. package/fesm2022/kirbydesign-extensions-angular-skeleton-loader.mjs.map +1 -1
  11. package/fesm2022/kirbydesign-extensions-angular-spot-illustration.mjs +164 -155
  12. package/fesm2022/kirbydesign-extensions-angular-spot-illustration.mjs.map +1 -1
  13. package/fesm2022/kirbydesign-extensions-angular.mjs +1 -8
  14. package/fesm2022/kirbydesign-extensions-angular.mjs.map +1 -1
  15. package/package.json +13 -13
  16. package/types/kirbydesign-extensions-angular-combobox.d.ts +273 -216
  17. package/types/kirbydesign-extensions-angular-image-banner.d.ts +102 -66
  18. package/types/kirbydesign-extensions-angular-localization.d.ts +185 -204
  19. package/types/kirbydesign-extensions-angular-sidebar-menu.d.ts +137 -120
  20. package/types/kirbydesign-extensions-angular-skeleton-loader.d.ts +23 -17
  21. package/types/kirbydesign-extensions-angular-spot-illustration.d.ts +224 -212
  22. package/types/kirbydesign-extensions-angular.d.ts +2 -2
  23. package/combobox/package.json +0 -4
  24. package/image-banner/package.json +0 -4
  25. package/localization/package.json +0 -4
  26. package/sidebar-menu/package.json +0 -4
  27. package/skeleton-loader/package.json +0 -4
  28. package/spot-illustration/package.json +0 -4
@@ -1,855 +1,900 @@
1
- import * as i0 from '@angular/core';
2
- import { EventEmitter, RendererStyleFlags2, ElementRef, TemplateRef, forwardRef, HostListener, ContentChildren, ViewChildren, ViewChild, ContentChild, HostBinding, Output, Input, ChangeDetectionStrategy, Component } from '@angular/core';
3
- import { NG_VALUE_ACCESSOR } from '@angular/forms';
4
- import { CardComponent } from '@kirbydesign/designsystem/card';
5
- import { UniqueIdGenerator } from '@kirbydesign/designsystem/helpers';
6
- import { ItemComponent } from '@kirbydesign/designsystem/item';
7
- import { ListItemTemplateDirective } from '@kirbydesign/designsystem/list';
8
- import { HorizontalDirection, PopoverComponent } from '@kirbydesign/designsystem/popover';
9
- import { InputSize, InputComponent, AffixDirective } from '@kirbydesign/designsystem/form-field';
10
- import { FORM_FIELD_CONTROL } from '@kirbydesign/designsystem/types';
11
- import * as i1 from '@kirbydesign/designsystem/shared';
12
- import { forwardAttributes } from '@kirbydesign/designsystem/shared';
13
- import { IconComponent } from '@kirbydesign/designsystem/icon';
14
- import { NgTemplateOutlet } from '@angular/common';
15
- import { CdkFixedSizeVirtualScroll, CdkVirtualScrollViewport, CdkVirtualForOf } from '@angular/cdk/scrolling';
16
-
1
+ import * as i0 from "@angular/core";
2
+ import { ChangeDetectionStrategy, Component, ContentChild, ContentChildren, ElementRef, EventEmitter, HostBinding, HostListener, Input, Output, RendererStyleFlags2, TemplateRef, ViewChild, ViewChildren, forwardRef } from "@angular/core";
3
+ import { NG_VALUE_ACCESSOR } from "@angular/forms";
4
+ import { CardComponent } from "@kirbydesign/designsystem/card";
5
+ import { UniqueIdGenerator } from "@kirbydesign/designsystem/helpers";
6
+ import { ItemComponent } from "@kirbydesign/designsystem/item";
7
+ import { ListItemTemplateDirective } from "@kirbydesign/designsystem/list";
8
+ import { HorizontalDirection, PopoverComponent } from "@kirbydesign/designsystem/popover";
9
+ import { AffixDirective, InputComponent, InputSize } from "@kirbydesign/designsystem/form-field";
10
+ import { FORM_FIELD_CONTROL } from "@kirbydesign/designsystem/types";
11
+ import * as i1 from "@kirbydesign/designsystem/shared";
12
+ import { forwardAttributes } from "@kirbydesign/designsystem/shared";
13
+ import { IconComponent } from "@kirbydesign/designsystem/icon";
14
+ import { NgTemplateOutlet } from "@angular/common";
15
+ import { CdkFixedSizeVirtualScroll, CdkVirtualForOf, CdkVirtualScrollViewport } from "@angular/cdk/scrolling";
17
16
  var OpenState;
18
- (function (OpenState) {
19
- OpenState[OpenState["closed"] = 0] = "closed";
20
- OpenState[OpenState["opening"] = 1] = "opening";
21
- OpenState[OpenState["open"] = 2] = "open";
17
+ (function(OpenState) {
18
+ OpenState[OpenState["closed"] = 0] = "closed";
19
+ OpenState[OpenState["opening"] = 1] = "opening";
20
+ OpenState[OpenState["open"] = 2] = "open";
22
21
  })(OpenState || (OpenState = {}));
23
-
24
- class ComboboxComponent {
25
- static { this.HEIGHT_OF_STANDARD_ITEM = 44; }
26
- compareAlphabetically(textA, textB) {
27
- if (textA < textB) {
28
- return -1;
29
- }
30
- if (textA > textB) {
31
- return 1;
32
- }
33
- return 0;
34
- }
35
- getItemText(item) {
36
- if (this.isTypeString(item)) {
37
- return item;
38
- }
39
- if (this.objectHasItemTextProperty(item)) {
40
- const objectItem = item;
41
- const textValue = objectItem[this.itemTextProperty];
42
- if (typeof textValue === 'string') {
43
- return textValue;
44
- }
45
- }
46
- return '';
47
- }
48
- get dropdownMaxHeight() {
49
- return 8 * ComboboxComponent.HEIGHT_OF_STANDARD_ITEM;
50
- }
51
- get dropdownMinHeight() {
52
- return this.itemHeight;
53
- }
54
- get viewportHeight() {
55
- const itemCount = this.searchItems?.length ?? 0;
56
- if (itemCount === 0) {
57
- return this.dropdownMinHeight;
58
- }
59
- return Math.min(this.dropdownMaxHeight, Math.max(this.dropdownMinHeight, itemCount * this.itemHeight));
60
- }
61
- isTypeString(item) {
62
- return typeof item === 'string';
63
- }
64
- objectHasItemTextProperty(item) {
65
- return item != undefined && typeof item === 'object' && this.itemTextProperty in item;
66
- }
67
- objectHasItemIdProperty(item) {
68
- return item != undefined && typeof item === 'object' && this.itemIdProperty in item;
69
- }
70
- getItemId(item) {
71
- if (this.isTypeString(item)) {
72
- return item;
73
- }
74
- if (this.objectHasItemIdProperty(item)) {
75
- const objectItem = item;
76
- const idValue = objectItem[this.itemIdProperty];
77
- if (this.isTypeString(idValue)) {
78
- return idValue;
79
- }
80
- }
81
- console.error('Each item must have an id property for scroll to work. Ensure that the itemIdProperty input is set correctly, and that each item has a unique id value.');
82
- return '';
83
- }
84
- get searchItems() {
85
- return this._searchItems;
86
- }
87
- set searchItems(value) {
88
- this._searchItems = value;
89
- if (!this._searchItems) {
90
- return;
91
- }
92
- // only set the focused item of the search result, if the input has value
93
- if (this.textInput?.nativeElement?.value) {
94
- this.focusedItem = this._searchItems[0];
95
- this._virtualScrollViewport?.scrollToIndex(0);
96
- }
97
- }
98
- get items() {
99
- return this._items;
100
- }
101
- /**
102
- * The list of items to display in the dropdown.
103
- * @param value
104
- */
105
- set items(value) {
106
- this._items = value;
107
- this.searchItems = this._items;
108
- }
109
- get selectedItem() {
110
- return this._selectedItem;
111
- }
112
- /**
113
- * The currently selected item.
114
- * @param value
115
- */
116
- set selectedItem(value) {
117
- // Allow clearing by setting undefined
118
- if (value !== this._selectedItem) {
119
- this._selectedItem = value;
120
- this.focusedItem = this._selectedItem;
121
- // Keep ControlValueAccessor value in sync with the selected data item
122
- this.value = this._selectedItem;
123
- this.setInputDisplayValue(this.getItemText(this.selectedItem));
124
- }
125
- }
126
- get focusedItem() {
127
- return this._focusedItem;
128
- }
129
- set focusedItem(item) {
130
- // the focus might not have changed, but where in the list might
131
- this.setAriaPosinsetOnElement(item);
132
- if (this._focusedItem === item) {
133
- return;
134
- }
135
- this._focusedItem = item;
136
- }
137
- getIndexOfItem(item) {
138
- return this.searchItems.indexOf(item);
139
- }
140
- getKirbyElement(item) {
141
- const kirbyItems = this.getKirbyItems();
142
- if (!kirbyItems || !item) {
143
- return undefined;
144
- }
145
- const itemId = this.getItemId(item);
146
- return kirbyItems.find((el) => el.nativeElement.id === itemId);
147
- }
148
- setAriaPosinsetOnElement(item) {
149
- const element = this.getKirbyElement(item);
150
- const index = this.getIndexOfItem(item);
151
- const setsize = this.searchItems.length;
152
- if (!element) {
153
- return;
154
- }
155
- this.renderer.setAttribute(element.nativeElement, 'aria-setsize', setsize.toString());
156
- this.renderer.setAttribute(element.nativeElement, 'aria-posinset', `${index + 1}`);
157
- }
158
- /**
159
- * The direction in which the dropdown should open relative to the input.
160
- * @param direction
161
- */
162
- set popout(direction) {
163
- this._popout = direction || HorizontalDirection.right;
164
- }
165
- get popout() {
166
- return this._popout;
167
- }
168
- get _isDisabled() {
169
- return this.disabled ? 'disabled' : null;
170
- }
171
- /**
172
- * When `true`, the combobox will be styled with error styles.
173
- */
174
- get hasError() {
175
- return this._hasError;
176
- }
177
- set hasError(value) {
178
- if (this._hasError !== value) {
179
- this._hasError = value;
180
- this.hasErrorChange.emit(this._hasError);
181
- }
182
- }
183
- // Prevent Ionic blur on scroll
184
- get _noBlurOnScroll() {
185
- return true;
186
- }
187
- get _isBlockLevel() {
188
- return this.expand === 'block';
189
- }
190
- get _isOpening() {
191
- return this.state === OpenState.opening;
192
- }
193
- get isOpen() {
194
- return this.state === OpenState.open;
195
- }
196
- get hasValue() {
197
- return this.selectedItem != null;
198
- }
199
- get interactiveElement() {
200
- return this.textInput.nativeElement;
201
- }
202
- forwardAriaLabelToCombobox() {
203
- forwardAttributes(this.elementRef.nativeElement, this._attributesToForward, this.renderer, this.rootElement.nativeElement);
204
- }
205
- set kirbyItemsSlotted(kirbyItems) {
206
- const hasSlottedItems = this.disposeItemClickListeners?.length > 0;
207
- if (hasSlottedItems) {
208
- this.unlistenAllSlottedItems();
209
- }
210
- kirbyItems.forEach((kirbyItem) => {
211
- this.renderer.setAttribute(kirbyItem.nativeElement, 'role', 'option');
212
- const disposeClickListener = this.renderer.listen(kirbyItem.nativeElement, 'click', () => {
213
- const id = kirbyItem.nativeElement.getAttribute('id');
214
- const item = this.items.find((it) => this.getItemId(it) === id);
215
- if (item) {
216
- this.onItemSelect(item);
217
- }
218
- });
219
- this.disposeItemClickListeners.push(disposeClickListener);
220
- });
221
- this._kirbyItemsSlotted = kirbyItems;
222
- }
223
- get kirbyItemsSlotted() {
224
- return this._kirbyItemsSlotted;
225
- }
226
- constructor(renderer, elementRef, cdr, resizeObserverService) {
227
- this.renderer = renderer;
228
- this.elementRef = elementRef;
229
- this.cdr = cdr;
230
- this.resizeObserverService = resizeObserverService;
231
- this.state = OpenState.closed;
232
- this._popout = HorizontalDirection.right;
233
- this._attributesToForward = ['aria-label', 'aria-labelledby'];
234
- this._listboxId = UniqueIdGenerator.scopedTo('kirby-x-combobox').next();
235
- this._comboboxId = UniqueIdGenerator.scopedTo('kirby-input').next();
236
- this._defaultSearchFunction = (searchTerm, itemsToSearch) => {
237
- if (!searchTerm) {
238
- return itemsToSearch;
239
- }
240
- const lowerSearchTerm = searchTerm.toLowerCase();
241
- return itemsToSearch
242
- .filter((item) => this.getItemText(item).toLowerCase().includes(lowerSearchTerm))
243
- .sort((a, b) => {
244
- const textA = this.getItemText(a).toLowerCase();
245
- const textB = this.getItemText(b).toLowerCase();
246
- const textAStartsWith = textA.startsWith(searchTerm);
247
- const textBStartsWith = textB.startsWith(searchTerm);
248
- if (textAStartsWith && textBStartsWith) {
249
- return this.compareAlphabetically(textA, textB);
250
- }
251
- if (textAStartsWith) {
252
- return -1;
253
- }
254
- if (textBStartsWith) {
255
- return 1;
256
- }
257
- return this.compareAlphabetically(textA, textB);
258
- });
259
- };
260
- /**
261
- * The text to display when the search returns no results.
262
- */
263
- this.noSearchResultsText = 'No results found.';
264
- /**
265
- * The text announced by screen readers when the selection is cleared.
266
- */
267
- this.selectionClearedAnnouncement = 'Selection cleared.';
268
- this._liveRegionText = '';
269
- /**
270
- * The name of the property to use as the display text for each item.
271
- */
272
- this.itemTextProperty = 'text';
273
- /**
274
- * The height of each item in the dropdown, in pixels. This is used to calculate the height of the dropdown based on the number of items.
275
- */
276
- this.itemHeight = 44;
277
- /**
278
- * The name of the property to use as the unique identifier for each item.
279
- */
280
- this.itemIdProperty = 'id';
281
- /**
282
- * A function that takes a search term and the list of items, and returns a filtered list of items to display in the dropdown.
283
- */
284
- this.searchFunction = this._defaultSearchFunction;
285
- this._searchItems = [];
286
- this._items = [];
287
- this._selectedItem = undefined;
288
- // _focusedItem keeps track of which element has focus and will be selected
289
- // if it is activated (by pressing ENTER)
290
- this._focusedItem = undefined;
291
- /**
292
- * The placeholder text to display in the input when no item is selected and the input is empty.
293
- */
294
- this.placeholder = 'Please search...';
295
- /**
296
- * When `true`, the user cannot interact with the combobox.
297
- */
298
- this.disabled = false;
299
- /**
300
- * Will emit the new value when error changes.
301
- */
302
- this.hasErrorChange = new EventEmitter();
303
- this._hasError = false;
304
- /**
305
- * The size of the input element.
306
- */
307
- this.size = InputSize.medium;
308
- /**
309
- * Emitted when an item is selected (tap on mobile, click/keypress on web)
310
- */
311
- this.change = new EventEmitter();
312
- this.value = undefined;
313
- this.disposeItemClickListeners = [];
314
- this.onChange = () => {
315
- /* empty */
316
- };
317
- this.onTouched = () => {
318
- /* empty */
319
- };
320
- }
321
- onToggle(event) {
322
- event.stopPropagation();
323
- this.textInput?.nativeElement.focus();
324
- this.toggle();
325
- }
326
- toggle() {
327
- if (this.disabled) {
328
- return;
329
- }
330
- this.isOpen ? this.close() : this.open();
331
- }
332
- ngAfterViewInit() {
333
- if (this.expand === 'block') {
334
- const { width: initialWidth } = this.elementRef.nativeElement.getBoundingClientRect();
335
- this.setPopoverCardStyle('max-width', 'initial');
336
- this.setPopoverCardStyle('min-width', 'initial');
337
- // Ensure initial width is set even if the resize observer callback also fires initially:
338
- this.setPopoverCardStyle('--kirby-card-width', `${initialWidth}px`);
339
- this.resizeObserverService.observe(this.elementRef, (entry) => {
340
- const newWidth = entry.contentRect.width;
341
- if (newWidth > 0) {
342
- this.setPopoverCardStyle('--kirby-card-width', `${newWidth}px`);
343
- }
344
- });
345
- }
346
- this.forwardAriaLabelToCombobox();
347
- }
348
- /* Utility that makes it easier to set styles on card element */
349
- setPopoverCardStyle(style, value) {
350
- this.renderer.setStyle(this.cardElement?.nativeElement, style, value, RendererStyleFlags2.DashCase);
351
- }
352
- ngOnDestroy() {
353
- this.unlistenAllSlottedItems();
354
- this.unobserveResize();
355
- }
356
- open() {
357
- if (this.disabled) {
358
- return;
359
- }
360
- if (!this.isOpen) {
361
- this.state = OpenState.opening;
362
- this.showPopOver();
363
- this.focusedItem = this.selectedItem;
364
- }
365
- }
366
- showPopOver() {
367
- if (this.state === OpenState.opening) {
368
- this.state = OpenState.open;
369
- this.popover?.show();
370
- this.cdr.markForCheck();
371
- // PopoverComponent.show() appends the element to document.body synchronously but
372
- // finishes positioning in a requestAnimationFrame. One rAF is enough to let the
373
- // browser compute layout so the CDK viewport has a real size before we scroll.
374
- requestAnimationFrame(() => this.scrollToIndexIntoViewWhenOpeningPopup());
375
- }
376
- }
377
- close() {
378
- if (this.disabled) {
379
- return;
380
- }
381
- if (this.isOpen) {
382
- this.state = OpenState.closed;
383
- this.setInputDisplayValue(this.getItemText(this.selectedItem));
384
- this.searchItems = this.items;
385
- this.popover?.hide();
386
- }
387
- }
388
- onItemSelect(item) {
389
- // Guard: slotted click listeners should map back to a data item, but be safe.
390
- if (item instanceof HTMLElement)
391
- return;
392
- this.selectItem(item);
393
- this.close();
394
- }
395
- /**
396
- * Sets the select's value. Part of the ControlValueAccessor interface
397
- * required to integrate with Angular's core forms API.
398
- *
399
- * @param value New value to be written to the model.
400
- */
401
- writeValue(value) {
402
- this.selectItemByInput(value);
403
- // When written from outside, reflect selected text in the input
404
- this.setInputDisplayValue(this.getItemText(this.value));
405
- this.cdr.markForCheck();
406
- }
407
- /**
408
- * Saves a callback function to be invoked when the select's value
409
- * changes from user input. Part of the ControlValueAccessor interface
410
- * required to integrate with Angular's core forms API.
411
- *
412
- * @param fn Callback to be triggered when the value changes.
413
- */
414
- registerOnChange(fn) {
415
- this.onChange = fn;
416
- }
417
- /**
418
- * Saves a callback function to be invoked when the select is blurred
419
- * by the user. Part of the ControlValueAccessor interface required
420
- * to integrate with Angular's core forms API.
421
- *
422
- * @param fn Callback to be triggered when the component has been touched.
423
- */
424
- registerOnTouched(fn) {
425
- this.onTouched = fn;
426
- }
427
- /**
428
- * Disables the select. Part of the ControlValueAccessor interface required
429
- * to integrate with Angular's core forms API.
430
- *
431
- * @param isDisabled Sets whether the component is disabled.
432
- */
433
- setDisabledState(isDisabled) {
434
- this.disabled = isDisabled;
435
- this.cdr.markForCheck();
436
- }
437
- selectItem(item) {
438
- if (item != this.selectedItem) {
439
- this.selectedItem = item;
440
- this.focusedItem = item;
441
- this.change.emit(this.value);
442
- this.onChange(this.value);
443
- this.setInputDisplayValue(this.getItemText(item));
444
- this.searchItems = this.items;
445
- }
446
- }
447
- selectItemByInput(input) {
448
- this.selectedItem = this.findItemByInput(input);
449
- }
450
- onInput(event) {
451
- if (!this.isOpen) {
452
- this.open();
453
- }
454
- const input = event.target;
455
- if (!input.value) {
456
- this.clearSelection();
457
- }
458
- this.updateSearchResults(input.value);
459
- // Screen readers (VoiceOver/NVDA) may move real browser focus to a list-item button.
460
- // When the list re-renders after filtering, that button is removed from the DOM and
461
- // focus falls to `document.body`. Restore it to the input so the user can keep typing
462
- // and the focusout handler doesn't mistake the body-focus for a genuine blur-away.
463
- if (document.activeElement !== this.textInput?.nativeElement) {
464
- this.textInput?.nativeElement.focus();
465
- }
466
- }
467
- clearSelection() {
468
- this.selectItem(undefined);
469
- // Reset after a short delay so the same message can be announced again on subsequent clears
470
- this.announce(this.selectionClearedAnnouncement);
471
- }
472
- announce(message) {
473
- clearTimeout(this._announceTimeout);
474
- this._liveRegionText = '';
475
- this._announceTimeout = setTimeout(() => {
476
- this._liveRegionText = message;
477
- this.cdr.markForCheck();
478
- }, 100);
479
- }
480
- updateSearchResults(inputValue) {
481
- this.searchItems = inputValue ? this.searchFunction(inputValue, this.items) : this.items;
482
- if (inputValue && this.searchItems.length === 0) {
483
- this.announce(this.noSearchResultsText);
484
- }
485
- }
486
- onPopoverWillHide() {
487
- this.state = OpenState.closed;
488
- this.rootElement.nativeElement.focus();
489
- this.onTouched();
490
- }
491
- onPopoverClick() {
492
- this.close();
493
- }
494
- onMouseDown(event) {
495
- if (this.disabled) {
496
- event.preventDefault();
497
- event.stopImmediatePropagation();
498
- }
499
- }
500
- onTouchStart(event) {
501
- if (this.isOpen) {
502
- event.stopPropagation();
503
- }
504
- }
505
- onFocusOut() {
506
- // Defer the check to allow the browser (and screen readers like VoiceOver/NVDA)
507
- // to settle focus. `relatedTarget` is often `null` with screen readers, so we
508
- // inspect `document.activeElement` after the microtask queue has flushed.
509
- setTimeout(() => {
510
- const activeElement = document.activeElement;
511
- const isOnTriggerButton = activeElement && this.elementRef.nativeElement.contains(activeElement);
512
- const isInsidePopover = activeElement && activeElement.closest('kirby-popover');
513
- if (isOnTriggerButton || isInsidePopover) {
514
- // Focus is still within the component — nothing to do.
515
- return;
516
- }
517
- // When a screen reader (VoiceOver/NVDA) moves real focus to a list-item button
518
- // and the user then types a character, CDK virtual scroll re-renders the list and
519
- // removes the focused button from the DOM. The browser then drops focus to
520
- // `document.body`. Detect this case: if the popover is still showing and focus is
521
- // on the body, it means focus was lost due to DOM removal — restore it to the
522
- // input rather than closing the popover.
523
- if (this.isOpen && activeElement === document.body) {
524
- this.textInput?.nativeElement.focus();
525
- return;
526
- }
527
- if (this.isOpen) {
528
- this.close();
529
- }
530
- this.onTouched();
531
- }, 0);
532
- }
533
- onTab() {
534
- if (this.isOpen) {
535
- this.selectItem(this.focusedItem);
536
- this.close();
537
- }
538
- }
539
- onEscape() {
540
- this.close();
541
- }
542
- onEnter(event) {
543
- event.preventDefault();
544
- event.stopPropagation();
545
- if (this.isOpen) {
546
- this.selectItem(this.focusedItem);
547
- }
548
- this.toggle();
549
- }
550
- onArrowKeys(event) {
551
- if (this.disabled)
552
- return;
553
- const keyEvent = event; // safe in this context
554
- // Avoid page scroll
555
- event.preventDefault();
556
- if (!this.isOpen) {
557
- this.open();
558
- if (this.selectedItem) {
559
- this.setFocusOnSelectedItem();
560
- }
561
- else {
562
- this.setFocusOnFirstOrLastItem(keyEvent);
563
- }
564
- }
565
- else {
566
- this.handleFocusNavigation(keyEvent);
567
- }
568
- }
569
- handleFocusNavigation(keyEvent) {
570
- switch (keyEvent.key) {
571
- case 'ArrowDown':
572
- this.shiftFocusIndex(1);
573
- break;
574
- case 'ArrowUp':
575
- this.shiftFocusIndex(-1);
576
- break;
577
- case 'PageDown':
578
- this.shiftFocusIndex(10);
579
- break;
580
- case 'PageUp':
581
- this.shiftFocusIndex(-10);
582
- break;
583
- case 'Home':
584
- this.setFocusOnFirstItem();
585
- break;
586
- case 'End':
587
- this.setFocusOnLastItem();
588
- break;
589
- default:
590
- break;
591
- }
592
- }
593
- shiftFocusIndex(numberOfItems) {
594
- // Handle up/down navigation when open
595
- const currentIndex = this.searchItems.indexOf(this.focusedItem);
596
- let newIndex;
597
- if (numberOfItems > 0) {
598
- newIndex = Math.min(this.searchItems.length - 1, currentIndex + numberOfItems);
599
- }
600
- else {
601
- newIndex = Math.max(0, currentIndex + numberOfItems);
602
- }
603
- if (newIndex !== currentIndex) {
604
- this.focusedItem = this.searchItems[newIndex];
605
- }
606
- this.scrollFocusedItemIntoViewWhileNavigating();
607
- }
608
- setFocusOnFirstOrLastItem(keyEvent) {
609
- switch (keyEvent.key) {
610
- case 'ArrowDown':
611
- case 'PageDown':
612
- case 'Home':
613
- this.setFocusOnFirstItem();
614
- break;
615
- case 'ArrowUp':
616
- case 'PageUp':
617
- case 'End':
618
- this.setFocusOnLastItem();
619
- break;
620
- default:
621
- break;
622
- }
623
- }
624
- setFocusOnSelectedItem() {
625
- if (this.selectedItem) {
626
- this.focusedItem = this.selectedItem;
627
- }
628
- }
629
- setFocusOnLastItem() {
630
- if (this.searchItems.length > 0) {
631
- this.focusedItem = this.searchItems[this.searchItems.length - 1];
632
- }
633
- }
634
- setFocusOnFirstItem() {
635
- if (this.searchItems.length > 0) {
636
- this.focusedItem = this.searchItems[0];
637
- }
638
- }
639
- unlistenAllSlottedItems() {
640
- let disposeClickListener;
641
- while ((disposeClickListener = this.disposeItemClickListeners.pop()) !== undefined) {
642
- disposeClickListener();
643
- }
644
- }
645
- unobserveResize() {
646
- this.resizeObserverService.unobserve(this.elementRef);
647
- }
648
- /**
649
- * Resolve a model/data item based on current `items` by comparing displayed text.
650
- * This is used to map an incoming form value or input `selectedItem` to an item
651
- * from the list.
652
- */
653
- findItemByInput(input) {
654
- if (!this.items || this.items.length === 0) {
655
- return input;
656
- }
657
- return this.items.find((it) => this.getItemText(it) === input) ?? input;
658
- }
659
- setInputDisplayValue(value) {
660
- // We intentionally update the DOM input imperatively ("hard way")
661
- // to ensure the visible value is cleared/updated immediately.
662
- if (this.interactiveElement) {
663
- this.renderer.setProperty(this.interactiveElement, 'value', value);
664
- }
665
- }
666
- scrollFocusedItemIntoViewWhileNavigating() {
667
- if (!this.focusedItem || !this._virtualScrollViewport) {
668
- return;
669
- }
670
- const focusedIndex = this.searchItems.indexOf(this.focusedItem);
671
- if (focusedIndex === -1)
672
- return;
673
- const itemTop = focusedIndex * this.itemHeight;
674
- const itemBottom = itemTop + this.itemHeight;
675
- const scrollOffset = this._virtualScrollViewport.measureScrollOffset();
676
- const viewportSize = this._virtualScrollViewport.getViewportSize();
677
- if (itemTop < scrollOffset) {
678
- // Item is above the visible area — scroll up so item appears at the top.
679
- this._virtualScrollViewport.scrollToOffset(itemTop);
680
- }
681
- else if (itemBottom > scrollOffset + viewportSize) {
682
- // Item is below the visible area — scroll down so item appears at the bottom.
683
- this._virtualScrollViewport.scrollToOffset(itemBottom - viewportSize);
684
- }
685
- this._virtualScrollViewport.checkViewportSize();
686
- }
687
- getKirbyItems() {
688
- return this.kirbyItemsSlotted && this.kirbyItemsSlotted.length
689
- ? this.kirbyItemsSlotted
690
- : this.kirbyItemsDefault;
691
- }
692
- scrollToIndexIntoViewWhenOpeningPopup() {
693
- const focusedIndex = this.searchItems.indexOf(this.focusedItem);
694
- this._virtualScrollViewport?.setRenderedRange({ start: 0, end: 20 });
695
- this._virtualScrollViewport?.checkViewportSize();
696
- this._virtualScrollViewport?.scrollToIndex(focusedIndex);
697
- }
698
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.23", ngImport: i0, type: ComboboxComponent, deps: [{ token: i0.Renderer2 }, { token: i0.ElementRef }, { token: i0.ChangeDetectorRef }, { token: i1.ResizeObserverService }], target: i0.ɵɵFactoryTarget.Component }); }
699
- static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.23", type: ComboboxComponent, isStandalone: true, selector: "kirby-x-combobox", inputs: { noSearchResultsText: "noSearchResultsText", selectionClearedAnnouncement: "selectionClearedAnnouncement", itemTextProperty: "itemTextProperty", itemHeight: "itemHeight", itemIdProperty: "itemIdProperty", searchFunction: "searchFunction", items: "items", selectedItem: "selectedItem", placeholder: "placeholder", popout: "popout", expand: "expand", disabled: "disabled", hasError: "hasError", size: "size" }, outputs: { hasErrorChange: "hasErrorChange", change: "change" }, host: { listeners: { "mousedown": "onMouseDown($event)", "touchstart": "onTouchStart($event)", "focusout": "onFocusOut()", "keydown.tab": "onTab()", "keydown.escape": "onEscape()", "keydown.enter": "onEnter($event)", "keydown.arrowUp": "onArrowKeys($event)", "keydown.arrowDown": "onArrowKeys($event)", "keydown.pageUp": "onArrowKeys($event)", "keydown.pageDown": "onArrowKeys($event)", "keydown.home": "onArrowKeys($event)", "keydown.end": "onArrowKeys($event)" }, properties: { "attr.disabled": "this._isDisabled", "attr.no-blur": "this._noBlurOnScroll", "class.expand": "this._isBlockLevel", "class.is-opening": "this._isOpening", "class.is-open": "this.isOpen", "class.has-value": "this.hasValue" } }, providers: [
700
- {
701
- provide: NG_VALUE_ACCESSOR,
702
- useExisting: forwardRef(() => ComboboxComponent),
703
- multi: true,
704
- },
705
- {
706
- provide: FORM_FIELD_CONTROL,
707
- useExisting: forwardRef(() => ComboboxComponent),
708
- },
709
- ], queries: [{ propertyName: "itemTemplate", first: true, predicate: ListItemTemplateDirective, descendants: true, read: TemplateRef }, { propertyName: "slottedItems", predicate: ListItemTemplateDirective, read: ElementRef }, { propertyName: "kirbyItemsSlotted", predicate: ItemComponent, read: ElementRef }], viewQueries: [{ propertyName: "cardElement", first: true, predicate: CardComponent, descendants: true, read: ElementRef }, { propertyName: "popover", first: true, predicate: PopoverComponent, descendants: true }, { propertyName: "rootElement", first: true, predicate: ["rootElement"], descendants: true, read: ElementRef, static: true }, { propertyName: "textInput", first: true, predicate: InputComponent, descendants: true, read: ElementRef, static: true }, { propertyName: "_virtualScrollViewport", first: true, predicate: CdkVirtualScrollViewport, descendants: true }, { propertyName: "kirbyItemsDefault", predicate: ItemComponent, descendants: true, read: ElementRef }], ngImport: i0, template: "<span class=\"kirby-visually-hidden\" aria-live=\"polite\" aria-atomic=\"true\">\n {{ _liveRegionText }}\n</span>\n<div (click)=\"onToggle($event)\" #rootElement>\n <input\n kirby-input\n type=\"text\"\n aria-haspopup=\"listbox\"\n role=\"combobox\"\n [hasError]=\"hasError\"\n [size]=\"size\"\n [disabled]=\"disabled\"\n [placeholder]=\"placeholder\"\n (change)=\"$event.stopPropagation()\"\n [attr.id]=\"_comboboxId\"\n [attr.aria-controls]=\"_listboxId\"\n [attr.aria-expanded]=\"isOpen\"\n [attr.aria-activedescendant]=\"isOpen && focusedItem ? getItemId(focusedItem) : null\"\n (input)=\"onInput($event)\"\n />\n <kirby-icon [name]=\"isOpen ? 'arrow-up' : 'arrow-down'\" kirby-affix=\"suffix\"></kirby-icon>\n</div>\n\n<kirby-popover\n [target]=\"rootElement\"\n [popout]=\"popout\"\n (click)=\"onPopoverClick()\"\n (mousedown)=\"$event.preventDefault()\"\n (willHide)=\"onPopoverWillHide()\"\n>\n <kirby-card [attr.id]=\"_listboxId\" [attr.aria-labelledby]=\"_comboboxId\">\n @if (searchItems.length === 0) {\n <kirby-item>\n <p class=\"kirby-item-title no-results\">{{ noSearchResultsText }}</p>\n </kirby-item>\n } @else {\n <cdk-virtual-scroll-viewport\n class=\"combobox-viewport\"\n role=\"listbox\"\n [itemSize]=\"itemHeight\"\n [style.height.px]=\"viewportHeight\"\n >\n <ng-container *cdkVirtualFor=\"let item of searchItems\">\n <ng-container\n *ngTemplateOutlet=\"\n itemTemplate || defaultItemTemplate;\n context: {\n $implicit: item,\n selected: item === selectedItem,\n focused: item === focusedItem,\n }\n \"\n ></ng-container>\n </ng-container>\n </cdk-virtual-scroll-viewport>\n }\n </kirby-card>\n</kirby-popover>\n\n<ng-template #defaultItemTemplate let-item let-selected=\"selected\" let-focused=\"focused\">\n <kirby-item\n role=\"option\"\n [selectable]=\"true\"\n [selected]=\"selected\"\n [class.focused]=\"focused\"\n [attr.id]=\"getItemId(item)\"\n [attr.aria-selected]=\"selected\"\n (click)=\"onItemSelect(item)\"\n >\n <p class=\"kirby-item-title\">{{ getItemText(item) }}</p>\n @if (selected) {\n <kirby-icon name=\"checkmark-selected\" slot=\"end\"></kirby-icon>\n }\n </kirby-item>\n</ng-template>\n", styles: [".kirby-line-clamp{display:-webkit-box;-webkit-line-clamp:var(--line-clamp, none);-webkit-box-orient:vertical;overflow:hidden}:host:focus-visible{transition:all 80ms linear 0ms;box-shadow:var(--kirby-focus-ring-md-inset);outline:none;border-radius:var(--kirby-border-radius-pill)}:host{display:inline-block;position:relative;max-width:calc(100vw - calc(2 * var(--kirby-spacing-s)))}:host.clicked{box-shadow:none}:host.expand{display:block}:host.expand kirby-card{width:100%;min-width:initial;max-width:initial}:host div{position:relative}:host div>input[kirby-input]{padding-right:var(--kirby-spacing-xl)}:host div>input[kirby-input]:disabled~kirby-icon{color:var(--kirby-semi-dark-shade)}:host div>kirby-icon{position:absolute;top:0;bottom:0;right:var(--kirby-spacing-xs)}:host.has-value>div>input[kirby-input]{text-overflow:ellipsis}kirby-popover{--max-height: 352px}kirby-card{display:flex;flex-direction:column;max-height:352px;overflow:hidden;box-shadow:var(--kirby-elevation-4);max-width:calc(100vw - calc(2 * var(--kirby-spacing-s)));min-width:calc(320px - calc(2 * var(--kirby-spacing-s)))}@media(min-width:321px){kirby-card{min-width:calc(375px - calc(2 * var(--kirby-spacing-s)))}}.combobox-viewport{display:block;width:100%}.no-results{color:var(--kirby-text-color-semi-dark)}\n"], dependencies: [{ kind: "component", type: InputComponent, selector: "input[kirby-input]", inputs: ["type", "size", "borderless", "hasError", "autocomplete", "autocorrect", "value", "maxlength", "inputmode"], outputs: ["hasErrorChange"] }, { kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "component", type: PopoverComponent, selector: "kirby-popover", inputs: ["popout", "target"], outputs: ["willHide"] }, { kind: "component", type: CardComponent, selector: "kirby-card", inputs: ["title", "subtitle", "backgroundImageUrl", "hasPadding", "sizes", "variant"] }, { kind: "component", type: ItemComponent, selector: "kirby-item", inputs: ["disabled", "selected", "disclosure", "selectable", "reorderable", "size", "href", "rotateIcon"] }, { kind: "component", type: IconComponent, selector: "kirby-icon", inputs: ["size", "name"] }, { kind: "directive", type: AffixDirective, selector: "[kirby-affix]", inputs: ["kirby-affix"] }, { kind: "directive", type: CdkFixedSizeVirtualScroll, selector: "cdk-virtual-scroll-viewport[itemSize]", inputs: ["itemSize", "minBufferPx", "maxBufferPx"] }, { kind: "component", type: CdkVirtualScrollViewport, selector: "cdk-virtual-scroll-viewport", inputs: ["orientation", "appendOnly"], outputs: ["scrolledIndexChange"] }, { kind: "directive", type: CdkVirtualForOf, selector: "[cdkVirtualFor][cdkVirtualForOf]", inputs: ["cdkVirtualForOf", "cdkVirtualForTrackBy", "cdkVirtualForTemplate", "cdkVirtualForTemplateCacheSize"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
710
- }
711
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.23", ngImport: i0, type: ComboboxComponent, decorators: [{
712
- type: Component,
713
- args: [{ selector: 'kirby-x-combobox', providers: [
714
- {
715
- provide: NG_VALUE_ACCESSOR,
716
- useExisting: forwardRef(() => ComboboxComponent),
717
- multi: true,
718
- },
719
- {
720
- provide: FORM_FIELD_CONTROL,
721
- useExisting: forwardRef(() => ComboboxComponent),
722
- },
723
- ], imports: [
724
- InputComponent,
725
- NgTemplateOutlet,
726
- PopoverComponent,
727
- CardComponent,
728
- ItemComponent,
729
- IconComponent,
730
- AffixDirective,
731
- CdkFixedSizeVirtualScroll,
732
- CdkVirtualScrollViewport,
733
- CdkVirtualForOf,
734
- ], changeDetection: ChangeDetectionStrategy.OnPush, template: "<span class=\"kirby-visually-hidden\" aria-live=\"polite\" aria-atomic=\"true\">\n {{ _liveRegionText }}\n</span>\n<div (click)=\"onToggle($event)\" #rootElement>\n <input\n kirby-input\n type=\"text\"\n aria-haspopup=\"listbox\"\n role=\"combobox\"\n [hasError]=\"hasError\"\n [size]=\"size\"\n [disabled]=\"disabled\"\n [placeholder]=\"placeholder\"\n (change)=\"$event.stopPropagation()\"\n [attr.id]=\"_comboboxId\"\n [attr.aria-controls]=\"_listboxId\"\n [attr.aria-expanded]=\"isOpen\"\n [attr.aria-activedescendant]=\"isOpen && focusedItem ? getItemId(focusedItem) : null\"\n (input)=\"onInput($event)\"\n />\n <kirby-icon [name]=\"isOpen ? 'arrow-up' : 'arrow-down'\" kirby-affix=\"suffix\"></kirby-icon>\n</div>\n\n<kirby-popover\n [target]=\"rootElement\"\n [popout]=\"popout\"\n (click)=\"onPopoverClick()\"\n (mousedown)=\"$event.preventDefault()\"\n (willHide)=\"onPopoverWillHide()\"\n>\n <kirby-card [attr.id]=\"_listboxId\" [attr.aria-labelledby]=\"_comboboxId\">\n @if (searchItems.length === 0) {\n <kirby-item>\n <p class=\"kirby-item-title no-results\">{{ noSearchResultsText }}</p>\n </kirby-item>\n } @else {\n <cdk-virtual-scroll-viewport\n class=\"combobox-viewport\"\n role=\"listbox\"\n [itemSize]=\"itemHeight\"\n [style.height.px]=\"viewportHeight\"\n >\n <ng-container *cdkVirtualFor=\"let item of searchItems\">\n <ng-container\n *ngTemplateOutlet=\"\n itemTemplate || defaultItemTemplate;\n context: {\n $implicit: item,\n selected: item === selectedItem,\n focused: item === focusedItem,\n }\n \"\n ></ng-container>\n </ng-container>\n </cdk-virtual-scroll-viewport>\n }\n </kirby-card>\n</kirby-popover>\n\n<ng-template #defaultItemTemplate let-item let-selected=\"selected\" let-focused=\"focused\">\n <kirby-item\n role=\"option\"\n [selectable]=\"true\"\n [selected]=\"selected\"\n [class.focused]=\"focused\"\n [attr.id]=\"getItemId(item)\"\n [attr.aria-selected]=\"selected\"\n (click)=\"onItemSelect(item)\"\n >\n <p class=\"kirby-item-title\">{{ getItemText(item) }}</p>\n @if (selected) {\n <kirby-icon name=\"checkmark-selected\" slot=\"end\"></kirby-icon>\n }\n </kirby-item>\n</ng-template>\n", styles: [".kirby-line-clamp{display:-webkit-box;-webkit-line-clamp:var(--line-clamp, none);-webkit-box-orient:vertical;overflow:hidden}:host:focus-visible{transition:all 80ms linear 0ms;box-shadow:var(--kirby-focus-ring-md-inset);outline:none;border-radius:var(--kirby-border-radius-pill)}:host{display:inline-block;position:relative;max-width:calc(100vw - calc(2 * var(--kirby-spacing-s)))}:host.clicked{box-shadow:none}:host.expand{display:block}:host.expand kirby-card{width:100%;min-width:initial;max-width:initial}:host div{position:relative}:host div>input[kirby-input]{padding-right:var(--kirby-spacing-xl)}:host div>input[kirby-input]:disabled~kirby-icon{color:var(--kirby-semi-dark-shade)}:host div>kirby-icon{position:absolute;top:0;bottom:0;right:var(--kirby-spacing-xs)}:host.has-value>div>input[kirby-input]{text-overflow:ellipsis}kirby-popover{--max-height: 352px}kirby-card{display:flex;flex-direction:column;max-height:352px;overflow:hidden;box-shadow:var(--kirby-elevation-4);max-width:calc(100vw - calc(2 * var(--kirby-spacing-s)));min-width:calc(320px - calc(2 * var(--kirby-spacing-s)))}@media(min-width:321px){kirby-card{min-width:calc(375px - calc(2 * var(--kirby-spacing-s)))}}.combobox-viewport{display:block;width:100%}.no-results{color:var(--kirby-text-color-semi-dark)}\n"] }]
735
- }], ctorParameters: () => [{ type: i0.Renderer2 }, { type: i0.ElementRef }, { type: i0.ChangeDetectorRef }, { type: i1.ResizeObserverService }], propDecorators: { noSearchResultsText: [{
736
- type: Input
737
- }], selectionClearedAnnouncement: [{
738
- type: Input
739
- }], itemTextProperty: [{
740
- type: Input
741
- }], itemHeight: [{
742
- type: Input
743
- }], itemIdProperty: [{
744
- type: Input
745
- }], searchFunction: [{
746
- type: Input
747
- }], items: [{
748
- type: Input
749
- }], selectedItem: [{
750
- type: Input
751
- }], placeholder: [{
752
- type: Input
753
- }], popout: [{
754
- type: Input
755
- }], expand: [{
756
- type: Input
757
- }], disabled: [{
758
- type: Input
759
- }], _isDisabled: [{
760
- type: HostBinding,
761
- args: ['attr.disabled']
762
- }], hasErrorChange: [{
763
- type: Output
764
- }], hasError: [{
765
- type: Input
766
- }], size: [{
767
- type: Input
768
- }], _noBlurOnScroll: [{
769
- type: HostBinding,
770
- args: ['attr.no-blur']
771
- }], change: [{
772
- type: Output
773
- }], _isBlockLevel: [{
774
- type: HostBinding,
775
- args: ['class.expand']
776
- }], _isOpening: [{
777
- type: HostBinding,
778
- args: ['class.is-opening']
779
- }], isOpen: [{
780
- type: HostBinding,
781
- args: ['class.is-open']
782
- }], hasValue: [{
783
- type: HostBinding,
784
- args: ['class.has-value']
785
- }], itemTemplate: [{
786
- type: ContentChild,
787
- args: [ListItemTemplateDirective, { read: TemplateRef }]
788
- }], slottedItems: [{
789
- type: ContentChildren,
790
- args: [ListItemTemplateDirective, { read: ElementRef }]
791
- }], cardElement: [{
792
- type: ViewChild,
793
- args: [CardComponent, { read: ElementRef }]
794
- }], popover: [{
795
- type: ViewChild,
796
- args: [PopoverComponent]
797
- }], rootElement: [{
798
- type: ViewChild,
799
- args: ['rootElement', { static: true, read: ElementRef }]
800
- }], textInput: [{
801
- type: ViewChild,
802
- args: [InputComponent, { static: true, read: ElementRef }]
803
- }], _virtualScrollViewport: [{
804
- type: ViewChild,
805
- args: [CdkVirtualScrollViewport]
806
- }], kirbyItemsDefault: [{
807
- type: ViewChildren,
808
- args: [ItemComponent, { read: ElementRef }]
809
- }], kirbyItemsSlotted: [{
810
- type: ContentChildren,
811
- args: [ItemComponent, { read: ElementRef }]
812
- }], onMouseDown: [{
813
- type: HostListener,
814
- args: ['mousedown', ['$event']]
815
- }], onTouchStart: [{
816
- type: HostListener,
817
- args: ['touchstart', ['$event']]
818
- }], onFocusOut: [{
819
- type: HostListener,
820
- args: ['focusout']
821
- }], onTab: [{
822
- type: HostListener,
823
- args: ['keydown.tab']
824
- }], onEscape: [{
825
- type: HostListener,
826
- args: ['keydown.escape']
827
- }], onEnter: [{
828
- type: HostListener,
829
- args: ['keydown.enter', ['$event']]
830
- }], onArrowKeys: [{
831
- type: HostListener,
832
- args: ['keydown.arrowUp', ['$event']]
833
- }, {
834
- type: HostListener,
835
- args: ['keydown.arrowDown', ['$event']]
836
- }, {
837
- type: HostListener,
838
- args: ['keydown.pageUp', ['$event']]
839
- }, {
840
- type: HostListener,
841
- args: ['keydown.pageDown', ['$event']]
842
- }, {
843
- type: HostListener,
844
- args: ['keydown.home', ['$event']]
845
- }, {
846
- type: HostListener,
847
- args: ['keydown.end', ['$event']]
848
- }] } });
849
-
850
- /**
851
- * Generated bundle index. Do not edit.
852
- */
853
-
22
+ var ComboboxComponent = class ComboboxComponent {
23
+ static {
24
+ this.HEIGHT_OF_STANDARD_ITEM = 44;
25
+ }
26
+ compareAlphabetically(textA, textB) {
27
+ if (textA < textB) return -1;
28
+ if (textA > textB) return 1;
29
+ return 0;
30
+ }
31
+ getItemText(item) {
32
+ if (this.isTypeString(item)) return item;
33
+ if (this.objectHasItemTextProperty(item)) {
34
+ const textValue = item[this.itemTextProperty];
35
+ if (typeof textValue === "string") return textValue;
36
+ }
37
+ return "";
38
+ }
39
+ get dropdownMaxHeight() {
40
+ return 8 * ComboboxComponent.HEIGHT_OF_STANDARD_ITEM;
41
+ }
42
+ get dropdownMinHeight() {
43
+ return this.itemHeight;
44
+ }
45
+ get viewportHeight() {
46
+ const itemCount = this.searchItems?.length ?? 0;
47
+ if (itemCount === 0) return this.dropdownMinHeight;
48
+ return Math.min(this.dropdownMaxHeight, Math.max(this.dropdownMinHeight, itemCount * this.itemHeight));
49
+ }
50
+ isTypeString(item) {
51
+ return typeof item === "string";
52
+ }
53
+ objectHasItemTextProperty(item) {
54
+ return item != void 0 && typeof item === "object" && this.itemTextProperty in item;
55
+ }
56
+ objectHasItemIdProperty(item) {
57
+ return item != void 0 && typeof item === "object" && this.itemIdProperty in item;
58
+ }
59
+ getItemId(item) {
60
+ if (this.isTypeString(item)) return item;
61
+ if (this.objectHasItemIdProperty(item)) {
62
+ const idValue = item[this.itemIdProperty];
63
+ if (this.isTypeString(idValue)) return idValue;
64
+ }
65
+ console.error("Each item must have an id property for scroll to work. Ensure that the itemIdProperty input is set correctly, and that each item has a unique id value.");
66
+ return "";
67
+ }
68
+ get searchItems() {
69
+ return this._searchItems;
70
+ }
71
+ set searchItems(value) {
72
+ this._searchItems = value;
73
+ if (!this._searchItems) return;
74
+ if (this.textInput?.nativeElement?.value) {
75
+ this.focusedItem = this._searchItems[0];
76
+ this._virtualScrollViewport?.scrollToIndex(0);
77
+ }
78
+ }
79
+ get items() {
80
+ return this._items;
81
+ }
82
+ set items(value) {
83
+ this._items = value;
84
+ this.searchItems = this._items;
85
+ }
86
+ get selectedItem() {
87
+ return this._selectedItem;
88
+ }
89
+ set selectedItem(value) {
90
+ if (value !== this._selectedItem) {
91
+ this._selectedItem = value;
92
+ this.focusedItem = this._selectedItem;
93
+ this.value = this._selectedItem;
94
+ this.setInputDisplayValue(this.getItemText(this.selectedItem));
95
+ }
96
+ }
97
+ get focusedItem() {
98
+ return this._focusedItem;
99
+ }
100
+ set focusedItem(item) {
101
+ this.setAriaPosinsetOnElement(item);
102
+ if (this._focusedItem === item) return;
103
+ this._focusedItem = item;
104
+ }
105
+ getIndexOfItem(item) {
106
+ return this.searchItems.indexOf(item);
107
+ }
108
+ getKirbyElement(item) {
109
+ const kirbyItems = this.getKirbyItems();
110
+ if (!kirbyItems || !item) return;
111
+ const itemId = this.getItemId(item);
112
+ return kirbyItems.find((el) => el.nativeElement.id === itemId);
113
+ }
114
+ setAriaPosinsetOnElement(item) {
115
+ const element = this.getKirbyElement(item);
116
+ const index = this.getIndexOfItem(item);
117
+ const setsize = this.searchItems.length;
118
+ if (!element) return;
119
+ this.renderer.setAttribute(element.nativeElement, "aria-setsize", setsize.toString());
120
+ this.renderer.setAttribute(element.nativeElement, "aria-posinset", `${index + 1}`);
121
+ }
122
+ set popout(direction) {
123
+ this._popout = direction || HorizontalDirection.right;
124
+ }
125
+ get popout() {
126
+ return this._popout;
127
+ }
128
+ get _isDisabled() {
129
+ return this.disabled ? "disabled" : null;
130
+ }
131
+ get hasError() {
132
+ return this._hasError;
133
+ }
134
+ set hasError(value) {
135
+ if (this._hasError !== value) {
136
+ this._hasError = value;
137
+ this.hasErrorChange.emit(this._hasError);
138
+ }
139
+ }
140
+ get _noBlurOnScroll() {
141
+ return true;
142
+ }
143
+ get _isBlockLevel() {
144
+ return this.expand === "block";
145
+ }
146
+ get _isOpening() {
147
+ return this.state === OpenState.opening;
148
+ }
149
+ get isOpen() {
150
+ return this.state === OpenState.open;
151
+ }
152
+ get hasValue() {
153
+ return this.selectedItem != null;
154
+ }
155
+ get interactiveElement() {
156
+ return this.textInput.nativeElement;
157
+ }
158
+ forwardAriaLabelToCombobox() {
159
+ forwardAttributes(this.elementRef.nativeElement, this._attributesToForward, this.renderer, this.rootElement.nativeElement);
160
+ }
161
+ set kirbyItemsSlotted(kirbyItems) {
162
+ if (this.disposeItemClickListeners?.length > 0) this.unlistenAllSlottedItems();
163
+ kirbyItems.forEach((kirbyItem) => {
164
+ this.renderer.setAttribute(kirbyItem.nativeElement, "role", "option");
165
+ const disposeClickListener = this.renderer.listen(kirbyItem.nativeElement, "click", () => {
166
+ const id = kirbyItem.nativeElement.getAttribute("id");
167
+ const item = this.items.find((it) => this.getItemId(it) === id);
168
+ if (item) this.onItemSelect(item);
169
+ });
170
+ this.disposeItemClickListeners.push(disposeClickListener);
171
+ });
172
+ this._kirbyItemsSlotted = kirbyItems;
173
+ }
174
+ get kirbyItemsSlotted() {
175
+ return this._kirbyItemsSlotted;
176
+ }
177
+ constructor(renderer, elementRef, cdr, resizeObserverService) {
178
+ this.renderer = renderer;
179
+ this.elementRef = elementRef;
180
+ this.cdr = cdr;
181
+ this.resizeObserverService = resizeObserverService;
182
+ this.state = OpenState.closed;
183
+ this._popout = HorizontalDirection.right;
184
+ this._attributesToForward = ["aria-label", "aria-labelledby"];
185
+ this._listboxId = UniqueIdGenerator.scopedTo("kirby-x-combobox").next();
186
+ this._comboboxId = UniqueIdGenerator.scopedTo("kirby-input").next();
187
+ this._defaultSearchFunction = (searchTerm, itemsToSearch) => {
188
+ if (!searchTerm) return itemsToSearch;
189
+ const lowerSearchTerm = searchTerm.toLowerCase();
190
+ return itemsToSearch.filter((item) => this.getItemText(item).toLowerCase().includes(lowerSearchTerm)).sort((a, b) => {
191
+ const textA = this.getItemText(a).toLowerCase();
192
+ const textB = this.getItemText(b).toLowerCase();
193
+ const textAStartsWith = textA.startsWith(searchTerm);
194
+ const textBStartsWith = textB.startsWith(searchTerm);
195
+ if (textAStartsWith && textBStartsWith) return this.compareAlphabetically(textA, textB);
196
+ if (textAStartsWith) return -1;
197
+ if (textBStartsWith) return 1;
198
+ return this.compareAlphabetically(textA, textB);
199
+ });
200
+ };
201
+ this.noSearchResultsText = "No results found.";
202
+ this.selectionClearedAnnouncement = "Selection cleared.";
203
+ this._liveRegionText = "";
204
+ this.itemTextProperty = "text";
205
+ this.itemHeight = 44;
206
+ this.itemIdProperty = "id";
207
+ this.searchFunction = this._defaultSearchFunction;
208
+ this._searchItems = [];
209
+ this._items = [];
210
+ this._selectedItem = void 0;
211
+ this._focusedItem = void 0;
212
+ this.placeholder = "Please search...";
213
+ this.disabled = false;
214
+ this.hasErrorChange = new EventEmitter();
215
+ this._hasError = false;
216
+ this.size = InputSize.medium;
217
+ this.change = new EventEmitter();
218
+ this.value = void 0;
219
+ this.disposeItemClickListeners = [];
220
+ this.onChange = () => {};
221
+ this.onTouched = () => {};
222
+ }
223
+ onToggle(event) {
224
+ event.stopPropagation();
225
+ this.textInput?.nativeElement.focus();
226
+ this.toggle();
227
+ }
228
+ toggle() {
229
+ if (this.disabled) return;
230
+ this.isOpen ? this.close() : this.open();
231
+ }
232
+ ngAfterViewInit() {
233
+ if (this.expand === "block") {
234
+ const { width: initialWidth } = this.elementRef.nativeElement.getBoundingClientRect();
235
+ this.setPopoverCardStyle("max-width", "initial");
236
+ this.setPopoverCardStyle("min-width", "initial");
237
+ this.setPopoverCardStyle("--kirby-card-width", `${initialWidth}px`);
238
+ this.resizeObserverService.observe(this.elementRef, (entry) => {
239
+ const newWidth = entry.contentRect.width;
240
+ if (newWidth > 0) this.setPopoverCardStyle("--kirby-card-width", `${newWidth}px`);
241
+ });
242
+ }
243
+ this.forwardAriaLabelToCombobox();
244
+ }
245
+ setPopoverCardStyle(style, value) {
246
+ this.renderer.setStyle(this.cardElement?.nativeElement, style, value, RendererStyleFlags2.DashCase);
247
+ }
248
+ ngOnDestroy() {
249
+ this.unlistenAllSlottedItems();
250
+ this.unobserveResize();
251
+ }
252
+ open() {
253
+ if (this.disabled) return;
254
+ if (!this.isOpen) {
255
+ this.state = OpenState.opening;
256
+ this.showPopOver();
257
+ this.focusedItem = this.selectedItem;
258
+ }
259
+ }
260
+ showPopOver() {
261
+ if (this.state === OpenState.opening) {
262
+ this.state = OpenState.open;
263
+ this.popover?.show();
264
+ this.cdr.markForCheck();
265
+ requestAnimationFrame(() => this.scrollToIndexIntoViewWhenOpeningPopup());
266
+ }
267
+ }
268
+ close() {
269
+ if (this.disabled) return;
270
+ if (this.isOpen) {
271
+ this.state = OpenState.closed;
272
+ this.setInputDisplayValue(this.getItemText(this.selectedItem));
273
+ this.searchItems = this.items;
274
+ this.popover?.hide();
275
+ }
276
+ }
277
+ onItemSelect(item) {
278
+ if (item instanceof HTMLElement) return;
279
+ this.selectItem(item);
280
+ this.close();
281
+ }
282
+ writeValue(value) {
283
+ this.selectItemByInput(value);
284
+ this.setInputDisplayValue(this.getItemText(this.value));
285
+ this.cdr.markForCheck();
286
+ }
287
+ registerOnChange(fn) {
288
+ this.onChange = fn;
289
+ }
290
+ registerOnTouched(fn) {
291
+ this.onTouched = fn;
292
+ }
293
+ setDisabledState(isDisabled) {
294
+ this.disabled = isDisabled;
295
+ this.cdr.markForCheck();
296
+ }
297
+ selectItem(item) {
298
+ if (item != this.selectedItem) {
299
+ this.selectedItem = item;
300
+ this.focusedItem = item;
301
+ this.change.emit(this.value);
302
+ this.onChange(this.value);
303
+ this.setInputDisplayValue(this.getItemText(item));
304
+ this.searchItems = this.items;
305
+ }
306
+ }
307
+ selectItemByInput(input) {
308
+ this.selectedItem = this.findItemByInput(input);
309
+ }
310
+ onInput(event) {
311
+ if (!this.isOpen) this.open();
312
+ const input = event.target;
313
+ if (!input.value) this.clearSelection();
314
+ this.updateSearchResults(input.value);
315
+ if (document.activeElement !== this.textInput?.nativeElement) this.textInput?.nativeElement.focus();
316
+ }
317
+ clearSelection() {
318
+ this.selectItem(void 0);
319
+ this.announce(this.selectionClearedAnnouncement);
320
+ }
321
+ announce(message) {
322
+ clearTimeout(this._announceTimeout);
323
+ this._liveRegionText = "";
324
+ this._announceTimeout = setTimeout(() => {
325
+ this._liveRegionText = message;
326
+ this.cdr.markForCheck();
327
+ }, 100);
328
+ }
329
+ updateSearchResults(inputValue) {
330
+ this.searchItems = inputValue ? this.searchFunction(inputValue, this.items) : this.items;
331
+ if (inputValue && this.searchItems.length === 0) this.announce(this.noSearchResultsText);
332
+ }
333
+ onPopoverWillHide() {
334
+ this.state = OpenState.closed;
335
+ this.rootElement.nativeElement.focus();
336
+ this.onTouched();
337
+ }
338
+ onPopoverClick() {
339
+ this.close();
340
+ }
341
+ onMouseDown(event) {
342
+ if (this.disabled) {
343
+ event.preventDefault();
344
+ event.stopImmediatePropagation();
345
+ }
346
+ }
347
+ onTouchStart(event) {
348
+ if (this.isOpen) event.stopPropagation();
349
+ }
350
+ onFocusOut() {
351
+ setTimeout(() => {
352
+ const activeElement = document.activeElement;
353
+ const isOnTriggerButton = activeElement && this.elementRef.nativeElement.contains(activeElement);
354
+ const isInsidePopover = activeElement && activeElement.closest("kirby-popover");
355
+ if (isOnTriggerButton || isInsidePopover) return;
356
+ if (this.isOpen && activeElement === document.body) {
357
+ this.textInput?.nativeElement.focus();
358
+ return;
359
+ }
360
+ if (this.isOpen) this.close();
361
+ this.onTouched();
362
+ }, 0);
363
+ }
364
+ onTab() {
365
+ if (this.isOpen) {
366
+ this.selectItem(this.focusedItem);
367
+ this.close();
368
+ }
369
+ }
370
+ onEscape() {
371
+ this.close();
372
+ }
373
+ onEnter(event) {
374
+ event.preventDefault();
375
+ event.stopPropagation();
376
+ if (this.isOpen) this.selectItem(this.focusedItem);
377
+ this.toggle();
378
+ }
379
+ onArrowKeys(event) {
380
+ if (this.disabled) return;
381
+ const keyEvent = event;
382
+ event.preventDefault();
383
+ if (!this.isOpen) {
384
+ this.open();
385
+ if (this.selectedItem) this.setFocusOnSelectedItem();
386
+ else this.setFocusOnFirstOrLastItem(keyEvent);
387
+ } else this.handleFocusNavigation(keyEvent);
388
+ }
389
+ handleFocusNavigation(keyEvent) {
390
+ switch (keyEvent.key) {
391
+ case "ArrowDown":
392
+ this.shiftFocusIndex(1);
393
+ break;
394
+ case "ArrowUp":
395
+ this.shiftFocusIndex(-1);
396
+ break;
397
+ case "PageDown":
398
+ this.shiftFocusIndex(10);
399
+ break;
400
+ case "PageUp":
401
+ this.shiftFocusIndex(-10);
402
+ break;
403
+ case "Home":
404
+ this.setFocusOnFirstItem();
405
+ break;
406
+ case "End": this.setFocusOnLastItem();
407
+ }
408
+ }
409
+ shiftFocusIndex(numberOfItems) {
410
+ const currentIndex = this.searchItems.indexOf(this.focusedItem);
411
+ let newIndex;
412
+ if (numberOfItems > 0) newIndex = Math.min(this.searchItems.length - 1, currentIndex + numberOfItems);
413
+ else newIndex = Math.max(0, currentIndex + numberOfItems);
414
+ if (newIndex !== currentIndex) this.focusedItem = this.searchItems[newIndex];
415
+ this.scrollFocusedItemIntoViewWhileNavigating();
416
+ }
417
+ setFocusOnFirstOrLastItem(keyEvent) {
418
+ switch (keyEvent.key) {
419
+ case "ArrowDown":
420
+ case "PageDown":
421
+ case "Home":
422
+ this.setFocusOnFirstItem();
423
+ break;
424
+ case "ArrowUp":
425
+ case "PageUp":
426
+ case "End": this.setFocusOnLastItem();
427
+ }
428
+ }
429
+ setFocusOnSelectedItem() {
430
+ if (this.selectedItem) this.focusedItem = this.selectedItem;
431
+ }
432
+ setFocusOnLastItem() {
433
+ if (this.searchItems.length > 0) this.focusedItem = this.searchItems[this.searchItems.length - 1];
434
+ }
435
+ setFocusOnFirstItem() {
436
+ if (this.searchItems.length > 0) this.focusedItem = this.searchItems[0];
437
+ }
438
+ unlistenAllSlottedItems() {
439
+ let disposeClickListener;
440
+ while ((disposeClickListener = this.disposeItemClickListeners.pop()) !== void 0) disposeClickListener();
441
+ }
442
+ unobserveResize() {
443
+ this.resizeObserverService.unobserve(this.elementRef);
444
+ }
445
+ findItemByInput(input) {
446
+ if (!this.items || this.items.length === 0) return input;
447
+ return this.items.find((it) => this.getItemText(it) === input) ?? input;
448
+ }
449
+ setInputDisplayValue(value) {
450
+ if (this.interactiveElement) this.renderer.setProperty(this.interactiveElement, "value", value);
451
+ }
452
+ scrollFocusedItemIntoViewWhileNavigating() {
453
+ if (!this.focusedItem || !this._virtualScrollViewport) return;
454
+ const focusedIndex = this.searchItems.indexOf(this.focusedItem);
455
+ if (focusedIndex === -1) return;
456
+ const itemTop = focusedIndex * this.itemHeight;
457
+ const itemBottom = itemTop + this.itemHeight;
458
+ const scrollOffset = this._virtualScrollViewport.measureScrollOffset();
459
+ const viewportSize = this._virtualScrollViewport.getViewportSize();
460
+ if (itemTop < scrollOffset) this._virtualScrollViewport.scrollToOffset(itemTop);
461
+ else if (itemBottom > scrollOffset + viewportSize) this._virtualScrollViewport.scrollToOffset(itemBottom - viewportSize);
462
+ this._virtualScrollViewport.checkViewportSize();
463
+ }
464
+ getKirbyItems() {
465
+ return this.kirbyItemsSlotted && this.kirbyItemsSlotted.length ? this.kirbyItemsSlotted : this.kirbyItemsDefault;
466
+ }
467
+ scrollToIndexIntoViewWhenOpeningPopup() {
468
+ const focusedIndex = this.searchItems.indexOf(this.focusedItem);
469
+ this._virtualScrollViewport?.setRenderedRange({
470
+ start: 0,
471
+ end: 20
472
+ });
473
+ this._virtualScrollViewport?.checkViewportSize();
474
+ this._virtualScrollViewport?.scrollToIndex(focusedIndex);
475
+ }
476
+ static {
477
+ this.ɵfac = i0.ɵɵngDeclareFactory({
478
+ minVersion: "12.0.0",
479
+ version: "22.2.2",
480
+ ngImport: i0,
481
+ type: ComboboxComponent,
482
+ deps: [
483
+ { token: i0.Renderer2 },
484
+ { token: i0.ElementRef },
485
+ { token: i0.ChangeDetectorRef },
486
+ { token: i1.ResizeObserverService }
487
+ ],
488
+ target: i0.ɵɵFactoryTarget.Component
489
+ });
490
+ }
491
+ static {
492
+ this.ɵcmp = i0.ɵɵngDeclareComponent({
493
+ minVersion: "17.0.0",
494
+ version: "22.2.2",
495
+ type: ComboboxComponent,
496
+ isStandalone: true,
497
+ selector: "kirby-x-combobox",
498
+ inputs: {
499
+ noSearchResultsText: "noSearchResultsText",
500
+ selectionClearedAnnouncement: "selectionClearedAnnouncement",
501
+ itemTextProperty: "itemTextProperty",
502
+ itemHeight: "itemHeight",
503
+ itemIdProperty: "itemIdProperty",
504
+ searchFunction: "searchFunction",
505
+ items: "items",
506
+ selectedItem: "selectedItem",
507
+ placeholder: "placeholder",
508
+ popout: "popout",
509
+ expand: "expand",
510
+ disabled: "disabled",
511
+ hasError: "hasError",
512
+ size: "size"
513
+ },
514
+ outputs: {
515
+ hasErrorChange: "hasErrorChange",
516
+ change: "change"
517
+ },
518
+ host: {
519
+ listeners: {
520
+ "mousedown": "onMouseDown($event)",
521
+ "touchstart": "onTouchStart($event)",
522
+ "focusout": "onFocusOut()",
523
+ "keydown.tab": "onTab()",
524
+ "keydown.escape": "onEscape()",
525
+ "keydown.enter": "onEnter($event)",
526
+ "keydown.arrowUp": "onArrowKeys($event)",
527
+ "keydown.arrowDown": "onArrowKeys($event)",
528
+ "keydown.pageUp": "onArrowKeys($event)",
529
+ "keydown.pageDown": "onArrowKeys($event)",
530
+ "keydown.home": "onArrowKeys($event)",
531
+ "keydown.end": "onArrowKeys($event)"
532
+ },
533
+ properties: {
534
+ "attr.disabled": "this._isDisabled",
535
+ "attr.no-blur": "this._noBlurOnScroll",
536
+ "class.expand": "this._isBlockLevel",
537
+ "class.is-opening": "this._isOpening",
538
+ "class.is-open": "this.isOpen",
539
+ "class.has-value": "this.hasValue"
540
+ }
541
+ },
542
+ providers: [{
543
+ provide: NG_VALUE_ACCESSOR,
544
+ useExisting: forwardRef(() => ComboboxComponent),
545
+ multi: true
546
+ }, {
547
+ provide: FORM_FIELD_CONTROL,
548
+ useExisting: forwardRef(() => ComboboxComponent)
549
+ }],
550
+ queries: [
551
+ {
552
+ propertyName: "itemTemplate",
553
+ first: true,
554
+ predicate: ListItemTemplateDirective,
555
+ descendants: true,
556
+ read: TemplateRef
557
+ },
558
+ {
559
+ propertyName: "slottedItems",
560
+ predicate: ListItemTemplateDirective,
561
+ read: ElementRef
562
+ },
563
+ {
564
+ propertyName: "kirbyItemsSlotted",
565
+ predicate: ItemComponent,
566
+ read: ElementRef
567
+ }
568
+ ],
569
+ viewQueries: [
570
+ {
571
+ propertyName: "cardElement",
572
+ first: true,
573
+ predicate: CardComponent,
574
+ descendants: true,
575
+ read: ElementRef
576
+ },
577
+ {
578
+ propertyName: "popover",
579
+ first: true,
580
+ predicate: PopoverComponent,
581
+ descendants: true
582
+ },
583
+ {
584
+ propertyName: "rootElement",
585
+ first: true,
586
+ predicate: ["rootElement"],
587
+ descendants: true,
588
+ read: ElementRef,
589
+ static: true
590
+ },
591
+ {
592
+ propertyName: "textInput",
593
+ first: true,
594
+ predicate: InputComponent,
595
+ descendants: true,
596
+ read: ElementRef,
597
+ static: true
598
+ },
599
+ {
600
+ propertyName: "_virtualScrollViewport",
601
+ first: true,
602
+ predicate: CdkVirtualScrollViewport,
603
+ descendants: true
604
+ },
605
+ {
606
+ propertyName: "kirbyItemsDefault",
607
+ predicate: ItemComponent,
608
+ descendants: true,
609
+ read: ElementRef
610
+ }
611
+ ],
612
+ ngImport: i0,
613
+ template: "<span class=\"kirby-visually-hidden\" aria-live=\"polite\" aria-atomic=\"true\">\n {{ _liveRegionText }}\n</span>\n<div (click)=\"onToggle($event)\" #rootElement>\n <input\n kirby-input\n type=\"text\"\n aria-haspopup=\"listbox\"\n role=\"combobox\"\n [hasError]=\"hasError\"\n [size]=\"size\"\n [disabled]=\"disabled\"\n [placeholder]=\"placeholder\"\n (change)=\"$event.stopPropagation()\"\n [attr.id]=\"_comboboxId\"\n [attr.aria-controls]=\"_listboxId\"\n [attr.aria-expanded]=\"isOpen\"\n [attr.aria-activedescendant]=\"isOpen && focusedItem ? getItemId(focusedItem) : null\"\n (input)=\"onInput($event)\"\n />\n <kirby-icon [name]=\"isOpen ? 'arrow-up' : 'arrow-down'\" kirby-affix=\"suffix\"></kirby-icon>\n</div>\n\n<kirby-popover\n [target]=\"rootElement\"\n [popout]=\"popout\"\n (click)=\"onPopoverClick()\"\n (mousedown)=\"$event.preventDefault()\"\n (willHide)=\"onPopoverWillHide()\"\n>\n <kirby-card [attr.id]=\"_listboxId\" [attr.aria-labelledby]=\"_comboboxId\">\n @if (searchItems.length === 0) {\n <kirby-item>\n <p class=\"kirby-item-title no-results\">{{ noSearchResultsText }}</p>\n </kirby-item>\n } @else {\n <cdk-virtual-scroll-viewport\n class=\"combobox-viewport\"\n role=\"listbox\"\n [itemSize]=\"itemHeight\"\n [style.height.px]=\"viewportHeight\"\n >\n <ng-container *cdkVirtualFor=\"let item of searchItems\">\n <ng-container\n *ngTemplateOutlet=\"\n itemTemplate || defaultItemTemplate;\n context: {\n $implicit: item,\n selected: item === selectedItem,\n focused: item === focusedItem,\n }\n \"\n ></ng-container>\n </ng-container>\n </cdk-virtual-scroll-viewport>\n }\n </kirby-card>\n</kirby-popover>\n\n<ng-template #defaultItemTemplate let-item let-selected=\"selected\" let-focused=\"focused\">\n <kirby-item\n role=\"option\"\n [selectable]=\"true\"\n [selected]=\"selected\"\n [class.focused]=\"focused\"\n [attr.id]=\"getItemId(item)\"\n [attr.aria-selected]=\"selected\"\n (click)=\"onItemSelect(item)\"\n >\n <p class=\"kirby-item-title\">{{ getItemText(item) }}</p>\n @if (selected) {\n <kirby-icon name=\"checkmark-selected\" slot=\"end\"></kirby-icon>\n }\n </kirby-item>\n</ng-template>\n",
614
+ styles: [".kirby-line-clamp{display:-webkit-box;-webkit-line-clamp:var(--line-clamp, none);-webkit-box-orient:vertical;overflow:hidden}:host:focus-visible{transition:all 80ms linear 0ms;box-shadow:var(--kirby-focus-ring-md-inset);outline:none;border-radius:var(--kirby-border-radius-pill)}:host{display:inline-block;position:relative;max-width:calc(100vw - calc(2 * var(--kirby-spacing-s)))}:host.clicked{box-shadow:none}:host.expand{display:block}:host.expand kirby-card{width:100%;min-width:initial;max-width:initial}:host div{position:relative}:host div>input[kirby-input]{padding-right:var(--kirby-spacing-xl)}:host div>input[kirby-input]:disabled~kirby-icon{color:var(--kirby-semi-dark-shade)}:host div>kirby-icon{position:absolute;top:0;bottom:0;right:var(--kirby-spacing-xs)}:host.has-value>div>input[kirby-input]{text-overflow:ellipsis}kirby-popover{--max-height: 352px}kirby-card{display:flex;flex-direction:column;max-height:352px;overflow:hidden;box-shadow:var(--kirby-elevation-4);max-width:calc(100vw - calc(2 * var(--kirby-spacing-s)));min-width:calc(320px - calc(2 * var(--kirby-spacing-s)))}@media(min-width:321px){kirby-card{min-width:calc(375px - calc(2 * var(--kirby-spacing-s)))}}.combobox-viewport{display:block;width:100%}.no-results{color:var(--kirby-text-color-semi-dark)}\n"],
615
+ dependencies: [
616
+ {
617
+ kind: "component",
618
+ type: InputComponent,
619
+ selector: "input[kirby-input]",
620
+ inputs: [
621
+ "type",
622
+ "size",
623
+ "borderless",
624
+ "hasError",
625
+ "autocomplete",
626
+ "autocorrect",
627
+ "value",
628
+ "maxlength",
629
+ "inputmode"
630
+ ],
631
+ outputs: ["hasErrorChange"]
632
+ },
633
+ {
634
+ kind: "directive",
635
+ type: NgTemplateOutlet,
636
+ selector: "[ngTemplateOutlet]",
637
+ inputs: [
638
+ "ngTemplateOutletContext",
639
+ "ngTemplateOutlet",
640
+ "ngTemplateOutletInjector"
641
+ ]
642
+ },
643
+ {
644
+ kind: "component",
645
+ type: PopoverComponent,
646
+ selector: "kirby-popover",
647
+ inputs: ["popout", "target"],
648
+ outputs: ["willHide"]
649
+ },
650
+ {
651
+ kind: "component",
652
+ type: CardComponent,
653
+ selector: "kirby-card",
654
+ inputs: [
655
+ "title",
656
+ "subtitle",
657
+ "backgroundImageUrl",
658
+ "hasPadding",
659
+ "sizes",
660
+ "variant"
661
+ ]
662
+ },
663
+ {
664
+ kind: "component",
665
+ type: ItemComponent,
666
+ selector: "kirby-item",
667
+ inputs: [
668
+ "disabled",
669
+ "selected",
670
+ "disclosure",
671
+ "selectable",
672
+ "reorderable",
673
+ "size",
674
+ "href",
675
+ "rotateIcon"
676
+ ]
677
+ },
678
+ {
679
+ kind: "component",
680
+ type: IconComponent,
681
+ selector: "kirby-icon",
682
+ inputs: ["size", "name"]
683
+ },
684
+ {
685
+ kind: "directive",
686
+ type: AffixDirective,
687
+ selector: "[kirby-affix]",
688
+ inputs: ["kirby-affix"]
689
+ },
690
+ {
691
+ kind: "directive",
692
+ type: CdkFixedSizeVirtualScroll,
693
+ selector: "cdk-virtual-scroll-viewport[itemSize]",
694
+ inputs: [
695
+ "itemSize",
696
+ "minBufferPx",
697
+ "maxBufferPx"
698
+ ]
699
+ },
700
+ {
701
+ kind: "component",
702
+ type: CdkVirtualScrollViewport,
703
+ selector: "cdk-virtual-scroll-viewport",
704
+ inputs: ["orientation", "appendOnly"],
705
+ outputs: ["scrolledIndexChange"]
706
+ },
707
+ {
708
+ kind: "directive",
709
+ type: CdkVirtualForOf,
710
+ selector: "[cdkVirtualFor][cdkVirtualForOf]",
711
+ inputs: [
712
+ "cdkVirtualForOf",
713
+ "cdkVirtualForTrackBy",
714
+ "cdkVirtualForTemplate",
715
+ "cdkVirtualForTemplateCacheSize"
716
+ ]
717
+ }
718
+ ],
719
+ changeDetection: i0.ChangeDetectionStrategy.OnPush
720
+ });
721
+ }
722
+ };
723
+ i0.ɵɵngDeclareClassMetadata({
724
+ minVersion: "12.0.0",
725
+ version: "22.2.2",
726
+ ngImport: i0,
727
+ type: ComboboxComponent,
728
+ decorators: [{
729
+ type: Component,
730
+ args: [{
731
+ selector: "kirby-x-combobox",
732
+ providers: [{
733
+ provide: NG_VALUE_ACCESSOR,
734
+ useExisting: forwardRef(() => ComboboxComponent),
735
+ multi: true
736
+ }, {
737
+ provide: FORM_FIELD_CONTROL,
738
+ useExisting: forwardRef(() => ComboboxComponent)
739
+ }],
740
+ imports: [
741
+ InputComponent,
742
+ NgTemplateOutlet,
743
+ PopoverComponent,
744
+ CardComponent,
745
+ ItemComponent,
746
+ IconComponent,
747
+ AffixDirective,
748
+ CdkFixedSizeVirtualScroll,
749
+ CdkVirtualScrollViewport,
750
+ CdkVirtualForOf
751
+ ],
752
+ changeDetection: ChangeDetectionStrategy.OnPush,
753
+ template: "<span class=\"kirby-visually-hidden\" aria-live=\"polite\" aria-atomic=\"true\">\n {{ _liveRegionText }}\n</span>\n<div (click)=\"onToggle($event)\" #rootElement>\n <input\n kirby-input\n type=\"text\"\n aria-haspopup=\"listbox\"\n role=\"combobox\"\n [hasError]=\"hasError\"\n [size]=\"size\"\n [disabled]=\"disabled\"\n [placeholder]=\"placeholder\"\n (change)=\"$event.stopPropagation()\"\n [attr.id]=\"_comboboxId\"\n [attr.aria-controls]=\"_listboxId\"\n [attr.aria-expanded]=\"isOpen\"\n [attr.aria-activedescendant]=\"isOpen && focusedItem ? getItemId(focusedItem) : null\"\n (input)=\"onInput($event)\"\n />\n <kirby-icon [name]=\"isOpen ? 'arrow-up' : 'arrow-down'\" kirby-affix=\"suffix\"></kirby-icon>\n</div>\n\n<kirby-popover\n [target]=\"rootElement\"\n [popout]=\"popout\"\n (click)=\"onPopoverClick()\"\n (mousedown)=\"$event.preventDefault()\"\n (willHide)=\"onPopoverWillHide()\"\n>\n <kirby-card [attr.id]=\"_listboxId\" [attr.aria-labelledby]=\"_comboboxId\">\n @if (searchItems.length === 0) {\n <kirby-item>\n <p class=\"kirby-item-title no-results\">{{ noSearchResultsText }}</p>\n </kirby-item>\n } @else {\n <cdk-virtual-scroll-viewport\n class=\"combobox-viewport\"\n role=\"listbox\"\n [itemSize]=\"itemHeight\"\n [style.height.px]=\"viewportHeight\"\n >\n <ng-container *cdkVirtualFor=\"let item of searchItems\">\n <ng-container\n *ngTemplateOutlet=\"\n itemTemplate || defaultItemTemplate;\n context: {\n $implicit: item,\n selected: item === selectedItem,\n focused: item === focusedItem,\n }\n \"\n ></ng-container>\n </ng-container>\n </cdk-virtual-scroll-viewport>\n }\n </kirby-card>\n</kirby-popover>\n\n<ng-template #defaultItemTemplate let-item let-selected=\"selected\" let-focused=\"focused\">\n <kirby-item\n role=\"option\"\n [selectable]=\"true\"\n [selected]=\"selected\"\n [class.focused]=\"focused\"\n [attr.id]=\"getItemId(item)\"\n [attr.aria-selected]=\"selected\"\n (click)=\"onItemSelect(item)\"\n >\n <p class=\"kirby-item-title\">{{ getItemText(item) }}</p>\n @if (selected) {\n <kirby-icon name=\"checkmark-selected\" slot=\"end\"></kirby-icon>\n }\n </kirby-item>\n</ng-template>\n",
754
+ styles: [".kirby-line-clamp{display:-webkit-box;-webkit-line-clamp:var(--line-clamp, none);-webkit-box-orient:vertical;overflow:hidden}:host:focus-visible{transition:all 80ms linear 0ms;box-shadow:var(--kirby-focus-ring-md-inset);outline:none;border-radius:var(--kirby-border-radius-pill)}:host{display:inline-block;position:relative;max-width:calc(100vw - calc(2 * var(--kirby-spacing-s)))}:host.clicked{box-shadow:none}:host.expand{display:block}:host.expand kirby-card{width:100%;min-width:initial;max-width:initial}:host div{position:relative}:host div>input[kirby-input]{padding-right:var(--kirby-spacing-xl)}:host div>input[kirby-input]:disabled~kirby-icon{color:var(--kirby-semi-dark-shade)}:host div>kirby-icon{position:absolute;top:0;bottom:0;right:var(--kirby-spacing-xs)}:host.has-value>div>input[kirby-input]{text-overflow:ellipsis}kirby-popover{--max-height: 352px}kirby-card{display:flex;flex-direction:column;max-height:352px;overflow:hidden;box-shadow:var(--kirby-elevation-4);max-width:calc(100vw - calc(2 * var(--kirby-spacing-s)));min-width:calc(320px - calc(2 * var(--kirby-spacing-s)))}@media(min-width:321px){kirby-card{min-width:calc(375px - calc(2 * var(--kirby-spacing-s)))}}.combobox-viewport{display:block;width:100%}.no-results{color:var(--kirby-text-color-semi-dark)}\n"]
755
+ }]
756
+ }],
757
+ ctorParameters: () => [
758
+ { type: i0.Renderer2 },
759
+ { type: i0.ElementRef },
760
+ { type: i0.ChangeDetectorRef },
761
+ { type: i1.ResizeObserverService }
762
+ ],
763
+ propDecorators: {
764
+ noSearchResultsText: [{ type: Input }],
765
+ selectionClearedAnnouncement: [{ type: Input }],
766
+ itemTextProperty: [{ type: Input }],
767
+ itemHeight: [{ type: Input }],
768
+ itemIdProperty: [{ type: Input }],
769
+ searchFunction: [{ type: Input }],
770
+ items: [{ type: Input }],
771
+ selectedItem: [{ type: Input }],
772
+ placeholder: [{ type: Input }],
773
+ popout: [{ type: Input }],
774
+ expand: [{ type: Input }],
775
+ disabled: [{ type: Input }],
776
+ _isDisabled: [{
777
+ type: HostBinding,
778
+ args: ["attr.disabled"]
779
+ }],
780
+ hasErrorChange: [{ type: Output }],
781
+ hasError: [{ type: Input }],
782
+ size: [{ type: Input }],
783
+ _noBlurOnScroll: [{
784
+ type: HostBinding,
785
+ args: ["attr.no-blur"]
786
+ }],
787
+ change: [{ type: Output }],
788
+ _isBlockLevel: [{
789
+ type: HostBinding,
790
+ args: ["class.expand"]
791
+ }],
792
+ _isOpening: [{
793
+ type: HostBinding,
794
+ args: ["class.is-opening"]
795
+ }],
796
+ isOpen: [{
797
+ type: HostBinding,
798
+ args: ["class.is-open"]
799
+ }],
800
+ hasValue: [{
801
+ type: HostBinding,
802
+ args: ["class.has-value"]
803
+ }],
804
+ itemTemplate: [{
805
+ type: ContentChild,
806
+ args: [ListItemTemplateDirective, { read: TemplateRef }]
807
+ }],
808
+ slottedItems: [{
809
+ type: ContentChildren,
810
+ args: [ListItemTemplateDirective, { read: ElementRef }]
811
+ }],
812
+ cardElement: [{
813
+ type: ViewChild,
814
+ args: [CardComponent, { read: ElementRef }]
815
+ }],
816
+ popover: [{
817
+ type: ViewChild,
818
+ args: [PopoverComponent]
819
+ }],
820
+ rootElement: [{
821
+ type: ViewChild,
822
+ args: ["rootElement", {
823
+ static: true,
824
+ read: ElementRef
825
+ }]
826
+ }],
827
+ textInput: [{
828
+ type: ViewChild,
829
+ args: [InputComponent, {
830
+ static: true,
831
+ read: ElementRef
832
+ }]
833
+ }],
834
+ _virtualScrollViewport: [{
835
+ type: ViewChild,
836
+ args: [CdkVirtualScrollViewport]
837
+ }],
838
+ kirbyItemsDefault: [{
839
+ type: ViewChildren,
840
+ args: [ItemComponent, { read: ElementRef }]
841
+ }],
842
+ kirbyItemsSlotted: [{
843
+ type: ContentChildren,
844
+ args: [ItemComponent, { read: ElementRef }]
845
+ }],
846
+ onMouseDown: [{
847
+ type: HostListener,
848
+ args: ["mousedown", ["$event"]]
849
+ }],
850
+ onTouchStart: [{
851
+ type: HostListener,
852
+ args: ["touchstart", ["$event"]]
853
+ }],
854
+ onFocusOut: [{
855
+ type: HostListener,
856
+ args: ["focusout"]
857
+ }],
858
+ onTab: [{
859
+ type: HostListener,
860
+ args: ["keydown.tab"]
861
+ }],
862
+ onEscape: [{
863
+ type: HostListener,
864
+ args: ["keydown.escape"]
865
+ }],
866
+ onEnter: [{
867
+ type: HostListener,
868
+ args: ["keydown.enter", ["$event"]]
869
+ }],
870
+ onArrowKeys: [
871
+ {
872
+ type: HostListener,
873
+ args: ["keydown.arrowUp", ["$event"]]
874
+ },
875
+ {
876
+ type: HostListener,
877
+ args: ["keydown.arrowDown", ["$event"]]
878
+ },
879
+ {
880
+ type: HostListener,
881
+ args: ["keydown.pageUp", ["$event"]]
882
+ },
883
+ {
884
+ type: HostListener,
885
+ args: ["keydown.pageDown", ["$event"]]
886
+ },
887
+ {
888
+ type: HostListener,
889
+ args: ["keydown.home", ["$event"]]
890
+ },
891
+ {
892
+ type: HostListener,
893
+ args: ["keydown.end", ["$event"]]
894
+ }
895
+ ]
896
+ }
897
+ });
854
898
  export { ComboboxComponent };
855
- //# sourceMappingURL=kirbydesign-extensions-angular-combobox.mjs.map
899
+
900
+ //# sourceMappingURL=kirbydesign-extensions-angular-combobox.mjs.map