Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Shadcn Download Trigger for React and Tailwind

Trigger file downloads programmatically.

Hello, World! This is a sample text file.

Installation

bunx --bun shadcn@latest add https://kit.dev/r/download-trigger.json

Usage

import { DownloadIcon, FileTextIcon } from "lucide-react";
import { Button } from "@/components/ui/button";
import { DownloadTrigger } from "@/components/ui/download-trigger";
import { Item, ItemTitle } from "@/components/ui/item";
const DownloadTriggerDemo = () => (
  <div className="flex flex-col gap-4">
    <Item variant="outline">
      <FileTextIcon />
      <ItemTitle>{content}</ItemTitle>
    </Item>
    <DownloadTrigger
      asChild
      data={content}
      fileName="hello.txt"
      mimeType="text/plain"
    >
      <Button size="lg" variant="outline">
        <DownloadIcon />
        Download
      </Button>
    </DownloadTrigger>
  </div>
);

const content = "Hello, World! This is a sample text file.";

Accessibility

KeyDescription
Enter
Activate the focused control.
Space
Activate the focused control.

Demos

Download Svg

Promise

API Reference

DownloadTrigger

PropType
AttributeType