DocsGuides

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

#
Prop Name
Type
Default Value
More Info Links
1boolean | 'context-menu' | ((cell: ST_Cell<TData>) => 'context-menu' | boolean)falseST Click to Copy Docs
2ButtonProps | ({ cell, column, row, table }) => ButtonPropsshadcn/ui Button Props

Relevant Column Options

#
Column Option
Type
Default Value
More Info Links
1boolean | 'context-menu' | ((cell: ST_Cell<TData>) => 'context-menu' | boolean)ST Click to Copy Docs
2ButtonProps | ({ cell, column, row, table }) => ButtonPropsshadcn/ui Button API

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

Loading example

View Extra Storybook Examples

On this page