Facet List
One facet of a filter sidebar: an attribute’s values with counts, to include or exclude from a search.
c2-facet-list is one facet of a log or search sidebar, as in Datadog, Sentry and Kibana: an attribute’s values with how many records have each, a checkbox to include a value, Only to make it the only one, and Exclude to filter it out. A sidebar stacks one element per attribute.
Import
import '@c2n/components/facet-list'Usage
Values and selection
values is an array of { value, label, count }, as a property or as JSON in the attribute. include and exclude hold the values picked, as arrays or as ;-separated attributes; an empty selection means no filter. Values are sorted by count, largest first (sort="label" or "none" to change it), and counts are shortened in the page’s language, or formatted by count-format (Intl.NumberFormat options).
Changing the filter
The checkbox includes a value; Only makes it the only value included; Exclude filters it out (it is struck through, and its button includes it again); Clear empties the selection. Each change fires a cancelable filter-change with include and exclude as they are about to become, then updates them; cancel it to keep the facet controlled, for example when the selection lives in the URL.
facet.addEventListener('filter-change', (event) => {
query.set(facet.label, event.detail) // then rerun the search
})Long lists
searchable adds a field that filters the values as you type. max-items shows the first values with a button to show the rest. The title is a disclosure button that collapses the facet (open), firing toggle.
Accessibility
The facet is a group named by its title. Each value’s checkbox is named by its label and count, and says when the value is excluded. The Only and Exclude buttons appear on hover and focus, but they are always in the tab order and named for screen readers (“Only checkout”, “Exclude checkout”).