如何在样式组件中覆盖CSS类

时间:2019-07-22 12:48:10

标签: css reactjs typescript styled-components

Search.tsx中:

import { SearchInput } from Search.styles.ts

<SearchInput
    onChange={handleChange}
    value={values["searchValue"]}
    placeholder="Search"
    type="text"
    name="searchValue"
/>

输出html:

<div class="1">
  <div class="2">
    <div class="3">
      <span class="InputWrapper">
        <input placeholder="Search" name="searchValue" class="Input input normalVariant" formnovalidate="" type="text" value="" >
      </span>
    </div>
  </div>
</div>

Search.styles.ts:

import * as Toolkit from "@some_repo/toolkit";
export const SearchInput = styled(Toolkit.Input)`
  InputWrapper: 100%
`

我要设置InputWrapper: width 100%,正确的方法是什么?

2 个答案:

答案 0 :(得分:0)

import * as Toolkit from "@some_repo/toolkit";
export const SearchInput = styled(Toolkit.Input)`
  width: 100%;
`

答案 1 :(得分:0)

它的工作方式类似于CSS,但是您需要在类名之前添加&。

import * as Toolkit from "@some_repo/toolkit";
export const SearchInput = styled(Toolkit.Input)`
  &.InputWrapper {
    width: 100%;
};