有条件的scss或覆盖变量

时间:2019-10-21 08:54:53

标签: javascript css reactjs sass bootstrap-4

在反应状态下,我正在传递列表,在其中传递并在需要的地方调用组件

comments: {
                elementLabel: "Comments",
                elementType: 'textarea',
                className: "form-control",
                elementConfig: {
                    placeholder: "comments",
                    name: "comments",
                    id: "comments",
                       },
                value: '',
                rows: "5",
                cols: 5,
                form_value: "",
                validation: {
                },
                valid: false,
                touched: false,
                isChanged: true,
                errorMessage: "",
                changed: (event) => this.inputChangedHandler(event, "comments"),
                blured: (event) => this.inputBlurHandler(event, "comments")
            },

如果低于此值,则比我要设置的类

.form-control {
    height: 34px !important;
  } instead of this i want to set `80px`

完整的scss类可以在style.scss中找到 我该如何实现?  如果我要添加新的类,使其使用div进行渲染,而不进行任何更改,则会将其覆盖。

<div className="form-row mb-3">
                                <div className="col-md-12">
                                    <div className="ftm-form">
                                        <Input
                                        className="form-control-height"
                                            {...this.state.comments}
                                        />
                                    </div>
                                </div>
                            </div>

更改前enter image description here enter image description here

1 个答案:

答案 0 :(得分:1)

首先,在CSS中,您应该将类​​描述为

.form-control {
    height: 34px;

    &.form-control-height {
      height: 80px;
    }
  }

在反应代码中,您正在用状态覆盖className。重构代码的方式:

<div className="form-row mb-3">
  <div className="col-md-12">
    <Input {...this.state.comments} className="form-control form-control-height" />
  </div>