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

@ -30,22 +30,30 @@ A utility component for wrapping demo elements with post-render functionality.
**Usage:**
```typescript
import { DeesDemoWrapper } from '@design.estate/dees-wcctools/demoTools';
import * as demoTools from '@design.estate/dees-wcctools/demotools';
// In your demo function:
demo: () => html`
<dees-demowrapper .runAfterRender=${(element) => {
// Do something with the rendered element
element.setAttribute('data-demo', 'true');
console.log('Element rendered:', element);
<dees-demowrapper .runAfterRender=${(children: HTMLCollection) => {
// Access all slotted elements
const firstElement = children[0] as HTMLElement;
firstElement.setAttribute('data-demo', 'true');
console.log('All slotted elements:', children);
// Work with multiple elements
Array.from(children).forEach(child => {
console.log('Element rendered:', child);
});
}}>
<my-custom-element></my-custom-element>
<div>Additional content</div>
</dees-demowrapper>
`
```
**Features:**
- Wraps demo elements without affecting layout (uses `display: contents`)
- Provides access to the rendered element instance after mounting
- Provides access to ALL slotted elements via HTMLCollection after mounting
- Supports async operations in runAfterRender callback
- Automatically handles timing to ensure element is fully rendered
- Automatically handles timing to ensure elements are fully rendered
- Can handle multiple slotted elements, not just the first one