Skip to content

Commit

Permalink
merge base styles with resolved multiple selectors closes #862 (#865)
Browse files Browse the repository at this point in the history
  • Loading branch information
robinweser authored Feb 12, 2021
1 parent b319f29 commit 12fa962
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,31 @@ describe('multiple-selectors plugin', () => {
},
})
})

it('should merge resolved nested objects', () => {
const style = {
color: 'blue',
':hover': {
color: 'blue',
fontSize: 12,
},
':hover,:focus': {
backgroundColor: 'red',
color: 'red',
},
}

expect(multipleSelectors()(style)).toEqual({
color: 'blue',
':hover': {
backgroundColor: 'red',
fontSize: 12,
color: 'red',
},
':focus': {
backgroundColor: 'red',
color: 'red',
},
})
})
})
9 changes: 8 additions & 1 deletion packages/fela-plugin-multiple-selectors/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@ function multipleSelectors(style: Object): Object {
const resolvedValue = multipleSelectors(value)

arrayEach(property.split(','), (selector) => {
normalizedStyle[selector.trim()] = resolvedValue
const key = selector.trim()

// merge styles with base styles
const baseStyle = normalizedStyle[key] || {}
normalizedStyle[key] = {
...baseStyle,
...resolvedValue,
}
})
} else {
normalizedStyle[property] = value
Expand Down

0 comments on commit 12fa962

Please sign in to comment.