react-select 选择选项后隐藏dropdownIndicator和indicatorSeparator

问题描述 投票:0回答:2

选择一个选项后,我需要隐藏 dropdownIndicator 和 IndicatorSeparator。

我尝试应用样式:

indicatorSeparator: (base) => ({
  ...base,
  display: "none",
}),
dropdownIndicator: (base) => ({
  ...base,
  display: "none",
}),

但不知道如何有条件地将它们放入反应选择样式。

reactjs react-select
2个回答
0
投票
<Select 
  components={{
    IndicatorSeparator: () => null,
    DropdownIndicator: () => null,
  }}
  style={{
   ...
  }}
/>

0
投票

我就是这样做的。

 dropdownIndicator: (base, state) => ({
  ...base,
  display: state.hasValue ? "none" : "block", }),

 indicatorSeparator: (base, state) => ({
   ...base,
   display: state.hasValue ? "none" : "block",
 }),
© www.soinside.com 2019 - 2024. All rights reserved.