diff --git a/src/declarations/stencil-private.ts b/src/declarations/stencil-private.ts index 20d6014f8dd3..6ac1c6b508b0 100644 --- a/src/declarations/stencil-private.ts +++ b/src/declarations/stencil-private.ts @@ -1331,6 +1331,12 @@ export interface RenderNode extends HostElement { */ host?: Element; + /** + * On Ref Function: + * Callback function to be called when the slotted node ref is ready. + */ + ['s-rf']?: (elm: Element) => unknown; + /** * Is initially hidden * Whether this node was originally rendered with the `hidden` attribute. diff --git a/src/runtime/vdom/vdom-render.ts b/src/runtime/vdom/vdom-render.ts index e465e4b37ddb..6de2d4610221 100644 --- a/src/runtime/vdom/vdom-render.ts +++ b/src/runtime/vdom/vdom-render.ts @@ -149,6 +149,9 @@ const createElm = (oldParentVNode: d.VNode, newParentVNode: d.VNode, childIndex: // remember the slot name, or empty string for default slot elm['s-sn'] = newVNode.$name$ || ''; + // remember the ref callback function + elm['s-rf'] = newVNode.$attrs$?.ref; + // check if we've got an old vnode for this slot oldVNode = oldParentVNode && oldParentVNode.$children$ && oldParentVNode.$children$[childIndex]; if (oldVNode && oldVNode.$tag$ === newVNode.$tag$ && oldParentVNode.$elm$) { @@ -1094,6 +1097,8 @@ render() { } } } + + nodeToRelocate && typeof slotRefNode['s-rf'] === 'function' && slotRefNode['s-rf'](nodeToRelocate); } else { // this node doesn't have a slot home to go to, so let's hide it if (nodeToRelocate.nodeType === NODE_TYPE.ElementNode) {