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
75.37k stars 4.72k forks source link

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

Open minhsu12113 opened 2 weeks ago

minhsu12113 commented 2 weeks 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 2 weeks 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>