|
1 | | -import { attr, FASTElement, Observable, observable, Updates } from '@microsoft/fast-element'; |
| 1 | +import { attr, FASTElement, Observable, observable } from '@microsoft/fast-element'; |
2 | 2 | import { BaseAccordionItem } from '../accordion-item/accordion-item.base.js'; |
3 | | -import { waitForConnectedDescendants } from '../utils/request-idle-callback.js'; |
4 | 3 | import { isAccordionItem } from '../accordion-item/accordion-item.options.js'; |
| 4 | +import { getUpgradedCustomElements, runAfterPendingDefinitions } from '../utils/custom-elements.js'; |
| 5 | +import { waitForConnectedDescendants } from '../utils/request-idle-callback.js'; |
5 | 6 | import { AccordionExpandMode } from './accordion.options.js'; |
6 | 7 |
|
7 | 8 | /** |
@@ -114,15 +115,22 @@ export class Accordion extends FASTElement { |
114 | 115 | return; |
115 | 116 | } |
116 | 117 |
|
117 | | - // Get all existing children and remove event listeners |
| 118 | + this.removeItemListeners(this.accordionItems ?? []); |
| 119 | + |
118 | 120 | const children: Element[] = Array.from(this.children); |
119 | | - this.removeItemListeners(children); |
| 121 | + const accordionItems = getUpgradedCustomElements(children, isAccordionItem); |
| 122 | + |
| 123 | + runAfterPendingDefinitions(children, isAccordionItem, () => { |
| 124 | + if (this.isConnected) { |
| 125 | + this.setItems(); |
| 126 | + } |
| 127 | + }); |
120 | 128 |
|
121 | 129 | // Resubscribe to the `disabled` attribute of all children |
122 | | - children.forEach((child: Element) => Observable.getNotifier(child).subscribe(this, 'disabled')); |
| 130 | + accordionItems.forEach((child: Element) => Observable.getNotifier(child).subscribe(this, 'disabled')); |
123 | 131 |
|
124 | 132 | // Add event listeners to each non-disabled AccordionItem |
125 | | - this.accordionItems = children.filter(child => !child.hasAttribute('disabled')); |
| 133 | + this.accordionItems = accordionItems.filter(child => !child.hasAttribute('disabled')); |
126 | 134 | this.accordionItems.forEach((item: Element, index: number) => { |
127 | 135 | item.addEventListener('click', this.expandedChangedHandler); |
128 | 136 | // Subscribe to the expanded attribute of the item |
|
0 commit comments