SelectedFacets
- Last Updated: May 5, 2026
- 4 minute read
- MarkLogic Server
- Documentation
The SelectedFacets widget displays colored, labeled tags representing the facet values selected in a search application. The widget can display selections from these FastTrack widgets:
Example configuration
This React application code includes the SelectedFacets widget. The code configures the widget to display current selections from the four types of facet selection widgets.
import { SelectedFacets, useMarkLogicContext } from "ml-fasttrack"
const App = () => {
const context = useMarkLogicContext();
const handleChipClose = (type, facet, value) => {
if (type === 'string') {
context.removeStringFacetConstraint(facet, value)
} else if (type === 'range') {
context.removeRangeFacetConstraint(facet)
}
}
return (
<SelectedFacets
dataConfig={{
stringFacets: context.stringFacetConstraints,
rangeFacets: context.rangeFacetConstraints,
}}
chipConfig={{
closeConfig: { disabled: false },
overrides: {
string: {
style: { color: 'red' },
},
number: {
style: { color: 'green' },
},
date: {
icon: <i className='fas fa-calendar' style={{ marginRight: 3 }}></i>,
style: { color: 'blue' },
},
},
}}
separatorConfig={{
betweenChips: ' | ',
betweenNames: ' to ',
}}
onChipClose={handleChipClose}
/>
)
}
Code explanation
The SelectedFacets widget displays tags based on the selected facet values provided via dataConfig.
-
The
dataConfigprop supplies the facet selections to display. PassstringFacetsand/orrangeFacetsarrays directly, or setuseMarkLogicContext: trueto read selections automatically from the MarkLogic context. -
The single
onChipClosecallback replaces the previous separateremoveStringFacetandremoveRangeFacetcallbacks. It receives the facettype('string'or'range'), thefacetconstraint object, and an optionalvaluefor multi-value string facets. -
Call
context.removeStringFacetConstraint(facet, value)orcontext.removeRangeFacetConstraint(facet)insideonChipCloseto update the application context. -
The
chipConfigprop controls the visual appearance of all chips. UsechipConfig.overridesto apply different styles per facet type (e.g.,'string','number','date') or per facet name (e.g.,'price','color'). -
The
separatorConfigprop controls the separators rendered between chips (betweenChips), between constraint names (betweenNames), and between constraint types (betweenTypes).Note:
The StringFacet, DateRangeFacet, BucketRangeFacet, and NumberRangeFacet widgets are not shown in the Example Configuration.
Example rendering
This example shows the tags rendered by the SelectedFacets widget:
![]() |
The Status facet is an example of a string facet that can only have a single selection. The Sources facet is an example of a string facet that can have multiple selections.
API
Prop |
Type |
Description |
|---|---|---|
dataConfig (required) |
object |
Configuration for the facet data to display. Either set |
separatorConfig |
object |
Configuration for custom separators rendered between chips, constraint names, and constraint types. See separatorConfig API below. |
chipConfig |
object |
Configuration for the appearance and behavior of all facet chips. Accepts all ISelectedFacetNode props plus an optional |
onChipClose |
((type: 'string' | 'range', facet: Constraint, value?: string) => void) |
Callback triggered when the close icon is clicked on a chip. Receives the facet |
dataConfig API
Prop |
Type |
Description |
|---|---|---|
useMarkLogicContext |
boolean |
When |
stringFacets |
Constraint[] |
Array of selected string facet constraints to display. Cannot be combined with |
rangeFacets |
Constraint[] |
Array of selected range facet constraints to display. Cannot be combined with |
facetRefs |
Record<string, RefObject> |
References to facet components, used under |
separatorConfig API
Prop |
Type |
Description |
|---|---|---|
betweenChips |
ReactNode |
Separator rendered between individual facet chips. |
betweenNames |
ReactNode |
Separator rendered between constraint names within a chip. |
betweenTypes |
ReactNode |
Separator rendered between constraint types. |
chipConfig API
The chipConfig prop accepts all ISelectedFacetNode fields (applied to every chip) plus an optional overrides map.
Prop |
Type |
Description |
|---|---|---|
id |
string |
Widget |
label |
ReactNode |
Label to display for the chip. Overrides the facet value label. |
icon |
ReactNode |
Icon element displayed alongside the chip label. |
ariaLabel |
string |
Accessible |
style |
CSSProperties & { dashed?: boolean } |
Inline CSS styles applied to the chip. Set |
className |
string |
CSS class name applied to the chip container. |
closeConfig |
object |
Configuration for the close icon on the chip. See closeConfig API below. |
hidden |
boolean |
When |
overrides |
Record<string, ISelectedFacetNode> |
Per-type or per-name overrides for chip appearance. Keys can be a facet type (e.g., |
closeConfig API
Prop |
Type |
Description |
|---|---|---|
disabled |
boolean |
When |
icon |
ReactNode |
Custom element to use as the close icon. |
iconClassName |
string |
CSS class name applied to the close icon element. |
