javascript - 单击它时防止展开 'React-select'

标签 javascript css reactjs react-select

我正在使用 react-selecthttps://react-select.com/home#getting-started .尝试将选择缩小到尺寸 width: 90px;高度:23px。但是,当您单击它时,选择增加。如何设置以上参数,让select的cay time为width: 90px;高度:23px?

此处演示:https://stackblitz.com/edit/react-sk7g4x

import Select from 'react-select'

const options = [
  { value: 'chocolate', label: 'Chocolate' },
  { value: 'strawberry', label: 'Strawberry' },
  { value: 'vanilla', label: 'Vanilla' }
]

class App extends Component {
  constructor() {
    super();
    this.state = {
      name: 'React'
    };
  }

  render() {
    return (
      <Select options={options} />
    );
  }
}

CSS

.css-2b097c-container {
  width: 90px;
  height: 23px;
  font-size: 10px;
}

.css-yk16xz-control {
  min-height: 23px;
}

.css-1pahdxg-control {
  min-height: 23px;
}

.select__control--is-focused {
  min-height: 23px;
}

.css-tu25sd-control {
  height: 23px;
}

.selectSort .css-aohzbe-control {
  height: 23px;
}

.selectSort .css-1hwfws3 {
  padding: 0;
}

.css-tlfecz-indicatorContainer {
  padding: 0;
}

.css-yk16xz-control {
  height: 23px;
}

最佳答案

尝试使用 Prop classNamePrefix .如果你不使用它,react-select 会创建动态前缀名称,例如 css-tu25sd-c..他们不可靠。

<Select options={options} classNamePrefix='my-className-prefix' />

有关更多 Prop 信息,请参阅:https://github.com/JedWatson/react-select#props 编辑的解决方案。尝试使用 classNamePrefix Prop ,更新你的 css 以匹配动态 css 类并在你的编辑器中运行。

h1, p {
  font-family: Lato;
}

.css-2b097c-container {
  width: 90px;
} 

.my-className-prefix-container,
.my-className-prefix__control {
  width: 90px !important;
  height: 3px !important;
}

.my-className-prefix__value-container,
.my-className-prefix__indicator-separator,
.my-className-prefix__dropdown-indicator {
  position: relative;
  bottom: 8px;
}

.my-className-prefix__control--is-focused {
  height: 23px;
}

.select__control--is-focused,
.css-1pahdxg-control {
  min-height: 23px;
}

.my-className-prefix__placeholder,
.my-className-prefix__value-container,
.my-className-prefix__menu {
  font-size: 10px;
}

.css-yk16xz-control {
  min-height: 23px;
  max-height: 23px;
}

关于javascript - 单击它时防止展开 'React-select',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58358982/

相关文章:

css - 标题 div 保持在顶部,垂直滚动的 div 在下面,滚动条仅附加到该 div

html - 如何使用 CSS 仅将 HTML 选项元素的首字母大写?

javascript - es6 中的装饰器是如何工作的?

javascript - React 子组件不会在父状态更改时重新渲染

javascript - 动态改变AngularJS中静态段落的颜色

asp.net - VS 2008 IDE 不断停止 jQuery 错误

javascript - jQuery Sticky Waypoints 方向选项不起作用

testing - 在 React 中使用 Mocha 测试高阶组件

javascript - 在激活验证之前查找 jQuery Accordion 中的元素

javascript - SharePoint 2013 - JavaScript : Why isn't my CAML query filtering my list data?