Data displayListingResults
Searchastronomic.dev# ListingResults
For a search page: the results list, paged, that follows your filters and works as a plain list with no script.
Interactive: inline script.
## Usage
```astro
import ListingResults from "@astronomic/ui-pro/components/ListingResults.astro";
```
## Examples
### Homes in Denver
FilterBar, ResultsHead and ListingResults over the demo listings. Pick a filter: the list, the count and the address follow. Pick Condo: no condo is for sale, so the empty state shows the nearest homes, without that filter.
```astro
---
import FilterBar from "@astronomic-dev/ui/components/FilterBar.astro";
import ResultsHead from "@astronomic-dev/ui/components/ResultsHead.astro";
import ListingResults from "@astronomic/ui-pro/components/ListingResults.astro";
import { defaults, fields, modes, sorts } from "../_data/vega.ts";
import { exampleIndex, firstPage } from "../_data/search.ts";
const listings = firstPage("buy");
---
<div class="grid grid-cols-[minmax(0,1fr)] gap-blocks">
<FilterBar id="search-main-filters" label="Filter homes" fields={fields} modes={modes} modesLabel="Buy or rent" sorts={sorts} defaults={defaults} textLabel="Where" textPlaceholder="Street or neighborhood" />
<ResultsHead heading="Homes in Denver" headingId="search-main-heading" count={listings.length} countText={{ one: "home", other: "homes" }} sorts={sorts} filtersId="search-main-filters" />
<ListingResults
filtersId="search-main-filters"
headingId="search-main-heading"
source={{ index: exampleIndex }}
fields={fields}
listings={listings}
page={1}
pages={1}
pageHref={() => "?"}
mode="buy"
imageSizes="(min-width: 64rem) 33vw, (min-width: 42rem) 50vw, 100vw"
/>
</div>
```
### Rows
card is row: ListingRow in one column, here for rentals (defaults.mode is rent).
```astro
---
import FilterBar from "@astronomic-dev/ui/components/FilterBar.astro";
import ResultsHead from "@astronomic-dev/ui/components/ResultsHead.astro";
import ListingResults from "@astronomic/ui-pro/components/ListingResults.astro";
import { defaults, fields, modes, sorts } from "../_data/vega.ts";
import { exampleIndex, firstPage } from "../_data/search.ts";
const rentDefaults = { ...defaults, mode: "rent" };
const listings = firstPage("rent");
---
<div class="grid grid-cols-[minmax(0,1fr)] gap-blocks">
<FilterBar id="search-row-filters" label="Filter rentals" fields={fields} modes={modes} modesLabel="Buy or rent" sorts={sorts} defaults={rentDefaults} textLabel="Where" textPlaceholder="Street or neighborhood" />
<ResultsHead heading="Homes for rent in Denver" headingId="search-row-heading" count={listings.length} countText={{ one: "home", other: "homes" }} sorts={sorts} filtersId="search-row-filters" />
<ListingResults
filtersId="search-row-filters"
headingId="search-row-heading"
source={{ index: exampleIndex }}
fields={fields}
listings={listings}
page={1}
pages={1}
pageHref={() => "?"}
mode="rent"
card="row"
imageSizes="(min-width: 36rem) 20rem, 100vw"
/>
</div>
```
### Nothing matches
Every listing here is a rental, and the search starts on homes for sale: the empty state. Clear filters shows once a filter or a text is set. Pick Rent to see the rentals.
```astro
---
import FilterBar from "@astronomic-dev/ui/components/FilterBar.astro";
import ResultsHead from "@astronomic-dev/ui/components/ResultsHead.astro";
import ListingResults from "@astronomic/ui-pro/components/ListingResults.astro";
import { defaults, fields, modes, sorts } from "../_data/vega.ts";
import { inlineIndex, records } from "../_data/search.ts";
// Only the rentals are listed, and the search starts on homes for sale: nothing matches. Pick Rent to see them.
const index = inlineIndex(records.filter((r) => r.mode === "rent"));
---
<div class="grid grid-cols-[minmax(0,1fr)] gap-blocks">
<FilterBar id="search-empty-filters" label="Filter homes" fields={fields} modes={modes} modesLabel="Buy or rent" sorts={sorts} defaults={defaults} textLabel="Where" textPlaceholder="Street or neighborhood" />
<ResultsHead heading="Homes in Denver" headingId="search-empty-heading" countText={{ one: "home", other: "homes" }} sorts={sorts} filtersId="search-empty-filters" />
<ListingResults
filtersId="search-empty-filters"
headingId="search-empty-heading"
source={{ index }}
fields={fields}
listings={[]}
page={1}
pages={1}
pageHref={() => "?"}
emptyTitle="No homes for sale match yet."
/>
</div>
```
## Props
### ListingResults
| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `filtersId` | `string` | None | The id of the Filters (or FilterBar) form the list follows. |
| `headingId` | `string` | None | The id of the heading that names the list: give ResultsHead the same headingId. The search writes that ResultsHead's count. |
| `source` | `{ index: string } \| { endpoint: string }` | None | Where the search reads: the JSON index (searchIndex() from @astronomic/ui-pro/lib/listing-record.ts, fetched once and searched in the browser), or a server endpoint asked once per search (GET with the filters' query, the page and the size; it answers { total, records }). |
| `fields` | `ListingField[]` | None | Your fields list (@astronomic-dev/ui/lib/listing.ts), as passed to Filters: the cards' facts. |
| `listings` | `ListingCardData[]` | None | The first page, rendered on the server: the list with no script, and the first paint. |
| `page` | `number` | None | The server list's page, from 1. |
| `pages` | `number` | None | The server list's page count. |
| `pageHref` | `(n: number) => string` | None | Each page's path, as Pagination takes it ("/search/page/2/"). Give Filters the same pageHref and pages, so a page is in the address bar. |
| `pageSize` | `number` | `24` | Cards per page, the server's and the search's. |
| `mode` | `string` | None | The mode the server cards show ("buy"). A search's cards follow the search's mode. |
| `card` | `"inset" \| "row"` | `"inset"` | The card recipe: ListingCardInset in as many columns as fit at 18.75rem or more each, or ListingRow in one column. |
| `itemHeadingTag` | `"h2" \| "h3" \| "h4"` | `"h3"` | Each card's title element. |
| `imageSizes` | `string` | None | The photos' sizes attribute, for each record's srcset. |
| `save` | `boolean` | `true` | Shows each card's Save button. |
| `saveList` | `string` | None | The Save buttons' list ("homes" by default). |
| `emptyTitle` | `string` | `"Nothing matches all of that yet."` | The empty state's title. |
| `emptyText` | `string` | `"These are the nearest matches, with one filter less."` | The note over the nearest results: the same search without its last filter (or its text). Hidden when there are none. |
| `clearText` | `string` | `"Clear filters"` | The empty state's button: it clears the text and every filter, as the filters' own Clear. Hidden when none is set. |
| `failedText` | `string` | `"Search is not available right now. Every listing is shown below."` | The note when the search cannot run. The server list stays. |
| `listClass` | `string` | None | For recipes. Classes for the list, merged with cn(). |
| `itemClass` | `string` | None | For recipes. Classes for each list item, the server's and the search's. |
| `class` | `string` | None | More classes for the <section>, merged with cn(), so yours win on conflicts. |
Any other attribute goes on the <section>. After each search it fires search:results on the section with { records, shown, total, page, pages, points, state, source }: the page's records, what the list holds (the nearest results when nothing matched), every match's pins, and what started the search. When a failed search puts the server's cards back it fires search:restored on the section.
## Accessibility
| Key | Action |
| --- | --- |
| Tab | Moves through each card's title link and Save button, then the pager's links |
| Enter on a pager link | Shows that page of the same search and moves focus to the results heading |
| Enter or Space on Clear filters | Clears the text and every filter and moves focus to the first filter |
- The list is a section named by the results heading, with a role=list list of cards. With no script, the server's list and its pager (real links) work.
- While a search runs the list is aria-busy and keeps its cards; a card that stays keeps its place and its focus.
- The visible count in ResultsHead is written on every search. Its status line, read by screen readers, is written only after a reader's own change or Back and Forward, so a page load says nothing.
- A pager link sets the page through the filters (the address bar follows), and focus moves to the results heading.
- When nothing matches, a short note and Clear filters show; Clear filters moves focus to the first filter. If the search cannot run, the note shows, the server list stays, and the status line says it once.
ListingResults
ProFor a search page: the results list, paged, that follows your filters and works as a plain list with no script.
- File
- ListingResults.astro
- Group
- Data display
- Kind
- Interactive: inline script
- Examples
- 3
Examples
Drag the orange handle to set the width. Frames get real breakpoints.
- Static
- Interactive
- Framed
Homes in Denver
FilterBar, ResultsHead and ListingResults over the demo listings. Pick a filter: the list, the count and the address follow. Pick Condo: no condo is for sale, so the empty state shows the nearest homes, without that filter.
This preview did not load.
examples/listingresults/main.astro
---
import FilterBar from "@astronomic-dev/ui/components/FilterBar.astro";
import ResultsHead from "@astronomic-dev/ui/components/ResultsHead.astro";
import ListingResults from "@astronomic/ui-pro/components/ListingResults.astro";
import { defaults, fields, modes, sorts } from "../_data/vega.ts";
import { exampleIndex, firstPage } from "../_data/search.ts";
const listings = firstPage("buy");
---
<div class="grid grid-cols-[minmax(0,1fr)] gap-blocks">
<FilterBar id="search-main-filters" label="Filter homes" fields={fields} modes={modes} modesLabel="Buy or rent" sorts={sorts} defaults={defaults} textLabel="Where" textPlaceholder="Street or neighborhood" />
<ResultsHead heading="Homes in Denver" headingId="search-main-heading" count={listings.length} countText={{ one: "home", other: "homes" }} sorts={sorts} filtersId="search-main-filters" />
<ListingResults
filtersId="search-main-filters"
headingId="search-main-heading"
source={{ index: exampleIndex }}
fields={fields}
listings={listings}
page={1}
pages={1}
pageHref={() => "?"}
mode="buy"
imageSizes="(min-width: 64rem) 33vw, (min-width: 42rem) 50vw, 100vw"
/>
</div>Rows
card is row: ListingRow in one column, here for rentals (defaults.mode is rent).
This preview did not load.
examples/listingresults/row.astro
---
import FilterBar from "@astronomic-dev/ui/components/FilterBar.astro";
import ResultsHead from "@astronomic-dev/ui/components/ResultsHead.astro";
import ListingResults from "@astronomic/ui-pro/components/ListingResults.astro";
import { defaults, fields, modes, sorts } from "../_data/vega.ts";
import { exampleIndex, firstPage } from "../_data/search.ts";
const rentDefaults = { ...defaults, mode: "rent" };
const listings = firstPage("rent");
---
<div class="grid grid-cols-[minmax(0,1fr)] gap-blocks">
<FilterBar id="search-row-filters" label="Filter rentals" fields={fields} modes={modes} modesLabel="Buy or rent" sorts={sorts} defaults={rentDefaults} textLabel="Where" textPlaceholder="Street or neighborhood" />
<ResultsHead heading="Homes for rent in Denver" headingId="search-row-heading" count={listings.length} countText={{ one: "home", other: "homes" }} sorts={sorts} filtersId="search-row-filters" />
<ListingResults
filtersId="search-row-filters"
headingId="search-row-heading"
source={{ index: exampleIndex }}
fields={fields}
listings={listings}
page={1}
pages={1}
pageHref={() => "?"}
mode="rent"
card="row"
imageSizes="(min-width: 36rem) 20rem, 100vw"
/>
</div>Nothing matches
Every listing here is a rental, and the search starts on homes for sale: the empty state. Clear filters shows once a filter or a text is set. Pick Rent to see the rentals.
This preview did not load.
examples/listingresults/empty.astro
---
import FilterBar from "@astronomic-dev/ui/components/FilterBar.astro";
import ResultsHead from "@astronomic-dev/ui/components/ResultsHead.astro";
import ListingResults from "@astronomic/ui-pro/components/ListingResults.astro";
import { defaults, fields, modes, sorts } from "../_data/vega.ts";
import { inlineIndex, records } from "../_data/search.ts";
// Only the rentals are listed, and the search starts on homes for sale: nothing matches. Pick Rent to see them.
const index = inlineIndex(records.filter((r) => r.mode === "rent"));
---
<div class="grid grid-cols-[minmax(0,1fr)] gap-blocks">
<FilterBar id="search-empty-filters" label="Filter homes" fields={fields} modes={modes} modesLabel="Buy or rent" sorts={sorts} defaults={defaults} textLabel="Where" textPlaceholder="Street or neighborhood" />
<ResultsHead heading="Homes in Denver" headingId="search-empty-heading" countText={{ one: "home", other: "homes" }} sorts={sorts} filtersId="search-empty-filters" />
<ListingResults
filtersId="search-empty-filters"
headingId="search-empty-heading"
source={{ index }}
fields={fields}
listings={[]}
page={1}
pages={1}
pageHref={() => "?"}
emptyTitle="No homes for sale match yet."
/>
</div>