Skip to content

Commit 3ee0814

Browse files
authored
fix: support .attrs method (#8)
Closes #7
1 parent 47e2a3e commit 3ee0814

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

packages/styled-components/src/styled.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ import { Box } from './Box'
55

66
function getCreateStyle(baseCreateStyle) {
77
const createStyle = (...args) => baseCreateStyle([css(...args)])
8+
createStyle.attrs = attrs => {
9+
const nextCreateStyle = baseCreateStyle.attrs(attrs)
10+
return getCreateStyle(nextCreateStyle)
11+
}
812
createStyle.withConfig = config => {
913
const nextCreateStyle = baseCreateStyle.withConfig(config)
1014
return getCreateStyle(nextCreateStyle)

packages/styled-components/src/styled.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ describe('#styled', () => {
6565
expect(container.firstChild).toHaveStyleRule('margin-top', '2px')
6666
expect(container.firstChild).toHaveStyleRule('padding', '4px')
6767
})
68+
it('works with "attrs"', () => {
69+
const Dummy = styled.div.attrs({ 'aria-label': 'label' })`
70+
margin: 2;
71+
`
72+
const { container } = render(<Dummy />)
73+
expect(container.firstChild.getAttribute('aria-label')).toBe('label')
74+
expect(container.firstChild).toHaveStyleRule('margin', '8px')
75+
})
6876
})
6977

7078
describe('#styled.xxx', () => {

0 commit comments

Comments
 (0)