-
Notifications
You must be signed in to change notification settings - Fork 12
Open
Description
- I searched for an existing RRFC which might be relevant to my RRFC
Motivation
Moved from lit/lit#2693
There are a few common patterns for using slots that could be nicely wrapped up in a reactive controller:
- Determining when a slot has assigned content so you can style the component differently (ex: add padding when there's content).
- Tracking slotted children to call APIs (set properties, add/remove event listeners, call methods) when child enter and exit the slot.
Example
We could make a SlotController(s) to help.
class MyElement extends LitElement {
private _slotController = new SlotController(this);
render() {
const slotStyles = {
padding: this._slotController.hasAssignedElements() ? '4px' : 0,
};
return html`<slot style=${styleMap(slotStyles)}></slot>`;
}
}
How
See https://gist.github.com/justinfagnani/a90eefb8da6bbfa4250a46732a8e5fbc
Current Behavior
Libraries write their own slot controller, like https://github.com/shoelace-style/shoelace/blob/next/src/internal/slot.ts or users use slotchange
.
Desired Behavior
It's easier.
References
- n/a
CathalMullan
Metadata
Metadata
Assignees
Labels
No labels