ui icon indicating copy to clipboard operation
ui copied to clipboard

feat(button): support render delegation with asChild parameter

Open emrosenf opened this issue 1 year ago • 6 comments

This PR adds the asChild parameter to Button, which renders the child component with the Button's behavior and styles, reducing DOM nodes.

Example:

<Button asChild variant="ghost">
  <Link to="/login">Login</Link>
</Button>

This pattern is very common in frameworks (e.g. Next.js, Remix, etc) and is used throughout @radix-ui/primitives

Here is a blogpost on implementation

emrosenf avatar Apr 17 '23 03:04 emrosenf

Someone is attempting to deploy a commit to the shadcn-pro Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot] avatar Apr 17 '23 03:04 vercel[bot]

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 30, 2023 7:55am
1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
next-template ⬜️ Ignored (Inspect) Visit Preview Apr 30, 2023 7:55am

vercel[bot] avatar Apr 17 '23 11:04 vercel[bot]

@emrosenf This is brilliant 👏

I'll review and merge.

shadcn avatar Apr 17 '23 11:04 shadcn

Sweet! Let me know if you need help with the documentation

emrosenf avatar Apr 17 '23 12:04 emrosenf

Sweet! Let me know if you need help with the documentation

Yeah. Let's update this section with your example above: https://ui.shadcn.com/docs/components/button#link

(Can you also run pnpm format:write to fix the formatting issues please?)

Thank you.

shadcn avatar Apr 20 '23 09:04 shadcn

Sweet! Let me know if you need help with the documentation

Yeah. Let's update this section with your example above: https://ui.shadcn.com/docs/components/button#link

(Can you also run pnpm format:write to fix the formatting issues please?)

Thank you.

Good call. Done. You can consider adding format as a commit hook so your PRs all come in formatted correctly.

emrosenf avatar Apr 20 '23 13:04 emrosenf