Skip to content

Commit f12a1bf

Browse files
committedMay 31, 2016
fix(component): fix unexpected match case (#3)
check parent and child key before matching value
1 parent 0b1bc20 commit f12a1bf

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed
 

‎src/utils/match-props.js

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ export function matchAnd(keys, parentProps, childProps) {
55
// all match
66
return keys.every(parentKey => {
77
return childKeys.some(childKey => {
8+
if (parentKey !== childKey) {
9+
return false;
10+
}
811
const parentValue = parentProps[parentKey];
912
const childValue = childProps[childKey];
1013
if (childValue === parentValue) {
@@ -22,6 +25,9 @@ export function matchOr(keys, parentProps, childProps) {
2225
// some match
2326
return keys.some(parentKey => {
2427
return childKeys.some(childKey => {
28+
if (parentKey !== childKey) {
29+
return false;
30+
}
2531
const parentValue = parentProps[parentKey];
2632
const childValue = childProps[childKey];
2733
if (childValue === parentValue) {

‎test/ToggleOrPattern-test.js

+21-1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,26 @@ describe('<ToggleOrPattern />', () => {
8383
const y = wrapper.find(ComponentX);
8484
assert(y.length === 1);
8585
assert.equal(wrapper.html(), `<div class="TogglePattern ToggleOrPattern"><div>Visible</div><div>Hidden</div></div>`)
86-
86+
});
87+
it('render match Or pattern', () => {
88+
class FixedBar extends React.Component {
89+
render() {
90+
return <div>{this.props.children}</div>
91+
}
92+
}
93+
const Order = {
94+
High: true,
95+
Middle: true,
96+
Low: false
97+
};
98+
const wrapper = shallow(<ToggleOrPattern High={Order.High} Middle={Order.Middle} Low={Order.Low}>
99+
<FixedBar High={true}>High</FixedBar>
100+
<FixedBar Middle={true}>Middle</FixedBar>
101+
<FixedBar Low={true}>Low</FixedBar>
102+
<FixedBar Middle={true}>Middle</FixedBar>
103+
</ToggleOrPattern>);
104+
// remove `Low`
105+
assert.equal(wrapper.html(), `<div class="TogglePattern ToggleOrPattern"><div>High</div><div>Middle</div><div>Middle</div></div>`)
87106
});
88107
});
108+

0 commit comments

Comments
 (0)
Please sign in to comment.