javascript - 使用 shouldForwardProp 时伪类不起作用 / 如何在 styled-components 的 shouldForwardProp 中使用多个过滤器
问题描述
1 - 当我styled-components
在使用东西之后使用伪选择器时withConfig
,应用的伪选择器不起作用。
const Input = styled.input.attrs(({
type: "number",
size: 2,
placeholder: "Your number",
}))`
color: red;
text-decoration: none;
:disabled {
border: red 20px solid;
}
${({foo, borderWidth}) =>
foo &&
css`
color: purple;
padding: 0.3rem;
outline: none;
border-width: ${borderWidth};
::-webkit-inner-spin-button,
::-webkit-outer-spin-button {
-webkit-appearance: none;
}
::placeholder {
color: purple;
}
&:focus {
border-color: red;
padding: 0.3rem;
}
`}
`;
const Div = styled.div.withConfig({
shouldForwardProp: (prop, defaultValidatorFn) =>
!["foo"].includes(prop) && defaultValidatorFn(prop),
})`
:disabled {
border: gray 200px solid;
};
${({ foo }) => `
background-color: ${foo}
`}
`;
Input
一切正常。另一方面,在渲染元素Div
:disabled
中调用时 on 不起作用。jsx
解决方案
推荐阅读
- service-worker - 我应该在 service-worker 安装事件中缓存哪些文件?
- python - 如何使用 MatPlotLib 在循环中显示一组文件
- c++ - 检查纪元时间戳是否在 C++ 中给定的人类可读时间范围内
- java - 将 1GB 文件的内容流式传输到单列下的 sqlite 表
- python-3.x - Raspberry Pi:如何让 RPi.GIPO 与 Python 3.6 一起工作?
- angular - 基于 Web API 令牌的身份验证
- applescript - Applescript 邮件附件未发送
- vue.js - 如何让 VueJS + ESLint (Airbnb) + Prettier 一起工作?(VS代码)
- javascript - 无法在反应组件中使用 setState
- wordpress - 如何为 Woocommerce 类别和产品设置不同的缩略图大小