# Product Filters

> Faceted filters for a collection page, with chips, sort and load more. Handles zero results, slow counts, long value lists and price ranges in any currency.

Canonical: https://hextaui.com/blocks/product-filters
Last updated: 2026-10-29

## Overview

Product Filters is the left side and the top of a collection page: a sidebar of facets, the applied filters as chips, a toolbar with the count, sort and grid size, and a Load more button with progress. On phones the same facets open in a bottom sheet. Facets are plain data, { id, label, type, values }, with list, swatch, range, boolean and rating types, so they map from Shopify, Algolia, Meilisearch or your own database.

On desktop every change applies at once and a polite live region says “12 results”. Each value shows its count, and values with no matches stay visible but disabled, so shoppers never pick their way into an empty grid. Long lists show six values and “Show 3 more”, and lists of 15 or more get a search field. Price is a two-thumb slider over a histogram plus two inputs with the currency symbol. The slider applies when you let go and the inputs on blur or Enter, so typing is never interrupted.

In the mobile sheet, changes are staged. The button reads “Show 24 results” and updates as you toggle, from onCount, which may be async. Stale answers are dropped, and the button turns into “No results” when nothing matches. Closing the sheet without applying throws the changes away.

Every applied value becomes a chip, such as Oat or $40–$120. Removing one moves focus to the next chip, and removing the last one moves it to a target you choose. On phones the chips scroll sideways, with a count and a faded edge. When nothing matches, FilterEmpty explains why and lists the chips to remove. The pure helpers, applyFilters, computeFacetCounts and the search param pair, work on the server too.

## Installation

### Step 1: Get HextaUI Pro

One payment unlocks every block, including future ones. [See pricing](https://hextaui.com/pricing).

### Step 2: Add the Pro registry to components.json

```json title="components.json"
{
  "registries": {
    "@hextaui-pro": {
      "url": "https://hextaui.com/r/pro/{name}.json",
      "headers": {
        "Authorization": "Bearer ${HEXTAUI_PRO_TOKEN}"
      }
    }
  }
}
```

### Step 3: Add your token

Create a token on your [account page](https://hextaui.com/account) and put it in `.env.local` as `HEXTAUI_PRO_TOKEN`.

### Step 4: Add the block

```bash
npx shadcn@latest add @hextaui-pro/product-filters
```

## Usage

### From Shopify’s productFilters

Map the Storefront API’s collection.products.filters to facets once. Each value keeps its input JSON, so toProductFilters turns the shopper’s selection straight back into the filters argument for the next query, price range and availability included.

```tsx
"use client"

import type { Facet, FilterState } from "@/components/blocks/product-filters/facets"
import { ProductFilters } from "@/components/blocks/product-filters/product-filters"

type StorefrontFilterValue = {
  id: string
  label: string
  count: number
  input: string
  swatch?: { color?: string | null; image?: { previewImage?: { url: string } | null } | null } | null
}

type StorefrontFilter = {
  id: string
  label: string
  type: "LIST" | "PRICE_RANGE" | "BOOLEAN"
  presentation?: "TEXT" | "SWATCH" | "IMAGE" | null
  values: StorefrontFilterValue[]
}

type ProductFilterInput = Record<string, unknown>

export function toFacets(filters: StorefrontFilter[], currencyCode: string): Facet[] {
  return filters.map((filter): Facet => {
    if (filter.type === "PRICE_RANGE") {
      const range = JSON.parse(filter.values[0]?.input ?? "{}") as {
        price?: { min?: number; max?: number }
      }
      return {
        id: filter.id,
        label: filter.label,
        type: "range",
        min: Math.floor(range.price?.min ?? 0),
        max: Math.ceil(range.price?.max ?? 0),
        step: 5,
        currencyCode,
      }
    }
    if (filter.type === "BOOLEAN") {
      const yes = filter.values.find((value) => value.input.includes("true"))
      return { id: filter.id, label: filter.label, type: "boolean", count: yes?.count }
    }
    return {
      id: filter.id,
      label: filter.label,
      type: filter.presentation === "SWATCH" ? "swatch" : "list",
      values: filter.values.map((value) => ({
        value: value.input,
        label: value.label,
        count: value.count,
        swatch: value.swatch
          ? {
              color: value.swatch.color ?? undefined,
              image: value.swatch.image?.previewImage?.url,
            }
          : undefined,
      })),
    }
  })
}

export function toProductFilters(
  filters: StorefrontFilter[],
  state: FilterState
): ProductFilterInput[] {
  return filters.flatMap((filter): ProductFilterInput[] => {
    const value = state[filter.id]
    if (value === undefined) return []
    if (filter.type === "PRICE_RANGE" && Array.isArray(value)) {
      return [{ price: { min: Number(value[0]), max: Number(value[1]) } }]
    }
    if (filter.type === "BOOLEAN" && value === true) {
      const yes = filter.values.find((item) => item.input.includes("true"))
      return yes ? [JSON.parse(yes.input) as ProductFilterInput] : []
    }
    return Array.isArray(value)
      ? value.map((input) => JSON.parse(String(input)) as ProductFilterInput)
      : []
  })
}

export function CollectionFilters({
  filters,
  value,
  total,
  onFilter,
}: {
  filters: StorefrontFilter[]
  value: FilterState
  total: number
  onFilter: (input: ProductFilterInput[], state: FilterState) => void
}) {
  return (
    <ProductFilters
      facets={toFacets(filters, "USD")}
      value={value}
      resultCount={total}
      onValueChange={(next) => onFilter(toProductFilters(filters, next), next)}
    />
  )
}
```

### From Algolia or Meilisearch

Build facets from facetDistribution and facetStats, and send the selection back as filter expressions. On mobile, onCount runs a limit: 0 search so the sheet’s button reads Show 128 results before anything is applied.

```tsx
"use client"

import type { Facet, FilterState } from "@/components/blocks/product-filters/facets"
import { FilterSheet } from "@/components/blocks/product-filters/filter-sheet"
import { ProductFilters } from "@/components/blocks/product-filters/product-filters"

type FacetDistribution = Record<string, Record<string, number>>

type SearchResponse = {
  estimatedTotalHits: number
  facetDistribution: FacetDistribution
  facetStats?: Record<string, { min: number; max: number }>
}

type SearchClient = {
  search: (query: string, options: { filter: string[]; facets: string[]; limit: number }) => Promise<SearchResponse>
}

const facetIds = ["category", "color", "price", "in_stock"]

const quote = (value: string) => `"${value.replace(/"/g, '\\"')}"`

export function toFilterExpressions(state: FilterState) {
  return Object.entries(state).map(([id, value]) => {
    if (value === true) return `${id} = true`
    if (Array.isArray(value) && typeof value[0] === "number") {
      return `${id} ${value[0]} TO ${value[1]}`
    }
    return (value as string[]).map((item) => `${id} = ${quote(item)}`).join(" OR ")
  })
}

export function toFacets(response: SearchResponse): Facet[] {
  const list = (id: string, label: string, type: "list" | "swatch"): Facet => ({
    id,
    label,
    type,
    values: Object.entries(response.facetDistribution[id] ?? {}).map(
      ([value, count]) => ({ value, label: value, count })
    ),
  })
  const price = response.facetStats?.price
  return [
    { id: "in_stock", label: "In stock only", type: "boolean", count: response.facetDistribution.in_stock?.true ?? 0 },
    list("category", "Category", "list"),
    { id: "price", label: "Price", type: "range", min: Math.floor(price?.min ?? 0), max: Math.ceil(price?.max ?? 0), step: 5, currencyCode: "USD" },
    list("color", "Color", "swatch"),
  ]
}

export function SearchFilters({
  client,
  response,
  value,
  onValueChange,
}: {
  client: SearchClient
  response: SearchResponse
  value: FilterState
  onValueChange: (state: FilterState) => void
}) {
  const facets = toFacets(response)
  const count = async (draft: FilterState) => {
    const result = await client.search("", {
      filter: toFilterExpressions(draft),
      facets: facetIds,
      limit: 0,
    })
    return result.estimatedTotalHits
  }

  return (
    <>
      <ProductFilters
        className="max-md:hidden"
        facets={facets}
        value={value}
        onValueChange={onValueChange}
        resultCount={response.estimatedTotalHits}
      />
      <div className="md:hidden">
        <FilterSheet
          facets={facets}
          value={value}
          onValueChange={onValueChange}
          resultCount={response.estimatedTotalHits}
          onCount={count}
        />
      </div>
    </>
  )
}
```

### Filters in the URL with Next.js

filtersToSearchParams and filtersFromSearchParams read and write ?color=Oat&price=40-120&page=2 with router.replace, so links can be shared and Back works. Keeping the page in the URL lets the browser restore the scroll position after a product page, because pages 1 to 2 render again.

```tsx
"use client"

import type { ReactNode } from "react"
import { usePathname, useRouter, useSearchParams } from "next/navigation"

import { ActiveFilters } from "@/components/blocks/product-filters/active-filters"
import {
  filtersFromSearchParams,
  filtersToSearchParams,
  type Facet,
  type FilterState,
} from "@/components/blocks/product-filters/facets"
import { LoadMore } from "@/components/blocks/product-filters/load-more"
import { ProductFilters } from "@/components/blocks/product-filters/product-filters"

const pageSize = 24

export function UrlFilters({
  facets,
  total,
  children,
}: {
  facets: Facet[]
  total: number
  children: (state: FilterState, shown: number) => ReactNode
}) {
  const router = useRouter()
  const pathname = usePathname()
  const searchParams = useSearchParams()
  const filters = filtersFromSearchParams(facets, searchParams)
  const page = Math.max(1, Number(searchParams.get("page")) || 1)

  const navigate = (next: FilterState, nextPage = 1) => {
    const params = filtersToSearchParams(facets, next, new URLSearchParams(searchParams))
    if (nextPage > 1) params.set("page", String(nextPage))
    else params.delete("page")
    router.replace(`${pathname}?${params}`, { scroll: false })
  }

  return (
    <div className="grid gap-10 md:grid-cols-[15rem_minmax(0,1fr)]">
      <ProductFilters facets={facets} value={filters} onValueChange={navigate} resultCount={total} />
      <div className="flex flex-col gap-5">
        <ActiveFilters facets={facets} value={filters} onValueChange={navigate} />
        {children(filters, Math.min(total, page * pageSize))}
        <LoadMore
          shown={page * pageSize}
          total={total}
          pageSize={pageSize}
          onLoadMore={() => navigate(filters, page + 1)}
        />
      </div>
    </div>
  )
}
```

## Anatomy

The parts you compose, from the outside in.

| Part | Description |
| --- | --- |
| `ProductFilters` | The desktop sidebar: collapsible facet groups that apply live. |
| `FilterSheet` | A bottom sheet with the same facets, staged changes and a Show results footer. |
| `ActiveFilters` | Removable chips for every applied value, with Clear all. |
| `ListingToolbar` | The result count, the sort select, grid size and a slot for the mobile Filters button. |
| `LoadMore` | Showing 24 of 128, a progress bar and Load more, with loading and retry states. |
| `FilterEmpty` | The no-results state, with the chips to remove and Clear all. |
| `applyFilters, computeFacetCounts` | Filter items and recount every facet against the other facets. |
| `filtersToSearchParams, filtersFromSearchParams` | Read and write the filters as URL search params, dropping unknown values. |

## API reference

### ProductFilters

Also takes div props.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `facets` | `Facet[]` | – | The facets in display order, with current counts. |
| `value` | `FilterState` | – | The applied filters, such as { color: ["Oat"], price: [40, 120], in_stock: true }. |
| `defaultValue` | `FilterState` | – | The starting filters when uncontrolled. |
| `onValueChange` | `(state: FilterState) => void` | – | Called on every change, already normalized. |
| `resultCount` | `number` | – | The number of results. Each change is announced to screen readers. Pass undefined while loading. |
| `defaultOpen` | `string[]` | – | Facet ids that start expanded. Facets with an applied value always start expanded. All facets are expanded by default. |
| `visibleValues` | `number` | `6` | Values shown before Show more in list facets. |
| `swatchVisibleValues` | `number` | `12` | Swatches shown before Show more. |
| `searchThreshold` | `number` | `15` | List facets with this many values or more get a search field. |
| `title` | `ReactNode \| null` | – | The heading. null hides the header and Clear all. |
| `locale` | `Intl.LocalesArgument` | `"en-US"` | Locale for prices and numbers. |
| `labels` | `Partial<ProductFiltersLabels>` | – | Words for Show more, search, ratings, counts and announcements. |

### FilterSheet

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `facets` | `Facet[]` | – | The facets with counts for the applied filters. |
| `getFacets` | `(draft: FilterState) => Facet[]` | – | Recount facets for the staged filters while the sheet is open. |
| `value` | `FilterState` | – | The applied filters. The sheet starts from these each time it opens. |
| `onValueChange` | `(state: FilterState) => void` | – | Called once, when the shopper taps Show results. |
| `resultCount` | `number` | – | The count for the applied filters. |
| `onCount` | `(draft: FilterState) => number \| Promise<number>` | – | The count for the staged filters. Throw to fall back to Show results. |
| `open` | `boolean` | – | Controlled open state, with onOpenChange and defaultOpen. |
| `trigger` | `ReactElement` | `<Button variant="outline" />` | The element that renders the Filters trigger. It shows the applied count. |
| `labels` | `Partial<FilterSheetLabels>` | – | Words for the trigger, title, Clear and the Show results button. |

### ActiveFilters

Also takes div props.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `facets` | `Facet[]` | – | The facets, used to label each chip. |
| `value` | `FilterState` | – | The applied filters. |
| `onValueChange` | `(state: FilterState) => void` | – | Called with the filters after a chip is removed or Clear all. |
| `layout` | `"bar" \| "wrap"` | `"bar"` | A bar scrolls sideways on phones and wraps on desktop. wrap always wraps and centers. |
| `clearAll` | `boolean` | `true` | Show the Clear all button. |
| `fallbackFocusRef` | `RefObject<HTMLElement>` | – | Where focus goes after the last chip is removed. Defaults to the next focusable element. |
| `labels` | `Partial<ActiveFiltersLabels>` | – | Words for chips, removal and announcements. |

### ListingToolbar

Also takes div props.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `count` | `number` | – | The total number of results. |
| `sort` | `string` | – | The selected sort value, with onSortChange. |
| `sortOptions` | `{ value; label }[]` | – | Defaults to Featured, Best selling, Newest, both price orders and Top rated. |
| `density` | `"comfortable" \| "compact"` | – | The grid size, with onDensityChange. |
| `densities` | `DensityOption[] \| null` | – | The grid size options. null hides the toggle. |
| `filters` | `ReactNode` | – | Shown below the md breakpoint, usually a FilterSheet. |

### LoadMore

Also takes div props.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `shown` | `number` | – | How many products are on the page. |
| `total` | `number` | – | How many match. |
| `pageSize` | `number` | – | Shown in the button as Load 12 more. When everything fits on one page, LoadMore renders nothing. |
| `onLoadMore` | `() => void \| Promise<unknown>` | – | Load the next page. Throw to show the message and a Retry button. |
| `loading` | `boolean` | – | Control the loading state yourself. |
| `labels` | `Partial<LoadMoreLabels>` | – | Words for progress, loading, errors and the end of the list. |

### Facet

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `id` | `string` | – | The key in FilterState and the URL. |
| `label` | `string` | – | The group heading, such as Color. |
| `type` | `"list" \| "swatch" \| "range" \| "boolean" \| "rating"` | – | How the facet is shown and matched. |
| `values` | `{ value; label; count; swatch?: { color?; image? } }[]` | – | For list, swatch and rating facets. A rating value of "4" means 4 stars and up. |
| `min, max, step` | `number` | – | Bounds and step for range facets. |
| `currencyCode` | `string` | – | Formats a range as money, such as $40–$120. |
| `unit` | `string` | – | A unit for other ranges, such as cm. |
| `count` | `number` | – | Matches for a boolean facet. |
| `histogram` | `number[]` | – | Bucket counts drawn above the price slider. computeFacetCounts fills it. |

## Keyboard

| Key | Action |
| --- | --- |
| `Tab` | Moves through facet headings, values, chips and the toolbar. |
| `Enter` `Space` | Expands or collapses a facet group, or toggles a value. |
| `ArrowLeft` `ArrowRight` | Moves a price thumb by one step, or moves between rating options. |
| `Enter` | Applies a typed minimum or maximum price. |
| `Escape` | Clears a facet search, or closes the filter sheet without applying it. |
| `Backspace` `Delete` | Removes the focused chip. |

## Accessibility

- Each facet heading is a button with its expanded state. Values are checkboxes, radios or a switch named by their label and count, such as “Oat, 12 products”. Disabled values stay visible.
- A polite live region announces the new result count after each change on desktop, and the sheet announces its count as you toggle. Load more announces how many products are shown, and its errors use role="alert".
- Removing a chip moves focus to the next chip. Removing the last one, or clearing the empty state, moves focus to the target you pass instead of dropping it on the page.
- Swatches show a ring and a check mark when selected, not just a color, and use system outlines in forced colors mode. With reduced motion, the expanding groups, histogram and image hover don’t animate.

## Built with

The free HextaUI components Product Filters is made from. Each one installs on its own.

- [Badge](https://hextaui.com/docs/badge) - Status labels with colored dots, removable tags that slide closed and counts that roll to their new value.
- [Button](https://hextaui.com/docs/button) - Buttons in every variant and size, with a built-in loading, success and error flow that skips the spinner for fast requests.
- [Checkbox](https://hextaui.com/docs/checkbox) - A checkbox whose check draws in, with indeterminate parents, groups and labels that share its hover.
- [Collapsible](https://hextaui.com/docs/collapsible) - A panel that shows and hides with height motion you can reverse mid-way, without jumping the layout.
- [Empty](https://hextaui.com/docs/empty) - A placeholder for screens with nothing to show yet, with an icon, a message and the next action.
- [Input group](https://hextaui.com/docs/input-group) - An input with icons, text, buttons or a keyboard hint attached, sharing one border and focus ring.
- [Number flow](https://hextaui.com/docs/number-flow) - Animated numbers where only the changed digits spin, with any Intl format and locale.
- [Progress](https://hextaui.com/docs/progress) - A bar or ring that shows how far a task has come, eases between updates and slides while the total is unknown.
- [Radio group](https://hextaui.com/docs/radio-group) - Pick one option from a set, with a dot that hands off between choices and cards whose selection ring slides to the new pick.
- [Select](https://hextaui.com/docs/select) - Pick one or more options from a list that opens on the current value, with typeahead, groups and form support.
- [Sheet](https://hextaui.com/docs/sheet) - A panel that slides in from any edge, with swipe-to-dismiss, scroll lock and stacked nesting.
- [Slider](https://hextaui.com/docs/slider) - Pick a value or a range by dragging, tapping the track or using the keys, with jumps that glide and an optional value bubble.
- [Switch](https://hextaui.com/docs/switch) - An on/off toggle you can tap, press or drag, with a thumb that stretches under your finger and an optional pending state for saves.
- [Toggle group](https://hextaui.com/docs/toggle-group) - A row of toggles for one choice or many, with a fill that slides to the picked item, joined or spaced items and arrow-key focus.

## Code

11 files, added to components/blocks/product-filters.
