Skip to content

Commit b048f0b

Browse files
committed
fix(refinementList): ensure the key reflects the underlying state
Fix #398
1 parent cb34048 commit b048f0b

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

components/RefinementList/RefinementList.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,11 @@ class RefinementList extends React.Component {
3535
[this.props.cssClasses.active]: facetValue.isRefined
3636
});
3737

38+
let key = facetValue[this.props.facetNameKey] + '/' + facetValue.isRefined + '/' + facetValue.count;
3839
return (
3940
<div
4041
className={cssClassItem}
41-
key={facetValue[this.props.facetNameKey]}
42+
key={key}
4243
onClick={this.handleClick.bind(this, facetValue[this.props.facetNameKey])}
4344
>
4445
<Template data={templateData} templateKey="item" {...this.props.templateProps} />

components/RefinementList/__tests__/RefinementList-test.js

+24-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ describe('RefinementList', () => {
2929
data: {
3030
cssClasses: {
3131
list: 'list',
32-
item: 'item'
32+
item: 'item',
33+
active: 'active'
3334
}
3435
}
3536
};
@@ -55,6 +56,26 @@ describe('RefinementList', () => {
5556
</div>
5657
</div>
5758
);
59+
expect(out.props.children[0].key).toEqual('facet1/undefined/undefined');
60+
expect(out.props.children[1].key).toEqual('facet2/undefined/undefined');
61+
});
62+
63+
it('should render default list highlighted', () => {
64+
let out = render({facetValues: [{name: 'facet1', isRefined: true, count: 42}]});
65+
let activeTemplateProp = {...templateProps};
66+
activeTemplateProp.data.count = 42;
67+
activeTemplateProp.data.isRefined = true;
68+
expect(out).toEqualJSX(
69+
<div {...parentListProps}>
70+
<div className="item active" onClick={itemProps.onClick}>
71+
<Template
72+
{...activeTemplateProp}
73+
data={{...templateProps.data, name: 'facet1'}}
74+
/>
75+
</div>
76+
</div>
77+
);
78+
expect(out.props.children[0].key).toEqual('facet1/true/42');
5879
});
5980

6081
context('sublist', () => {
@@ -127,7 +148,8 @@ describe('RefinementList', () => {
127148
return {
128149
cssClasses: {
129150
list: 'list',
130-
item: 'item'
151+
item: 'item',
152+
active: 'active'
131153
},
132154
facetValues: [
133155
{name: 'facet1'},

0 commit comments

Comments
 (0)