Shadcn/next problem with button inside button
Answered
Common House-Martin posted this in #help-forum
Common House-MartinOP
Hey I have a problem that's been annoying me for a while. In shadcn you have some components that have triggers on them for example this
you see the problem I have is that I want to trigger the component using the button component from the same ui but if i do that, the console will complain that a button is inside another because drawertrigger is a button tag too.
a few solutions are just copying the style from the button into the trigger, or I could do use usestate to set the open property but there's gotta be a more efficient way of doing it right?
<Drawer>
<DrawerTrigger><Button>Open</Button></DrawerTrigger>
<DrawerContent>
<DrawerHeader>
<DrawerTitle>Are you absolutely sure?</DrawerTitle>
<DrawerDescription>This action cannot be undone.
</DrawerDescription>
</DrawerHeader>
<DrawerFooter>
<Button>Submit</Button>
<DrawerClose>
<Button variant="outline">Cancel</Button>
</DrawerClose>
</DrawerFooter>
</DrawerContent>
</Drawer>you see the problem I have is that I want to trigger the component using the button component from the same ui but if i do that, the console will complain that a button is inside another because drawertrigger is a button tag too.
a few solutions are just copying the style from the button into the trigger, or I could do use usestate to set the open property but there's gotta be a more efficient way of doing it right?
Answered by Ray
have you tried this?
<DrawerTrigger asChild><Button>Open</Button></DrawerTrigger>4 Replies
You should use
asChild in the Trigger component.Common House-MartinOP
Oh yeah that's it, I swear I tried that it must not have refreshed or something, thanks guys.