Guides
Click to Copy Guide
How to use and customize the click to copy features of Shadcn Table
Shadcn Table has an easy-to-implement feature that allows a user to copy a cell's value to the clipboard.
Relevant Table Options
Relevant Column Options
Enable Click to Copy Per Column
Most likely, there will just be a couple columns that you want to enable click to copy for. You can do this by setting the enableClickToCopy option to true per column on the column definition.
const columns = [
//...
{
accessorKey: 'email',
header: 'Email',
enableClickToCopy: true,
},
//...
];Enable Click to Copy For All Cells
Alternatively, you can enable click to copy globally by setting the enableClickToCopy table option to true. You could then opt out per column by setting the enableClickToCopy option to false on the column definition.
const table = useShadcnTable({
columns,
data,
enableClickToCopy: true,
});Customize Copy Buttons
The click to copy feature is built on top of the shadcn/ui Button component. You can customize the copy button by passing in the stCopyButtonProps table or column option.
const table = useShadcnTable({
columns,
data,
enableClickToCopy: true,
stCopyButtonProps: {
className: 'w-full justify-start',
},
});Click to Copy Example
View Extra Storybook Examples