|
60 | 60 | this.itemTemplate = this.itemsListContainer.dataset.template; |
61 | 61 | this.sourceOptionsObserver = new MutationObserver((mutationsList) => { |
62 | 62 | if (this.hasChangedOptions(mutationsList)) { |
| 63 | + const optionsCount = this.sourceInput.querySelectorAll('option').length; |
| 64 | + |
| 65 | + if (optionsCount && !this.itemsPopover) { |
| 66 | + this.initializeDropdownUI(); |
| 67 | + } |
| 68 | + |
63 | 69 | this.recreateOptions(); |
64 | 70 | } |
65 | 71 | }); |
|
91 | 97 | this.itemsPopoverContent = this.itemsPopoverContent.bind(this); |
92 | 98 | this.onSourceFocus = this.onSourceFocus.bind(this); |
93 | 99 | this.onSourceBlur = this.onSourceBlur.bind(this); |
| 100 | + this.initializeDropdownUI = this.initializeDropdownUI.bind(this); |
94 | 101 |
|
95 | 102 | ibexa.helpers.objectInstances.setInstance(this.container, this); |
96 | 103 | } |
|
530 | 537 | this.selectionTogglerBtn.innerHTML = label; |
531 | 538 | } |
532 | 539 |
|
533 | | - init() { |
534 | | - if (this.container.dataset.initialized) { |
535 | | - console.warn('Dropdown has already been initialized!'); |
536 | | - |
537 | | - return; |
538 | | - } |
539 | | - |
540 | | - this.container.dataset.initialized = true; |
541 | | - |
542 | | - this.sourceInput.addEventListener('focus', this.onSourceFocus, false); |
543 | | - this.sourceInput.addEventListener('blur', this.onSourceBlur, false); |
544 | | - |
545 | | - const optionsCount = this.container.querySelectorAll('.ibexa-dropdown__source option').length; |
546 | | - |
547 | | - if (!optionsCount) { |
| 540 | + initializeDropdownUI() { |
| 541 | + if (this.itemsPopover) { |
548 | 542 | return; |
549 | 543 | } |
550 | 544 |
|
|
610 | 604 | this.itemsFilterInput.addEventListener('keyup', this.filterItems, false); |
611 | 605 | this.itemsFilterInput.addEventListener('input', this.filterItems, false); |
612 | 606 | } |
| 607 | + } |
613 | 608 |
|
| 609 | + init() { |
| 610 | + if (this.container.dataset.initialized) { |
| 611 | + console.warn('Dropdown has already been initialized!'); |
| 612 | + |
| 613 | + return; |
| 614 | + } |
| 615 | + |
| 616 | + this.container.dataset.initialized = true; |
| 617 | + |
| 618 | + this.sourceInput.addEventListener('focus', this.onSourceFocus, false); |
| 619 | + this.sourceInput.addEventListener('blur', this.onSourceBlur, false); |
614 | 620 | this.sourceOptionsObserver.observe(this.sourceInput, { |
615 | 621 | childList: true, |
616 | 622 | }); |
|
620 | 626 | }); |
621 | 627 | this.resizeObserver.observe(this.container); |
622 | 628 |
|
| 629 | + const optionsCount = this.container.querySelectorAll('.ibexa-dropdown__source option').length; |
| 630 | + |
| 631 | + if (!optionsCount) { |
| 632 | + return; |
| 633 | + } |
| 634 | + |
| 635 | + this.initializeDropdownUI(); |
| 636 | + |
623 | 637 | const selectedItems = this.container.querySelectorAll( |
624 | 638 | '.ibexa-dropdown__selected-item:not(.ibexa-dropdown__selected-overflow-number):not(.ibexa-dropdown__selected-placeholder)', |
625 | 639 | ); |
|
0 commit comments