gpt4 book ai didi

reactjs - 如何删除 react 选择中的栏?

转载 作者:行者123 更新时间:2023-12-03 13:25:23 24 4
gpt4 key购买 nike

我正在尝试改进 react 选择的用户界面。我在网上做了一些研究,但我仍然不知道如何删除选择中的栏。

我可以设置控件组件的样式来删除栏吗?怎么办?

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}
/>
);

Edit react-codesandboxer-example

最佳答案

react-select 允许我们通过执行操作来控制组件

components={{
IndicatorSeparator: () => null
}}

例如:

<Select
id="search-commodity"
options={comodityOptions}
components={{
IndicatorSeparator: () => null
}}
/>

关于reactjs - 如何删除 react 选择中的栏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54047325/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com