Skip to content

Commit ceddd42

Browse files
tkruggHaroenv
authored andcommitted
fix(RefinementList): remove root css class on sublists (#4117)
**Summary** The RefinementList is the component used for rendering of the HierarchicalMenu widget. When a given item of the HierarchicalMenu has children, the RefinementList is recursively called, with the same cssClasses prop. As a result, the `cssClasses.root` is appearing on every list of children. This change is proposed because: 1. This is not the specified behaviour. 2. This is not the behaviour observed on InstantSearch V2. In V2, the `cssClasses.root` belonged to the [headerFooter HOC](https://github.com/algolia/instantsearch.js/blob/v2/src/decorators/headerFooter.js#L22). The problem emerged in InstantSearch V3 as the `cssClasses.root` property was moved inside the RefinementList widget.
1 parent 77ffb93 commit ceddd42

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

src/components/RefinementList/RefinementList.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ class RefinementList extends Component {
3030
let subItems;
3131
const hasChildren = facetValue.data && facetValue.data.length > 0;
3232
if (hasChildren) {
33+
const { root, ...cssClasses } = this.props.cssClasses;
3334
subItems = (
3435
<RefinementList
3536
{...this.props}
37+
cssClasses={cssClasses}
3638
depth={this.props.depth + 1}
3739
facetValues={facetValue.data}
3840
showMore={false}

src/components/RefinementList/__tests__/RefinementList-test.js

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ describe('RefinementList', () => {
1919
facetValues: [],
2020
...extraProps,
2121
};
22-
return shallow(React.createElement(RefinementList, props));
22+
return shallow(<RefinementList {...props} />);
2323
}
2424

2525
describe('cssClasses', () => {
@@ -209,6 +209,11 @@ describe('RefinementList', () => {
209209
isRefined: false,
210210
},
211211
],
212+
templateProps: {
213+
templates: {
214+
item: item => item.value,
215+
},
216+
},
212217
};
213218

214219
const root = shallowRender(props);
@@ -218,6 +223,32 @@ describe('RefinementList', () => {
218223
expect(root.props().children[2].props.className).toContain('depth-0');
219224
expect(subList.props().children[2].props.className).toContain('depth-1');
220225
});
226+
227+
it('should not add root class on sub lists', () => {
228+
const props = {
229+
...defaultProps,
230+
cssClasses: {
231+
root: 'my-root',
232+
},
233+
facetValues: [
234+
{
235+
value: 'foo',
236+
data: [
237+
{ value: 'bar', isRefined: false },
238+
{ value: 'baz', isRefined: false },
239+
],
240+
isRefined: false,
241+
},
242+
],
243+
};
244+
245+
const root = shallowRender(props);
246+
const mainItem = root.find(RefinementListItem).at(0);
247+
const subList = shallow(mainItem.props().subItems);
248+
249+
expect(root.hasClass(props.cssClasses.root)).toBe(true);
250+
expect(subList.hasClass(props.cssClasses.root)).toBe(false);
251+
});
221252
});
222253

223254
describe('rendering', () => {

0 commit comments

Comments
 (0)