# QR Code Scanner (Components)

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

A drop zone for shadcn/ui projects that reads a QR code from an image in the browser, with copy and open-link actions.

`QrCodeScanner` is a drop zone that decodes a QR code from an image file, in the browser, and hands you the text. Use it to check in tickets from screenshots, read codes from photos people upload, or verify a code you generated. It reads image files, not a live camera feed.

## Installation [#installation]

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

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

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

## Usage [#usage]

```tsx title="components/example.tsx"
import { QrCodeScanner } from "@/components/qr-code-scanner";
```

```tsx title="components/example.tsx"
<QrCodeScanner onResult={(value) => console.log(value)} />
```

People drop an image or click to pick one. Decoding runs in the browser with qrdx's [detection helpers](https://qrdx.dev/docs/qr-detection), so the image never leaves the device. The result appears with a **Copy** button, plus an **Open link** button when it is an `http` or `https` URL.

## Examples [#examples]

### Checking a result [#checking-a-result]

`onResult` receives the decoded text, so you can act on it, for example to check in a ticket. `label` changes the heading in the drop zone. Download the sample code above and drop it in to see a valid ticket.

## What the reader shows [#what-the-reader-shows]

| State | Message |
| --- | --- |
| Scanning | "Scanning…" |
| No code in the image | "No QR code found. Try a sharper or closer image." |
| Not an image file | "Choose an image file." |
| The image cannot be read | "Could not read that image." |
| Found | The decoded text, with **Copy** and, for links, **Open link** |

The decoder tries the whole image and four crops, at several scales, so a code that fills a small part of a screenshot is still found.

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

- The drop zone is a `<label>` for a visually hidden file input, so it works with the keyboard and with screen readers like any file picker.
- Results and errors are announced through a polite live region.
- **Open link** opens in a new tab with `rel="noopener noreferrer nofollow"`, so a scanned page cannot reach yours.
- The component is a Client Component. It needs the browser's canvas and, on the first scan, loads the decoder on demand.

## API reference [#api-reference]

### $Fumadocs

| Prop        | Type       | Description                                                             |
| ----------- | ---------- | ----------------------------------------------------------------------- |
| `onResult?` | `function` | Called with the decoded text when a QR code is found.                   |
| `label?`    | `string`   | Heading inside the drop zone. Default: `"Scan a QR code from an image"` |

Any other prop, such as `className`, is passed to the wrapping `<div>`.

## Related [#related]

- [QR detection](https://qrdx.dev/docs/qr-detection): The library functions the scanner calls, for your own reader.
- [QR Code](https://qrdx.dev/docs/components/qr-code): Generate the codes the scanner reads.
- [Frames, scan score and print files](https://qrdx.dev/docs/features/frames): Score a code image with getImageScanScore instead of only decoding it.
