Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/utils/match-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ export function matchAnd(keys, parentProps, childProps) {
// all match
return keys.every(parentKey => {
return childKeys.some(childKey => {
if (parentKey !== childKey) {
return false;
}
const parentValue = parentProps[parentKey];
const childValue = childProps[childKey];
if (childValue === parentValue) {
Expand All @@ -22,6 +25,9 @@ export function matchOr(keys, parentProps, childProps) {
// some match
return keys.some(parentKey => {
return childKeys.some(childKey => {
if (parentKey !== childKey) {
return false;
}
const parentValue = parentProps[parentKey];
const childValue = childProps[childKey];
if (childValue === parentValue) {
Expand Down
22 changes: 21 additions & 1 deletion test/ToggleOrPattern-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,26 @@ describe('<ToggleOrPattern />', () => {
const y = wrapper.find(ComponentX);
assert(y.length === 1);
assert.equal(wrapper.html(), `<div class="TogglePattern ToggleOrPattern"><div>Visible</div><div>Hidden</div></div>`)

});
it('render match Or pattern', () => {
class FixedBar extends React.Component {
render() {
return <div>{this.props.children}</div>
}
}
const Order = {
High: true,
Middle: true,
Low: false
};
const wrapper = shallow(<ToggleOrPattern High={Order.High} Middle={Order.Middle} Low={Order.Low}>
<FixedBar High={true}>High</FixedBar>
<FixedBar Middle={true}>Middle</FixedBar>
<FixedBar Low={true}>Low</FixedBar>
<FixedBar Middle={true}>Middle</FixedBar>
</ToggleOrPattern>);
// remove `Low`
assert.equal(wrapper.html(), `<div class="TogglePattern ToggleOrPattern"><div>High</div><div>Middle</div><div>Middle</div></div>`)
});
});