【问题标题】:How to style react autocomplete input box?如何样式反应自动完成输入框?
【发布时间】:2019-08-09 23:04:00
【问题描述】:

我正在尝试在我的组件中使用 react-autocomplete。一切正常,结果显示。但我无法设置默认输入框的样式。 这是自动完成

<Autocomplete 
getItemValue={this.getItemValue}
items={this.state.autocompleteData}
renderItem={this.renderItem}
value={this.state.value}
onChange={this.onChange}
onSelect={this.onSelect} 
menuStyle={menuStyle}
/> 

下拉菜单的样式工作正常。

const menuStyle = {
  borderRadius: '3px',
  boxShadow: '0 2px 12px rgba(0, 0, 0, 0.1)',
  background: 'rgba(255, 255, 255, 0.9)',
  padding: '2px 0',
  fontSize: '90%',
  position: 'fixed',
  overflow: 'auto',
  maxHeight: '50%', // TODO: don't cheat, let it flow to the bottom
  "zIndex": 100,
};

我尝试根据这个问题的答案添加样式,但它不起作用。 how to increase input text box size in react-autocomplete?

如何给输入框添加样式?

【问题讨论】:

    标签: reactjs autocomplete


    【解决方案1】:
    inputProps={{ style: menuStyle }}

    或者你可以这样做

    造型={ 边界半径:'3px', boxShadow: '0 2px 12px rgba(0, 0, 0, 0.1)', 背景:'rgba(255, 255, 255, 0.9)', 填充:'2px 0', 字体大小:'90%', 位置:'固定', 溢出:'自动', maxHeight: '50%', // TODO: 不要作弊,让它流到底部 “zIndex”:100, }

    【讨论】:

      【解决方案2】:

      给道具inputProps 的对象用作输入的道具,因此您可以给一个具有style 属性的对象,其中包含您的menuStyles。

      <Autocomplete
        getItemValue={this.getItemValue}
        items={this.state.autocompleteData}
        renderItem={this.renderItem}
        value={this.state.value}
        onChange={this.onChange}
        onSelect={this.onSelect}
        inputProps={{ style: menuStyle }}
      />
      

      【讨论】:

        猜你喜欢
        • 2014-11-14
        • 2016-03-11
        • 1970-01-01
        • 2019-12-01
        • 1970-01-01
        • 2016-08-18
        • 1970-01-01
        • 2012-08-08
        • 1970-01-01
        相关资源
        最近更新 更多