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.

Example

Relevant Table Options

Prop NameTypeDescription
enableClickToCopyboolean | 'context-menu' | ((cell: ST_Cell<TData>) => 'context-menu' | boolean)
stCopyButtonPropsButtonProps | ({ cell, column, row, table }) => ButtonProps

Relevant Column Options

Column OptionTypeDescription
enableClickToCopyboolean | 'context-menu' | ((cell: ST_Cell<TData>) => 'context-menu' | boolean)Enable the click to copy feature for this column.
stCopyButtonPropsButtonProps | ({ cell, column, row, table }) => ButtonProps

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',
  },
});

View Extra Storybook Examples

On this page