【问题标题】:Changing the default color of placeholder in react-virtualized-select在 react-virtualized-select 中更改占位符的默认颜色
【发布时间】:2019-08-23 09:35:37
【问题描述】:

尝试使用 input::-webkit-input-placeholder 和 singleValue 属性更改我的 react-virtualized-select 元素的占位符的默认颜色,但它不起作用。我什至尝试将整个代码包装在一个自定义主题中,其中原色为蓝色,但它也不起作用。我希望它将其更改为文本字段占位符中的颜色。

import "react-select/dist/react-select.css";
import "react-virtualized/styles.css";
import "react-virtualized-select/styles.css";
import "material-components-web/dist/material-components-web.css";
import "./react-select.css";

import React from "react";
import ReactDOM from "react-dom";
import Select from "react-virtualized-select";
import TextField from "rmwc/TextField";

const colourStyles = {
  singleValue: styles => ({ ...styles, color: "blue" })
};

const options = Array.from(new Array(10), (_, index) => ({
  label: `Item ${index}`,
  value: index
}));

class Foo extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      option: undefined
    };
  }
  render() {
    return (
      <React.Fragment>
        <Select
          className={"mdc-react-select"}
          value={this.state.option}
          onChange={option => this.setState({ option })}
          styles={colourStyles}
          options={options}
          inputRenderer={props => {
            return (
              <TextField
                {...props}
                fullwidth
                ref={undefined}
                inputRef={props.ref}
                placeholder={"Farm"}
                required
                value={
                  props.value ||
                  (this.state.option ? this.state.option.label : undefined)
                }
              />
            );
          }}
        />
        <br />
        <br />

        <div>
          <TextField
            ref={undefined}
            label={"Farm"}
            value={this.state.option ? this.state.option.label : undefined}
            style={{ width: "100%" }}
          />
        </div>


      </React.Fragment>
    );
  }
}
ReactDOM.render(<Foo />, document.getElementById("root"));

CSS:

body {
  font-family: "Roboto";
}
.mdc-react-select .Select-placeholder,
.mdc-react-select .Select-value {
  display: none;
}

.mdc-react-select .Select-control {
  background-color: transparent;
  border-color: none;
  border-radius: 0;
  border: none;
  color: #333;
  cursor: default;
  display: table;
  border-spacing: 0;
  border-collapse: separate;
  height: 36px;
  outline: none;
  overflow: hidden;
  position: relative;
  width: 100%;
  box-shadow: none !important;
}

.mdc-react-select .Select-input {
  opacity: 1 !important;
  width: 100%;
}

.mdc-text-field .mdc-line-ripple{
  background-color: rgb(23,87,170);
}

.mdc-floating-label .mdc-floating-label--float-above{
  color: rgb(23,87,170) !important;
}

.mdc-text-field--focused:not(.mdc-text-field--disabled) .mdc-floating-label{
  color:rgb(23,87,170) !important;
}

/* .mdc-text-field--invalid:not(.mdc-text-field--disabled):not(.mdc-text-field--outlined):not(.mdc-text-field--textarea) .mdc-text-field__input:hover{
    color:rgb(23,87,170) !important;
} */
/* input::-webkit-input-placeholder {
  color: #999;
} */

【问题讨论】:

    标签: css react-virtualized


    【解决方案1】:

    试试这个:

    .mdc-react-select .Select-input {
    color: red;
    }
    
    .mdc-react-select .Select-placeholder {
    color: red;
    }
    

    【讨论】:

    • 你为什么给这个风格? .mdc-react-select .Select-placeholder, .mdc-react-select .Select-value { display: none; }
    • 因为如果没有给出上面的 css,除了我的自定义“农场”占位符之外,它还会显示一个额外的“选择...”占位符。
    • 现在我看到您在 Select 中有一个 TextField,这就是上述代码不起作用的原因。你能给我们一个活生生的例子吗?
    • 我希望线条和占位符的颜色都是蓝色而不是选择和文本字段的紫色
    猜你喜欢
    • 1970-01-01
    • 2021-05-12
    • 2020-03-27
    • 2012-08-03
    • 2012-04-01
    • 2019-02-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多