[英]Is there anyway to disable the "x" that delete a selected option in react-select?
I'm Working with react-select and I need to disable the option to delete specific selections (hide or delete the x which is in the red square)我正在使用 react-select,我需要禁用删除特定选择的选项(隐藏或删除红色方块中的 x)
I have looking for a prop to do it and I found this:我一直在寻找一个道具来做这件事,我发现了这个:
isClearable={false}
But that option hide this:但是该选项隐藏了这一点:
In summary I need to hide the x's shown at first image but keep the shown in the second one总之,我需要隐藏第一张图片中显示的 x,但保留第二张图片中显示的
you can try this way with know the class name for the x
and hide it with CSS您可以通过知道
x
的 class 名称并使用 CSS 隐藏它来尝试这种方式
1- open the console in the browser and use the select tools 1-在浏览器中打开控制台并使用 select 工具
and then use the class name in CSS as this way然后以这种方式使用 CSS 中的 class 名称
className {
display: none !important;
}
use multiValueRemove
as使用
multiValueRemove
作为
const selectStyle = {
multiValueRemove: (style, state) => {
console.log('multi value remove', state, style);
return {
...style,
...(state.data?.isDisabled
? {
visibility: 'hidden',
width: '4px',
}
: {}),
};
},
};
return <Select styles={selectStyle} />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.