@@ -24,6 +24,11 @@ import { type RefinementListProps } from '../types/InstantSearch';
2424import './FacetList.css' ;
2525
2626type Props = FacetProps & RefinementListProps & {
27+ /**
28+ * (Optional) class name to append to the root element.
29+ */
30+ className ?: string ,
31+
2732 /**
2833 * The default value for the `operator` prop. If not provided, this will default to `or`.
2934 */
@@ -34,6 +39,11 @@ type Props = FacetProps & RefinementListProps & {
3439 */
3540 defaultValue ?: string ,
3641
42+ /**
43+ * Renders a custom label element for the passed item.
44+ */
45+ renderLabel ?: ( item : any ) => JSX . Element ,
46+
3747 /**
3848 * If "true", the component will render a search box for searching individual facet values.
3949 */
@@ -45,6 +55,7 @@ type Props = FacetProps & RefinementListProps & {
4555 toggleable ?: boolean
4656} ;
4757
58+ const CLASS_SEPARATOR = ' ' ;
4859const OPERATOR_OR = 'or' ;
4960const OPERATOR_AND = 'and' ;
5061
@@ -68,6 +79,11 @@ const FacetList = forwardRef(({ useRefinementList, ...props }: Props, ref: HTMLE
6879 const searchRef = useRef ( ) ;
6980 const [ query , setQuery ] = useState ( '' ) ;
7081
82+ /**
83+ * Memo-izes the class name.
84+ */
85+ const className = useMemo ( ( ) => _ . compact ( [ 'facet-list' , props . className ] ) . join ( CLASS_SEPARATOR ) , [ props . className ] ) ;
86+
7187 /**
7288 * Clears the current search state.
7389 *
@@ -128,10 +144,11 @@ const FacetList = forwardRef(({ useRefinementList, ...props }: Props, ref: HTMLE
128144
129145 return (
130146 < Facet
131- className = 'facet-list'
147+ className = { className }
132148 defaultActive = { props . defaultActive }
133149 divided = { props . divided }
134150 innerRef = { ref }
151+ onActive = { props . onActive }
135152 title = { props . title }
136153 visible = { visible }
137154 >
@@ -156,23 +173,25 @@ const FacetList = forwardRef(({ useRefinementList, ...props }: Props, ref: HTMLE
156173 < List
157174 className = 'facet-list'
158175 >
159- { _ . map ( items , ( item , index ) => (
176+ { _ . map ( items , ( item ) => (
160177 < List . Item
161- key = { index }
178+ key = { item . value }
162179 >
163180 < Checkbox
164181 checked = { item . isRefined }
165182 label = { {
166- children : (
167- < >
168- < span > { item . label } </ span >
169- < Label
170- circular
171- content = { item . count }
172- size = 'small'
173- />
174- </ >
175- )
183+ children : props . renderLabel
184+ ? props . renderLabel ( item )
185+ : (
186+ < >
187+ < span > { item . label } </ span >
188+ < Label
189+ circular
190+ content = { item . count }
191+ size = 'small'
192+ />
193+ </ >
194+ )
176195 } }
177196 onClick = { ( ) => refine ( item . value ) }
178197 />
0 commit comments