# QR Code Share Dialog (Components)

URL: https://qrdx.dev/docs/components/qr-code-share-dialog
Source: https://github.com/qrdxinc/qrdx/blob/main/apps/docs/content/docs/components/qr-code-share-dialog.mdx

A share dialog for shadcn/ui projects with a QR code for a link, a copy button, a PNG download and the native share sheet.

`QrCodeShareDialog` opens a dialog that shows a link as a QR code, with the link in a field you can copy, a PNG download and, on phones, the system share sheet. Use it behind a "Share" button wherever people hand a link to someone standing next to them: an invite, a document, a profile.

## Installation [#installation]

```bash
npx shadcn@latest add @qrdx/qr-code-share-dialog
```

Or by URL, which works with older versions of the CLI too:

```bash
npx shadcn@latest add https://qrdx.dev/r/qr-code-share-dialog.json
```

## Usage [#usage]

```tsx title="components/example.tsx"
import { QrCodeShareDialog } from "@/components/qr-code-share-dialog";
```

```tsx title="components/example.tsx"
<QrCodeShareDialog url="https://example.com/invite/abc123" />
```

The dialog shows the code, the link in a read-only field with a copy button, and **Download PNG**. On devices with a share sheet (most phones), a **Share…** button opens it.

## Examples [#examples]

### Custom trigger [#custom-trigger]

Pass your own trigger as children, such as an icon button in a toolbar. `title`, `description` and `qr` customize the dialog.

### Controlled [#controlled]

The dialog accepts the [Dialog](https://ui.shadcn.com/docs/components/dialog) props, so you can open it from code:

```tsx title="components/share-after-save.tsx"
"use client";

import { useState } from "react";
import { QrCodeShareDialog } from "@/components/qr-code-share-dialog";

export function ShareAfterSave({ url }: { url: string }) {
  const [open, setOpen] = useState(false);
  return (
    <>
      <button type="button" onClick={() => setOpen(true)}>
        Save and share
      </button>
      <QrCodeShareDialog url={url} open={open} onOpenChange={setOpen} />
    </>
  );
}
```

## Accessibility and rendering [#accessibility-and-rendering]

- The dialog is your Dialog, so focus moves into it when it opens and returns to the trigger when it closes.
- The code has `aria-label="QR code: <url>"`, and the link field has a visually hidden "Link" label. The copy button's label changes to "Link copied" for a moment after a copy.
- The **Share…** button appears only where `navigator.share` exists, after the first render in the browser, so the server's HTML and the client's first paint match.
- Clicking the link field selects the whole link. Copying needs a secure context (HTTPS or localhost).

## API reference [#api-reference]

### $Fumadocs

| Prop           | Type          | Description                                                                         |
| -------------- | ------------- | ----------------------------------------------------------------------------------- |
| `url`          | `string`      | The link to share. It is encoded in the QR code.                                    |
| `title?`       | `string`      | Dialog title. Default: `"Share link"`                                               |
| `description?` | `ReactNode`   | Text under the title. Default: `"Anyone with the link or the QR code can open it."` |
| `children?`    | `ReactNode`   | Custom trigger element. Defaults to a "Share" button.                               |
| `size?`        | `number`      | Width and height of the code in pixels. Default: `200`                              |
| `qr?`          | `QrCodeStyle` | qrdx style options for the code.                                                    |
| `filename?`    | `string`      | File name for the PNG download, without extension. Default: `"qr-code"`             |

`open`, `defaultOpen`, `onOpenChange` and `modal` are passed to the Dialog.

## Related [#related]

- [QR Code Download](https://qrdx.dev/docs/components/qr-code-download): More formats and sizes than the dialog's single PNG button.
- [QR Code](https://qrdx.dev/docs/components/qr-code): The code inline on a page instead of in a dialog.
- [Dynamic QR codes](https://qrdx.dev/docs/dynamic-qr-codes): Share a short link you can change later instead of the final URL.
