如何删除 react-select 中的栏?
How can I remove the bar in the react-select?
我正在努力改进我的 UI 以响应 select。我在网上做了一些研究,但我仍然不知道如何删除 select.
中的栏
我可以设置控件组件的样式以移除该栏吗?怎么样?
import React from 'react';
import chroma from 'chroma-js';
import { colourOptions } from './docs/data';
import Select from 'react-select';
const dot = (color = '#ccc') => ({
alignItems: 'center',
display: 'flex',
':before': {
backgroundColor: color,
borderRadius: 10,
content: ' ',
display: 'block',
marginRight: 8,
height: 10,
width: 10,
},
});
const colourStyles = {
control: styles => ({ ...styles, backgroundColor: 'white' }),
option: (styles, { data, isDisabled, isFocused, isSelected }) => {
const color = chroma(data.color);
return {
...styles,
backgroundColor: isDisabled
? null
: isSelected ? data.color : isFocused ? color.alpha(0.1).css() : null,
color: isDisabled
? '#ccc'
: isSelected
? chroma.contrast(color, 'white') > 2 ? 'white' : 'black'
: data.color,
cursor: isDisabled ? 'not-allowed' : 'default',
};
},
input: styles => ({ ...styles, ...dot() }),
placeholder: styles => ({ ...styles, ...dot() }),
singleValue: (styles, { data }) => ({ ...styles, ...dot(data.color) }),
};
export default () => (
<Select
defaultValue={colourOptions[2]}
label="Single select"
options={colourOptions}
styles={colourStyles}
/>
);
您要设置样式的组件是 indicatorSeparator
。例如,将此添加到您的样式中:
indicatorSeparator: (styles) => ({display:'none'})
我是怎么发现这个的?我将 classNamePrefix 添加到 react-select 属性,然后使用检查器查看元素的 class 名称是什么。
react-select 允许我们通过
来控制组件
components={{
IndicatorSeparator: () => null
}}
例如:
<Select
id="search-commodity"
options={comodityOptions}
components={{
IndicatorSeparator: () => null
}}
/>
我正在努力改进我的 UI 以响应 select。我在网上做了一些研究,但我仍然不知道如何删除 select.
中的栏我可以设置控件组件的样式以移除该栏吗?怎么样?
import React from 'react';
import chroma from 'chroma-js';
import { colourOptions } from './docs/data';
import Select from 'react-select';
const dot = (color = '#ccc') => ({
alignItems: 'center',
display: 'flex',
':before': {
backgroundColor: color,
borderRadius: 10,
content: ' ',
display: 'block',
marginRight: 8,
height: 10,
width: 10,
},
});
const colourStyles = {
control: styles => ({ ...styles, backgroundColor: 'white' }),
option: (styles, { data, isDisabled, isFocused, isSelected }) => {
const color = chroma(data.color);
return {
...styles,
backgroundColor: isDisabled
? null
: isSelected ? data.color : isFocused ? color.alpha(0.1).css() : null,
color: isDisabled
? '#ccc'
: isSelected
? chroma.contrast(color, 'white') > 2 ? 'white' : 'black'
: data.color,
cursor: isDisabled ? 'not-allowed' : 'default',
};
},
input: styles => ({ ...styles, ...dot() }),
placeholder: styles => ({ ...styles, ...dot() }),
singleValue: (styles, { data }) => ({ ...styles, ...dot(data.color) }),
};
export default () => (
<Select
defaultValue={colourOptions[2]}
label="Single select"
options={colourOptions}
styles={colourStyles}
/>
);
您要设置样式的组件是 indicatorSeparator
。例如,将此添加到您的样式中:
indicatorSeparator: (styles) => ({display:'none'})
我是怎么发现这个的?我将 classNamePrefix 添加到 react-select 属性,然后使用检查器查看元素的 class 名称是什么。
react-select 允许我们通过
来控制组件components={{
IndicatorSeparator: () => null
}}
例如:
<Select
id="search-commodity"
options={comodityOptions}
components={{
IndicatorSeparator: () => null
}}
/>