Skip to content

Commit 67b6f9a

Browse files
committed
refactor(CFocusTrap): expose container reference properly
1 parent 9dae4d7 commit 67b6f9a

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

packages/coreui-vue/src/components/focus-trap/CFocusTrap.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -278,14 +278,25 @@ const CFocusTrap = defineComponent({
278278
containerRef,
279279
})
280280

281-
return () =>
282-
slots.default?.().map((slot) =>
283-
cloneVNode(slot, {
284-
ref: (el) => {
285-
containerRef.value = el as HTMLElement | null
286-
},
287-
})
288-
)
281+
return () => {
282+
const vnodes = slots.default?.()
283+
const vnode = vnodes?.[0]
284+
if (!vnode) return null
285+
286+
const originalRef = (vnode.props as any)?.ref
287+
288+
return cloneVNode(vnode, {
289+
ref: (el) => {
290+
containerRef.value = el as HTMLElement | null
291+
292+
if (typeof originalRef === 'function') {
293+
originalRef(el)
294+
} else if (originalRef && typeof originalRef === 'object' && 'value' in originalRef) {
295+
;(originalRef as { value: any }).value = el
296+
}
297+
},
298+
})
299+
}
289300
},
290301
})
291302

0 commit comments

Comments
 (0)