@vaadin/combo-box 25.0.0-alpha2 → 25.0.0-alpha20

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 (34) hide show
  1. package/package.json +14 -17
  2. package/src/styles/vaadin-combo-box-base-styles.js +2 -2
  3. package/src/styles/vaadin-combo-box-overlay-base-styles.js +31 -48
  4. package/src/vaadin-combo-box-base-mixin.d.ts +54 -0
  5. package/src/vaadin-combo-box-base-mixin.js +772 -0
  6. package/src/vaadin-combo-box-data-provider-mixin.js +17 -32
  7. package/src/vaadin-combo-box-item-mixin.js +6 -1
  8. package/src/vaadin-combo-box-item.js +5 -2
  9. package/src/vaadin-combo-box-items-mixin.d.ts +53 -0
  10. package/src/vaadin-combo-box-items-mixin.js +275 -0
  11. package/src/vaadin-combo-box-mixin.d.ts +3 -74
  12. package/src/vaadin-combo-box-mixin.js +84 -886
  13. package/src/vaadin-combo-box-overlay-mixin.js +1 -22
  14. package/src/vaadin-combo-box-overlay.js +4 -4
  15. package/src/vaadin-combo-box-scroller-mixin.d.ts +1 -2
  16. package/src/vaadin-combo-box-scroller-mixin.js +5 -0
  17. package/src/vaadin-combo-box-scroller.js +1 -1
  18. package/src/vaadin-combo-box.d.ts +33 -19
  19. package/src/vaadin-combo-box.js +67 -22
  20. package/vaadin-combo-box.js +1 -1
  21. package/web-types.json +51 -73
  22. package/web-types.lit.json +17 -24
  23. package/src/styles/vaadin-combo-box-core-styles.d.ts +0 -8
  24. package/src/styles/vaadin-combo-box-core-styles.js +0 -12
  25. package/src/styles/vaadin-combo-box-overlay-core-styles.js +0 -18
  26. package/src/styles/vaadin-combo-box-scroller-core-styles.js +0 -30
  27. package/theme/lumo/vaadin-combo-box-item-styles.d.ts +0 -5
  28. package/theme/lumo/vaadin-combo-box-item-styles.js +0 -25
  29. package/theme/lumo/vaadin-combo-box-overlay-styles.d.ts +0 -6
  30. package/theme/lumo/vaadin-combo-box-overlay-styles.js +0 -60
  31. package/theme/lumo/vaadin-combo-box-styles.d.ts +0 -2
  32. package/theme/lumo/vaadin-combo-box-styles.js +0 -12
  33. package/theme/lumo/vaadin-combo-box.d.ts +0 -4
  34. package/theme/lumo/vaadin-combo-box.js +0 -4
@@ -0,0 +1,772 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2015 - 2025 Vaadin Ltd.
4
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
+ */
6
+ import { DisabledMixin } from '@vaadin/a11y-base/src/disabled-mixin.js';
7
+ import { FocusMixin } from '@vaadin/a11y-base/src/focus-mixin.js';
8
+ import { isElementFocused, isKeyboardActive } from '@vaadin/a11y-base/src/focus-utils.js';
9
+ import { KeyboardMixin } from '@vaadin/a11y-base/src/keyboard-mixin.js';
10
+ import { isTouch } from '@vaadin/component-base/src/browser-utils.js';
11
+ import { InputMixin } from '@vaadin/field-base/src/input-mixin.js';
12
+ import { VirtualKeyboardController } from '@vaadin/field-base/src/virtual-keyboard-controller.js';
13
+ import { ComboBoxPlaceholder } from './vaadin-combo-box-placeholder.js';
14
+
15
+ /**
16
+ * @polymerMixin
17
+ * @mixes DisabledMixin
18
+ * @mixes FocusMixin
19
+ * @mixes InputMixin
20
+ * @mixes KeyboardMixin
21
+ * @param {function(new:HTMLElement)} superClass
22
+ */
23
+ export const ComboBoxBaseMixin = (superClass) =>
24
+ class ComboBoxMixinBaseClass extends KeyboardMixin(InputMixin(DisabledMixin(FocusMixin(superClass)))) {
25
+ static get properties() {
26
+ return {
27
+ /**
28
+ * True if the dropdown is open, false otherwise.
29
+ * @type {boolean}
30
+ */
31
+ opened: {
32
+ type: Boolean,
33
+ notify: true,
34
+ value: false,
35
+ reflectToAttribute: true,
36
+ sync: true,
37
+ observer: '_openedChanged',
38
+ },
39
+
40
+ /**
41
+ * Set true to prevent the overlay from opening automatically.
42
+ * @attr {boolean} auto-open-disabled
43
+ */
44
+ autoOpenDisabled: {
45
+ type: Boolean,
46
+ sync: true,
47
+ },
48
+
49
+ /**
50
+ * When present, it specifies that the field is read-only.
51
+ * @type {boolean}
52
+ */
53
+ readonly: {
54
+ type: Boolean,
55
+ value: false,
56
+ reflectToAttribute: true,
57
+ },
58
+
59
+ /**
60
+ * @type {number}
61
+ * @protected
62
+ */
63
+ _focusedIndex: {
64
+ type: Number,
65
+ observer: '_focusedIndexChanged',
66
+ value: -1,
67
+ sync: true,
68
+ },
69
+
70
+ /**
71
+ * @type {!HTMLElement | undefined}
72
+ * @protected
73
+ */
74
+ _toggleElement: {
75
+ type: Object,
76
+ observer: '_toggleElementChanged',
77
+ },
78
+
79
+ /**
80
+ * Set of items to be rendered in the dropdown.
81
+ * @protected
82
+ */
83
+ _dropdownItems: {
84
+ type: Array,
85
+ sync: true,
86
+ },
87
+
88
+ /**
89
+ * Whether the overlay should be opened.
90
+ * @protected
91
+ */
92
+ _overlayOpened: {
93
+ type: Boolean,
94
+ sync: true,
95
+ observer: '_overlayOpenedChanged',
96
+ },
97
+ };
98
+ }
99
+
100
+ constructor() {
101
+ super();
102
+
103
+ /**
104
+ * Reference to the `vaadin-combo-box-scroller` element instance.
105
+ * Do not define in `properties` to avoid triggering updates.
106
+ * @type {HTMLElement}
107
+ * @protected
108
+ */
109
+ this._scroller;
110
+
111
+ /**
112
+ * Used to detect if focusout should be ignored due to touch.
113
+ * Do not define in `properties` to avoid triggering updates.
114
+ * @type {boolean}
115
+ * @protected
116
+ */
117
+ this._closeOnBlurIsPrevented;
118
+
119
+ this._boundOverlaySelectedItemChanged = this._overlaySelectedItemChanged.bind(this);
120
+ this._boundOnClearButtonMouseDown = this.__onClearButtonMouseDown.bind(this);
121
+ this._boundOnClick = this._onClick.bind(this);
122
+ this._boundOnOverlayTouchAction = this._onOverlayTouchAction.bind(this);
123
+ this._boundOnTouchend = this._onTouchend.bind(this);
124
+ }
125
+
126
+ /**
127
+ * Tag name prefix used by scroller and items.
128
+ * @protected
129
+ * @return {string}
130
+ */
131
+ get _tagNamePrefix() {
132
+ return 'vaadin-combo-box';
133
+ }
134
+
135
+ /**
136
+ * Override method inherited from `InputMixin`
137
+ * to customize the input element.
138
+ * @protected
139
+ * @override
140
+ */
141
+ _inputElementChanged(input) {
142
+ super._inputElementChanged(input);
143
+
144
+ if (input) {
145
+ input.autocomplete = 'off';
146
+ input.autocapitalize = 'off';
147
+
148
+ input.setAttribute('role', 'combobox');
149
+ input.setAttribute('aria-autocomplete', 'list');
150
+ input.setAttribute('aria-expanded', !!this.opened);
151
+
152
+ // Disable the macOS Safari spell check auto corrections.
153
+ input.setAttribute('spellcheck', 'false');
154
+
155
+ // Disable iOS autocorrect suggestions.
156
+ input.setAttribute('autocorrect', 'off');
157
+ }
158
+ }
159
+
160
+ /** @protected */
161
+ firstUpdated() {
162
+ super.firstUpdated();
163
+
164
+ // Init scroller in `firstUpdated()` to ensure the `_scroller` reference
165
+ // is available by the time property observer runs. Also, do not store it
166
+ // in a reactive property to avoid triggering another unnecessary update.
167
+ this._initScroller();
168
+ }
169
+
170
+ /** @protected */
171
+ ready() {
172
+ super.ready();
173
+
174
+ this._initOverlay();
175
+
176
+ this.addEventListener('click', this._boundOnClick);
177
+ this.addEventListener('touchend', this._boundOnTouchend);
178
+
179
+ if (this.clearElement) {
180
+ this.clearElement.addEventListener('mousedown', this._boundOnClearButtonMouseDown);
181
+ }
182
+
183
+ this.addController(new VirtualKeyboardController(this));
184
+ }
185
+
186
+ /** @protected */
187
+ disconnectedCallback() {
188
+ super.disconnectedCallback();
189
+
190
+ // Close the overlay on detach
191
+ this.close();
192
+ }
193
+
194
+ /**
195
+ * Opens the dropdown list.
196
+ */
197
+ open() {
198
+ // Prevent _open() being called when input is disabled or read-only
199
+ if (!this.disabled && !this.readonly) {
200
+ this.opened = true;
201
+ }
202
+ }
203
+
204
+ /**
205
+ * Closes the dropdown list.
206
+ */
207
+ close() {
208
+ this.opened = false;
209
+ }
210
+
211
+ /** @private */
212
+ _initOverlay() {
213
+ const overlay = this.$.overlay;
214
+
215
+ overlay.addEventListener('touchend', this._boundOnOverlayTouchAction);
216
+ overlay.addEventListener('touchmove', this._boundOnOverlayTouchAction);
217
+
218
+ // Prevent blurring the input when clicking inside the overlay
219
+ overlay.addEventListener('mousedown', (e) => e.preventDefault());
220
+
221
+ // Manual two-way binding for the overlay "opened" property
222
+ overlay.addEventListener('opened-changed', (e) => {
223
+ this._overlayOpened = e.detail.value;
224
+ });
225
+
226
+ this._overlayElement = overlay;
227
+ }
228
+
229
+ /**
230
+ * Create and initialize the scroller element.
231
+ *
232
+ * @private
233
+ */
234
+ _initScroller() {
235
+ const scroller = document.createElement(`${this._tagNamePrefix}-scroller`);
236
+
237
+ scroller.owner = this;
238
+ scroller.getItemLabel = this._getItemLabel.bind(this);
239
+ scroller.addEventListener('selection-changed', this._boundOverlaySelectedItemChanged);
240
+
241
+ this._renderScroller(scroller);
242
+
243
+ this._scroller = scroller;
244
+ }
245
+
246
+ /**
247
+ * Render the scroller element to the overlay.
248
+ *
249
+ * @private
250
+ */
251
+ _renderScroller(scroller) {
252
+ scroller.setAttribute('slot', 'overlay');
253
+ // Prevent focusing scroller on input Tab
254
+ scroller.setAttribute('tabindex', '-1');
255
+ this.appendChild(scroller);
256
+ }
257
+
258
+ /**
259
+ * @type {boolean}
260
+ * @protected
261
+ */
262
+ get _hasDropdownItems() {
263
+ return !!(this._dropdownItems && this._dropdownItems.length);
264
+ }
265
+
266
+ /** @private */
267
+ _overlayOpenedChanged(opened, wasOpened) {
268
+ if (opened) {
269
+ this._onOpened();
270
+ } else if (wasOpened && this._hasDropdownItems) {
271
+ this.close();
272
+ this._onOverlayClosed();
273
+ }
274
+ }
275
+
276
+ /** @private */
277
+ _focusedIndexChanged(index, oldIndex) {
278
+ if (oldIndex === undefined) {
279
+ return;
280
+ }
281
+ this._updateActiveDescendant(index);
282
+ }
283
+
284
+ /** @protected */
285
+ _isInputFocused() {
286
+ return this.inputElement && isElementFocused(this.inputElement);
287
+ }
288
+
289
+ /** @private */
290
+ _updateActiveDescendant(index) {
291
+ const input = this.inputElement;
292
+ if (!input) {
293
+ return;
294
+ }
295
+
296
+ const item = this._getItemElements().find((el) => el.index === index);
297
+ if (item) {
298
+ input.setAttribute('aria-activedescendant', item.id);
299
+ } else {
300
+ input.removeAttribute('aria-activedescendant');
301
+ }
302
+ }
303
+
304
+ /** @private */
305
+ _openedChanged(opened, wasOpened) {
306
+ // Prevent _close() being called when opened is set to its default value (false).
307
+ if (wasOpened === undefined) {
308
+ return;
309
+ }
310
+
311
+ if (opened) {
312
+ // For touch devices, we don't want to popup virtual keyboard
313
+ // unless input element is explicitly focused by the user.
314
+ if (!this._isInputFocused() && !isTouch) {
315
+ if (this.inputElement) {
316
+ this.inputElement.focus();
317
+ }
318
+ }
319
+ } else {
320
+ this._onClosed();
321
+ }
322
+
323
+ const input = this.inputElement;
324
+ if (input) {
325
+ input.setAttribute('aria-expanded', !!opened);
326
+
327
+ if (opened) {
328
+ input.setAttribute('aria-controls', this._scroller.id);
329
+ } else {
330
+ input.removeAttribute('aria-controls');
331
+ }
332
+ }
333
+ }
334
+
335
+ /** @private */
336
+ _onOverlayTouchAction() {
337
+ // On touch devices, blur the input on touch start inside the overlay, in order to hide
338
+ // the virtual keyboard. But don't close the overlay on this blur.
339
+ this._closeOnBlurIsPrevented = true;
340
+ this.inputElement.blur();
341
+ this._closeOnBlurIsPrevented = false;
342
+ }
343
+
344
+ /** @protected */
345
+ _isClearButton(event) {
346
+ return event.composedPath()[0] === this.clearElement;
347
+ }
348
+
349
+ /** @private */
350
+ __onClearButtonMouseDown(event) {
351
+ event.preventDefault(); // Prevent native focusout event
352
+ this.inputElement.focus();
353
+ }
354
+
355
+ /**
356
+ * @param {Event} event
357
+ * @protected
358
+ */
359
+ _onClearButtonClick(event) {
360
+ event.preventDefault();
361
+ this._onClearAction();
362
+ }
363
+
364
+ /**
365
+ * @param {Event} event
366
+ * @private
367
+ */
368
+ _onToggleButtonClick(event) {
369
+ // Prevent parent components such as `vaadin-grid`
370
+ // from handling the click event after it bubbles.
371
+ event.preventDefault();
372
+
373
+ if (this.opened) {
374
+ this.close();
375
+ } else {
376
+ this.open();
377
+ }
378
+ }
379
+
380
+ /**
381
+ * @param {Event} event
382
+ * @protected
383
+ */
384
+ _onHostClick(event) {
385
+ if (!this.autoOpenDisabled) {
386
+ event.preventDefault();
387
+ this.open();
388
+ }
389
+ }
390
+
391
+ /** @private */
392
+ _onClick(event) {
393
+ if (this._isClearButton(event)) {
394
+ this._onClearButtonClick(event);
395
+ } else if (event.composedPath().includes(this._toggleElement)) {
396
+ this._onToggleButtonClick(event);
397
+ } else {
398
+ this._onHostClick(event);
399
+ }
400
+ }
401
+
402
+ /** @private */
403
+ _onTouchend(event) {
404
+ if (!this.clearElement || event.composedPath()[0] !== this.clearElement) {
405
+ return;
406
+ }
407
+
408
+ event.preventDefault();
409
+ this._onClearAction();
410
+ }
411
+
412
+ /**
413
+ * Override an event listener from `KeyboardMixin`.
414
+ *
415
+ * @param {KeyboardEvent} e
416
+ * @protected
417
+ * @override
418
+ */
419
+ _onKeyDown(e) {
420
+ super._onKeyDown(e);
421
+
422
+ if (e.key === 'ArrowDown') {
423
+ this._onArrowDown();
424
+
425
+ // Prevent caret from moving
426
+ e.preventDefault();
427
+ } else if (e.key === 'ArrowUp') {
428
+ this._onArrowUp();
429
+
430
+ // Prevent caret from moving
431
+ e.preventDefault();
432
+ }
433
+ }
434
+
435
+ /**
436
+ * Override to provide logic for item label path.
437
+ * @protected
438
+ */
439
+ _getItemLabel(item) {
440
+ return item ? item.toString() : '';
441
+ }
442
+
443
+ /** @private */
444
+ _onArrowDown() {
445
+ if (this.opened) {
446
+ const items = this._dropdownItems;
447
+ if (items) {
448
+ this._focusedIndex = Math.min(items.length - 1, this._focusedIndex + 1);
449
+ this._prefillFocusedItemLabel();
450
+ }
451
+ } else {
452
+ this.open();
453
+ }
454
+ }
455
+
456
+ /** @private */
457
+ _onArrowUp() {
458
+ if (this.opened) {
459
+ if (this._focusedIndex > -1) {
460
+ this._focusedIndex = Math.max(0, this._focusedIndex - 1);
461
+ } else {
462
+ const items = this._dropdownItems;
463
+ if (items) {
464
+ this._focusedIndex = items.length - 1;
465
+ }
466
+ }
467
+
468
+ this._prefillFocusedItemLabel();
469
+ } else {
470
+ this.open();
471
+ }
472
+ }
473
+
474
+ /** @private */
475
+ _prefillFocusedItemLabel() {
476
+ if (this._focusedIndex > -1) {
477
+ const focusedItem = this._dropdownItems[this._focusedIndex];
478
+ this._inputElementValue = this._getItemLabel(focusedItem);
479
+ this._markAllSelectionRange();
480
+ }
481
+ }
482
+
483
+ /** @private */
484
+ _setSelectionRange(start, end) {
485
+ // Setting selection range focuses and/or moves the caret in some browsers,
486
+ // and there's no need to modify the selection range if the input isn't focused anyway.
487
+ // This affects Safari. When the overlay is open, and then hitting tab, browser should focus
488
+ // the next focusable element instead of the combo-box itself.
489
+ if (this._isInputFocused() && this.inputElement.setSelectionRange) {
490
+ this.inputElement.setSelectionRange(start, end);
491
+ }
492
+ }
493
+
494
+ /** @private */
495
+ _markAllSelectionRange() {
496
+ if (this._inputElementValue !== undefined) {
497
+ this._setSelectionRange(0, this._inputElementValue.length);
498
+ }
499
+ }
500
+
501
+ /** @private */
502
+ _clearSelectionRange() {
503
+ if (this._inputElementValue !== undefined) {
504
+ const pos = this._inputElementValue ? this._inputElementValue.length : 0;
505
+ this._setSelectionRange(pos, pos);
506
+ }
507
+ }
508
+
509
+ /**
510
+ * @protected
511
+ */
512
+ _closeOrCommit() {
513
+ if (!this.opened) {
514
+ this._commitValue();
515
+ } else {
516
+ this.close();
517
+ }
518
+ }
519
+
520
+ /**
521
+ * Override an event listener from `KeyboardMixin`.
522
+ *
523
+ * @param {KeyboardEvent} e
524
+ * @protected
525
+ * @override
526
+ */
527
+ _onEnter(e) {
528
+ // Do not commit value when custom values are disallowed and input value is not a valid option
529
+ // also stop propagation of the event, otherwise the user could submit a form while the input
530
+ // still contains an invalid value
531
+ if (!this._hasValidInputValue()) {
532
+ // Do not submit the surrounding form.
533
+ e.preventDefault();
534
+ // Do not trigger global listeners
535
+ e.stopPropagation();
536
+ return;
537
+ }
538
+
539
+ // Stop propagation of the enter event only if the dropdown is opened, this
540
+ // "consumes" the enter event for the action of closing the dropdown
541
+ if (this.opened) {
542
+ // Do not submit the surrounding form.
543
+ e.preventDefault();
544
+ // Do not trigger global listeners
545
+ e.stopPropagation();
546
+ }
547
+
548
+ this._closeOrCommit();
549
+ }
550
+
551
+ /**
552
+ * Override this method to detect whether valid value is provided.
553
+ * @protected
554
+ */
555
+ _hasValidInputValue() {
556
+ return true;
557
+ }
558
+
559
+ /**
560
+ * Override an event listener from `KeyboardMixin`.
561
+ * Do not call `super` in order to override clear
562
+ * button logic defined in `InputControlMixin`.
563
+ *
564
+ * @param {!KeyboardEvent} e
565
+ * @protected
566
+ * @override
567
+ */
568
+ _onEscape(e) {
569
+ if (
570
+ this.autoOpenDisabled &&
571
+ (this.opened || (this.value !== this._inputElementValue && this._inputElementValue.length > 0))
572
+ ) {
573
+ // Auto-open is disabled
574
+ // The overlay is open or
575
+ // The input value has changed but the change hasn't been committed, so cancel it.
576
+ e.stopPropagation();
577
+ this._focusedIndex = -1;
578
+ this._onEscapeCancel();
579
+ } else if (this.opened) {
580
+ // Auto-open is enabled
581
+ // The overlay is open
582
+ e.stopPropagation();
583
+
584
+ if (this._focusedIndex > -1) {
585
+ // An item is focused, revert the input to the filtered value
586
+ this._focusedIndex = -1;
587
+ this._revertInputValue();
588
+ } else {
589
+ // No item is focused, cancel the change and close the overlay
590
+ this._onEscapeCancel();
591
+ }
592
+ } else if (this.clearButtonVisible && !!this.value && !this.readonly) {
593
+ e.stopPropagation();
594
+ // The clear button is visible and the overlay is closed, so clear the value.
595
+ this._onClearAction();
596
+ }
597
+ }
598
+
599
+ /**
600
+ * Override to handle canceling and closing overlay on Escape.
601
+ * @protected
602
+ */
603
+ _onEscapeCancel() {
604
+ // To be implemented
605
+ }
606
+
607
+ /** @private */
608
+ _toggleElementChanged(toggleElement) {
609
+ if (toggleElement) {
610
+ // Don't blur the input on toggle mousedown
611
+ toggleElement.addEventListener('mousedown', (e) => e.preventDefault());
612
+ // Unfocus previously focused element if focus is not inside combo box (on touch devices)
613
+ toggleElement.addEventListener('click', () => {
614
+ if (isTouch && !this._isInputFocused()) {
615
+ document.activeElement.blur();
616
+ }
617
+ });
618
+ }
619
+ }
620
+
621
+ /**
622
+ * Override to implement logic for clearing value.
623
+ * @protected
624
+ */
625
+ _onClearAction() {
626
+ // To be implemented
627
+ }
628
+
629
+ /**
630
+ * Override to implement logic for overlay opening.
631
+ * @protected
632
+ */
633
+ _onOpened() {
634
+ // To be implemented
635
+ }
636
+
637
+ /**
638
+ * Override to implement logic for changing opened to false.
639
+ * @protected
640
+ */
641
+ _onClosed() {
642
+ // To be implemented
643
+ }
644
+
645
+ /**
646
+ * Override to implement logic for overlay closing.
647
+ * @protected
648
+ */
649
+ _onOverlayClosed() {
650
+ // To be implemented
651
+ }
652
+
653
+ /**
654
+ * Override to implement logic for committing value.
655
+ * @protected
656
+ */
657
+ _commitValue() {
658
+ // To be implemented
659
+ }
660
+
661
+ /**
662
+ * Override to implement logic for value reverting.
663
+ * @protected
664
+ */
665
+ _revertInputValue() {
666
+ this._inputElementValue = this.value;
667
+ this._clearSelectionRange();
668
+ }
669
+
670
+ /**
671
+ * Override an event listener from `InputMixin`.
672
+ * @param {!Event} event
673
+ * @protected
674
+ * @override
675
+ */
676
+ _onInput(event) {
677
+ if (!this.opened && !this._isClearButton(event) && !this.autoOpenDisabled) {
678
+ this.opened = true;
679
+ }
680
+ }
681
+
682
+ /** @private */
683
+ _getItemElements() {
684
+ return Array.from(this._scroller.querySelectorAll(`${this._tagNamePrefix}-item`));
685
+ }
686
+
687
+ /** @protected */
688
+ _scrollIntoView(index) {
689
+ if (!this._scroller) {
690
+ return;
691
+ }
692
+ this._scroller.scrollIntoView(index);
693
+ }
694
+
695
+ /** @private */
696
+ _overlaySelectedItemChanged(e) {
697
+ // Stop this private event from leaking outside.
698
+ e.stopPropagation();
699
+
700
+ if (e.detail.item instanceof ComboBoxPlaceholder) {
701
+ // Placeholder items should not be selectable.
702
+ return;
703
+ }
704
+
705
+ if (this.opened) {
706
+ this._focusedIndex = this._dropdownItems.indexOf(e.detail.item);
707
+ this.close();
708
+ }
709
+ }
710
+
711
+ /**
712
+ * Override method inherited from `FocusMixin`
713
+ * to close the overlay on blur and commit the value.
714
+ *
715
+ * @param {boolean} focused
716
+ * @protected
717
+ * @override
718
+ */
719
+ _setFocused(focused) {
720
+ super._setFocused(focused);
721
+
722
+ if (!focused && !this.readonly && !this._closeOnBlurIsPrevented) {
723
+ this._handleFocusOut();
724
+ }
725
+ }
726
+
727
+ /**
728
+ * Override this method to provide custom logic for focusout.
729
+ * @protected
730
+ */
731
+ _handleFocusOut() {
732
+ if (isKeyboardActive()) {
733
+ // Close on Tab key causing blur. With mouse, close on outside click instead.
734
+ this._closeOrCommit();
735
+ return;
736
+ }
737
+
738
+ if (!this.opened) {
739
+ this._commitValue();
740
+ } else if (!this._overlayOpened) {
741
+ // Combo-box is opened, but overlay is not visible -> custom value was entered.
742
+ // Make sure we close here as there won't be an "outside click" in this case.
743
+ this.close();
744
+ }
745
+ }
746
+
747
+ /**
748
+ * Override method inherited from `FocusMixin` to not remove focused
749
+ * state when focus moves to the overlay.
750
+ *
751
+ * @param {FocusEvent} event
752
+ * @return {boolean}
753
+ * @protected
754
+ * @override
755
+ */
756
+ _shouldRemoveFocus(event) {
757
+ // VoiceOver on iOS fires `focusout` event when moving focus to the item in the dropdown.
758
+ // Do not focus the input in this case, because it would break announcement for the item.
759
+ if (event.relatedTarget && event.relatedTarget.localName === `${this._tagNamePrefix}-item`) {
760
+ return false;
761
+ }
762
+
763
+ // Do not blur when focus moves to the overlay
764
+ // Also, fixes the problem with `focusout` happening when clicking on the scroll bar on Edge
765
+ if (event.relatedTarget === this._overlayElement) {
766
+ event.composedPath()[0].focus();
767
+ return false;
768
+ }
769
+
770
+ return true;
771
+ }
772
+ };