# Share a listing

Source: https://help.ruuster.com/idx/recipe-share

> The listing page's share screen, from ShareModal, which shares your own listing URL through the device's share sheet or a modal with Copy link, Facebook, WhatsApp and email.

The share button on a listing page shares the page itself: the listing's URL on your own domain.
On phones and computers that offer a share sheet, the button opens it. Everywhere else it opens the
share screen, with the link in a field, a "Copy link" button, and buttons for Facebook, WhatsApp and
email. `ListingDetail` mounts the share screen for you whenever the page has a share link.

## What the visitor sees

<figure class="idx-shot"><img src="/idx-docs/screens/ours/share-modal-1440.png" alt="The share dialog, closed, on a desktop (1440 px wide)" width="1440" height="900" loading="lazy" decoding="async"><figcaption>The share dialog: the link to the home, Copy link, and Facebook, WhatsApp and email.</figcaption></figure>

<figure class="idx-shot"><img src="/idx-docs/screens/ours/share-modal-375.png" alt="The share dialog, closed, on a phone (375 px wide)" width="375" height="812" loading="lazy" decoding="async"><figcaption>The share dialog: the link to the home, Copy link, and Facebook, WhatsApp and email.</figcaption></figure>

The markup is `static/html/share-modal.html` in `@ruuster/idx-recipes`. The [HTML and CSS recipe](https://help.ruuster.com/idx/recipe-html-css) shows how to fill it and which stylesheet and script to load.

## How it opens

Three buttons carry `data-rw-open="share"`: the round share button on the first photo of the photo
grid, the dark "Share" button in the gallery's header from 768 pixels, and the share button that
floats over the gallery on a phone.

1. When the browser offers `navigator.share`, a click opens the device's share sheet with the title
   "A home at 123 Peachtree St NE, Atlanta, GA 30308", a short sentence and the link.
2. When the visitor closes the share sheet, nothing else happens.
3. When the browser has no share sheet, or the share sheet fails for any other reason, the share
   screen opens.

Inside the share screen, a "More ways to share" button opens the device's share sheet on browsers
that have one. Pass `nativeShare={false}` to always open the share screen.

## The share screen

- **The link** sits in a read-only field labelled "Link to this home". A relative URL becomes an
  absolute one on your own domain at the moment the visitor clicks.
- **Copy link** copies it. The button reads "Link copied" for two seconds. When the browser blocks
  the clipboard, the field's text is selected and the button reads "Select the link above and copy
  it."
- **Facebook, WhatsApp and email** open in a new tab: Facebook's share page with the link, WhatsApp
  with "Take a look at this home:" and the link, and a new email with the home as the subject.

The link is always your own listing URL. On the listing page it is the `shareUrl` you pass to
`ListingDetail`, else the canonical URL the API answers in `head.canonical` (your domain and your
detail-page template), else the listing's `href`. Pass `shareUrl={null}` to leave sharing out.

## Use it on your own layout

Mount `ShareModal` once inside the element that carries `data-rw-detail`, and put
`data-rw-open="share"` on any button of yours in that element. The
[gallery page](https://help.ruuster.com/idx/recipe-gallery) shows a full layout.

| Prop | Type | Required | What it does |
|---|---|---|---|
| `listing` | `ListingDetail` or `ListingCard` | Yes | The listing being shared, for the title and the text |
| `url` | `string` | Yes | Your listing URL, absolute or relative to your site |
| `nativeShare` | `boolean` | No | Default `true`: the device's share sheet first. `false` always opens the share screen |

## Rules this screen follows

**MUST**

- Share your own listing URL, the page the visitor is on.

**NEVER**

- Share a link to another site's copy of the listing.
- Add tracking parameters that carry the visitor's details to the link.

## Without React

The static listing page prints the share screen closed, and `ruuster-idx.js` opens it from the same
buttons. The share URL is in `data-rw-share-url` on the dialog. See
[Build without React](https://help.ruuster.com/idx/recipe-html-css) and `static/HOOKS.md`.
