我正在使用styled-components
npm包,需要将aria-haspopup
属性添加到我的扩展Button组件中。我尝试过以下操作,但这不会添加属性:
import Button from './button';
const StyledBtn = Button.attrs({
'aria-haspopup': 'true',
}).extend``;
答案 0 :(得分:2)
我发现解决方案是:
新样式组件v4语法:
import Button from './button';
const StyledBtn = styled(Button).attrs({
'aria-haspopup': 'true',
})``;
旧语法:
import Button from './button';
const StyledBtn = Button.extend.attrs({
'aria-haspopup': 'true',
})``;
答案 1 :(得分:-1)
解决方案是:
import Button from './button';
const StyledBtn = Button.attrs(({ value }) => ({
ariaHaspopup: value,
}));