Skip to content

Commit d476da2

Browse files
author
vvo
committed
fix(RefinementList): click on child should not click on parent
Before this fix, when clicking inside the child of a <a>..</a> would propagate to the parent and thus in hierarchical facets would close the parent as soon as we open the child. fixes #191
1 parent 200a7fe commit d476da2

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

components/RefinementList.js

+12-7
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,13 @@ class RefinementList extends React.Component {
3636
//
3737
// So the code here checks if the click was done on or in a LABEL. If this LABEL
3838
// has a checkbox inside, we ignore the first click event because we will get another one.
39+
//
40+
// We also check if the click was done inside a link and then e.preventDefault() because we already
41+
// handle the url
42+
//
43+
// Finally, we always stop propagation of the event to avoid multiple levels RefinementLists to fail: click
44+
// on child would click on parent also
3945
handleClick(value, e) {
40-
if (e.target.tagName === 'A' && e.target.href) {
41-
// do not trigger any url change by the href
42-
e.preventDefault();
43-
// do not bubble (so that hierarchical lists are not triggering refine twice)
44-
e.stopPropagation();
45-
}
46-
4746
if (e.target.tagName === 'INPUT') {
4847
this.refine(value);
4948
return;
@@ -56,9 +55,15 @@ class RefinementList extends React.Component {
5655
return;
5756
}
5857

58+
if (parent.tagName === 'A' && parent.href) {
59+
e.preventDefault();
60+
}
61+
5962
parent = parent.parentNode;
6063
}
6164

65+
e.stopPropagation();
66+
6267
this.refine(value);
6368
}
6469

0 commit comments

Comments
 (0)