Facet
editFacet
editShow a Facet filter for a particular field.
Must configure the corresponding field in the SearchProvider
facets object.
Example
editimport { Facet } from "@elastic/react-search-ui"; import { MultiCheckboxFacet } from "@elastic/react-search-ui-views"; ... <SearchProvider config={{ ...otherConfig, searchQuery: { facets: { states: { type: "value", size: 30 } } } }}> {() => ( <Facet field="states" label="States" view={MultiCheckboxFacet} /> )} </SearchProvider>
Example of an OR based Facet filter
editCertain configuration of the Facet
Component will require a "disjunctive" facet to work
correctly. "Disjunctive" facets are facets that do not change when a selection is made. Meaning, all available options
will remain as selectable options even after a selection is made.
import { Facet } from "@elastic/react-search-ui"; import { MultiCheckboxFacet } from "@elastic/react-search-ui-views"; ... <SearchProvider config={{ ...otherConfig, searchQuery: { disjunctiveFacets: ["states"], facets: { states: { type: "value", size: 30 } } } }}> {() => ( <Facet field="states" label="States" view={MultiCheckboxFacet} filterType="any" /> )} </SearchProvider>
Properties
editName | Description |
---|---|
className |
|
field |
Field name corresponding to this filter. This requires that the corresponding field has been configured in |
filterType |
The type of filter to apply with the selected values. I.e., should "all" of the values match, or just "any" of the values, or "none" of the values. Note: See the example above which describes using "disjunctive" facets in conjunction with filterType. |
label |
A static label to show in the facet filter. |
show |
The number of facet filter options to show before concatenating with a "Show more" link. |
isFilterable |
Whether or not to show Facet quick filter. |
view |
Used to override the default view for this Component. See View customization below. |
* |
Any other property passed will be passed through and available to use in a Custom View |
View customization
editA complete guide to view customization can be found in the Customization: Component views and HTML section.
The following properties are available in the view:
Name | Description |
---|---|
className |
Passed through from main component. |
label |
Type: |
onMoreClick |
Type: |
onRemove |
Type: |
onChange |
Type: |
onSelect |
Type: |
options |
Type: |
showMore |
Type: |
values |
Type: |
showSearch |
Type: |
onSearch |
Type: |
searchPlaceholder |
Type: |
See MultiCheckboxFacet.tsx for an example.
When overriding Facet views, note that there are pre-built options that you can choose from, in addition to providing your own:
import { BooleanFacet, SingleSelectFacet, SingleLinksFacet } from "@elastic/react-search-ui-views"; // Default out-of-the-box view <Facet field="acres" label="Acres" /> // Choose an alternate out-of-the-box view <Facet field="acres" label="Acres" view={SingleSelectFacet} />