Skip to content

asChild for TooltipTrigger and TooltipAnchor #96

@teidesu

Description

@teidesu

it would be cool if TooltipTrigger and TooltipAnchor had an asChild prop (similar to radix) that would attach the listeners to already existing dom nodes instead of creating a new wrapper div.

currently i have to patch @corvu/tooltip to expose useInternalTooltipContext (since the set{Anchor,Trigger}Ref are only available there. tbh would be nice if they were public too) and do something like this

function TooltipTrigger(props: { children: JSX.Element }) {
  const child = resolveFirst(() => props.children)

  const context = TooltipPrimitive.useInternalContext()

  createEffect(on(child, (child) => {
    context.setTriggerRef(child)
  }))

  return child as unknown as JSX.Element
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions