javascript - React下拉菜单的jss样式

标签 javascript html css reactjs jss

  • 我正在尝试设计我的占位符
  • 我没有使用 css,而是使用了 JSS。
  • 所以我用谷歌搜索并找到了这个链接 Styling the placeholder in a TextField

  • 我也试过 !important 但它不起作用。

  • 你能告诉我如何解决吗?
  • 在下面提供我的代码片段和沙箱

https://codesandbox.io/s/react-codesandboxer-example-ntz22

const styles = theme => ({


  input: {
    // padding: 0,
    "&::placeholder": {
      //  fontSize: '14 !important',
      color: "blue !important"
    }
  }
});

class SingleSelect extends Component<*, State> {
  state = {
    isClearable: true,
    isDisabled: false,
    isLoading: false,
    isRtl: false,
    isSearchable: true
  };

  toggleClearable = () =>
    this.setState(state => ({ isClearable: !state.isClearable }));
  toggleDisabled = () =>
    this.setState(state => ({ isDisabled: !state.isDisabled }));
  toggleLoading = () =>
    this.setState(state => ({ isLoading: !state.isLoading }));
  toggleRtl = () => this.setState(state => ({ isRtl: !state.isRtl }));
  toggleSearchable = () =>
    this.setState(state => ({ isSearchable: !state.isSearchable }));
  render() {
    const {
      isClearable,
      isSearchable,
      isDisabled,
      isLoading,
      isRtl
    } = this.state;
    return (
      <Fragment>
        <Select
          className="basic-single"
          classNamePrefix="select"
          // defaultValue={colourOptions[0]}
          isDisabled={isDisabled}
          isLoading={isLoading}
          isClearable={isClearable}
          isRtl={isRtl}
          isSearchable={isSearchable}
          name="color"
          options={colourOptions}
          placeholder={"2 testing here."}
        />
      </Fragment>

最佳答案

您找到的链接是针对 Material-UI <TextField/> 的但你正在使用 React Select .

React select 有一个 styles 接受 paceholder 的属性返回占位符样式的方法如下:

<Fragment>
  <Select
    className="basic-single"
    classNamePrefix="select"
    // defaultValue={colourOptions[0]}
    isDisabled={isDisabled}
    isLoading={isLoading}
    isClearable={isClearable}
    isRtl={isRtl}
    isSearchable={isSearchable}
    name="color"
    options={colourOptions}
    placeholder={"2 testing here."}
    styles={{
      placeholder: () => ({
        color: 'blue'
      })
    }}
  />
</Fragment>

关于javascript - React下拉菜单的jss样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59325087/

相关文章:

javascript - Phaser 3 碰撞器剪辑

javascript - commands.js 中未定义 Cypress 和 cy,但一切正常

javascript - 使用 JavaScript 将类添加到特定的 href 元素

html - 在怪癖模式下,是否可以将 img 的大小调整为其包含的表格单元格?

javascript - React - 如何从子组件获取状态数据?

javascript - Lightbox 2 在另一个页面中打开图像。我该如何解决?

javascript - 使用 HTML/Javascript 在图像上放置点

html - CSS : text is moving up while hover

asp.net - 多个提交按钮和 css tabpanel

html - 当我使用 Thymeleaf 运行我的 Spring Boot 元素时,浏览器不会加载 css 文件,而是加载 href 和 th :href is correct 的路径