Facets

Collapsible groups of checkboxes with counts, to filter a list of results.

Data Added in v0.76.3 Updated

Default

Clear all
Format 1
120
34
18
Language
150
12
Audience
90
40

{component facets,
	clear: '#',
	items: [
		['title' => 'Format', 'name' => 'format', 'options' => [
			['title' => 'Book', 'value' => 'book', 'count' => 120, 'checked' => true],
			['title' => 'Audiobook', 'value' => 'audio', 'count' => 34],
			['title' => 'DVD', 'value' => 'dvd', 'count' => 18],
		]],
		['title' => 'Language', 'name' => 'language', 'options' => [
			['title' => 'English', 'value' => 'en', 'count' => 150],
			['title' => 'Spanish', 'value' => 'es', 'count' => 12],
		]],
		['title' => 'Audience', 'name' => 'audience', 'open' => true, 'options' => [
			['title' => 'Adult', 'value' => 'adult', 'count' => 90],
			['title' => 'Teen', 'value' => 'teen', 'count' => 40],
		]],
	],
/}

items are the groups. Each has a title, a name, so its checkboxes submit as name[], and options with a title, value, count and checked. A group with a checked option opens itself and shows how many are checked, and open opens one at first. clear is the URL that removes every filter, and its Clear all link shows only while something is checked. Put the component inside the form that filters. For results as people tick, give attrs the hx-get, hx-trigger: change and hx-target of any form.

Long groups

Genre
80
41
37
See 2 more
25
19

{component facets,
	limit: 3,
	more: 'See {count} more',
	items: [
		['title' => 'Genre', 'name' => 'genre', 'open' => true, 'options' => [
			['title' => 'Fiction', 'value' => 'fiction', 'count' => 80],
			['title' => 'Mystery', 'value' => 'mystery', 'count' => 41],
			['title' => 'Romance', 'value' => 'romance', 'count' => 37],
			['title' => 'Science fiction', 'value' => 'scifi', 'count' => 25],
			['title' => 'Biography', 'value' => 'biography', 'count' => 19],
		]],
	],
/}

A group shows limit options (8 by default) and holds the rest in a Show more section, a native details with no script. more is its text, with {count} replaced by how many it holds.