shadcn-ui / ui

Beautifully designed components that you can copy and paste into your apps. Accessible. Customizable. Open Source.
https://ui.shadcn.com
MIT License
74.46k stars 4.61k forks source link

[bug]: Incident bug validateDOMNesting(...): <button> cannot appear as a descendant of <button> #5777

Open minhsu12113 opened 5 days ago

minhsu12113 commented 5 days ago

Describe the bug

I creating tree compoent with checkbox like the below image

image

That component reference: https://github.com/shadcn-ui/ui/issues/355#issuecomment-1703767574

I'm notice if I put the Checkbox inside Tree item then I get error: validateDOMNesting(...):

minhsu12113 commented 5 days ago

For anyone facing same issue as I am, you can use input type checkbox instead of button. You might want to re-style the input as needed.

<div className='flex items-center gap-2 w-full'>
    <input
       type='checkbox'
       className='rounded-sm w-4 h-4  focus:ring-primary text-primary dark:focus:ring-primary dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600' />
       <span className='flex-grow text-sm truncate'>{item.name}</span>
</div>