Skip to content

Commit 12601ea

Browse files
wellguimaraeslttb
authored andcommitted
fixed issue while updating dynamic props for conditional rules
1 parent f35db97 commit 12601ea

3 files changed

Lines changed: 46 additions & 1 deletion

File tree

src/styled.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,15 @@ const styled = ({tagName, elementStyle, mountSheet}: StyledArgs) => {
7171
updateSheet(props: StyledElementPropsType) {
7272
let rule
7373
let ruleIndex = 0
74+
7475
// nested styles become to flatten rules, so we need to update each nested rule
7576
for (ruleIndex; ruleIndex < classMap[this.dynamicTagName].length; ruleIndex++) {
7677
rule = classMap[this.dynamicTagName][ruleIndex]
77-
this.sheet.update(rule.name, props)
78+
79+
if (rule.name)
80+
this.sheet.update(rule.name, props)
81+
else
82+
this.sheet.update(props)
7883
}
7984
}
8085

src/tests/__snapshots__/functional.spec.jsx.snap

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
exports[`functional tests should update all dynamic props 1`] = `
2+
".button-1-id {
3+
padding: 10px;
4+
}
5+
@media screen {
6+
.button-1-id {
7+
margin: 10px;
8+
}
9+
}"
10+
`;
11+
12+
exports[`functional tests should update all dynamic props 2`] = `
13+
".button-1-id {
14+
padding: 0;
15+
}
16+
@media screen {
17+
.button-1-id {
18+
margin: 0;
19+
}
20+
}"
21+
`;
22+
123
exports[`functional tests should update nested props 1`] = `
224
".button-id {
325
font-size: 12px;

src/tests/functional.spec.jsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,22 @@ describe('functional tests', () => {
110110
assertSheet(sheet)
111111
wrapper.unmount()
112112
})
113+
114+
it('should update all dynamic props', () => {
115+
const Button = styled('button')({
116+
padding: props => props.spaced ? 10 : 0,
117+
118+
'@media screen': {
119+
margin: props => props.spaced ? 10 : 0
120+
}
121+
})
122+
123+
const wrapper = mount(<Button spaced={true} />)
124+
125+
expect(styled.mountSheet().toString()).toMatchSnapshot()
126+
wrapper.setProps({ spaced: false })
127+
expect(styled.mountSheet().toString()).toMatchSnapshot()
128+
129+
wrapper.unmount()
130+
})
113131
})

0 commit comments

Comments
 (0)