fix(demotools): update DeesDemoWrapper to handle multiple slotted elements in runAfterRender callback

This commit is contained in:
Juergen Kunz
2025-06-16 14:35:28 +00:00
parent bed41da573
commit 87bbf0bbdc
5 changed files with 57 additions and 34 deletions

View File

@ -3,7 +3,7 @@ import { DeesElement, customElement, html, css, property, type TemplateResult }
@customElement('dees-demowrapper')
export class DeesDemoWrapper extends DeesElement {
@property({ attribute: false })
public runAfterRender: (element: HTMLElement) => void | Promise<void>;
public runAfterRender: (children: HTMLCollection) => void | Promise<void>;
public static styles = [
css`
@ -25,14 +25,12 @@ export class DeesDemoWrapper extends DeesElement {
// Wait a bit for slotted content to render
await new Promise(resolve => setTimeout(resolve, 50));
// Find the first element child (excluding text nodes)
// Get all slotted elements
const slottedElements = this.children;
if (slottedElements.length > 0 && this.runAfterRender) {
const firstElement = slottedElements[0] as HTMLElement;
// Call the runAfterRender function with the element
// Call the runAfterRender function with all slotted elements
try {
await this.runAfterRender(firstElement);
await this.runAfterRender(slottedElements);
} catch (error) {
console.error('Error in runAfterRender:', error);
}