【发布时间】:2021-04-30 07:56:11
【问题描述】:
我正在尝试在 React 中创建一个带有描述的下拉列表。参考下图:
还有其他方法可以使用引导程序或 Material-UI 来实现吗?
我正在使用react-select npm 包作为下拉列表。您可以在下面找到实时链接和代码:
const colourOptions = [
{ value: "red", label: "Red" ,description:"Test description for red"},
{ value: "green", label: "Green", description:"Test description for green" },
{ value: "blue", label: "Blue", description:"Test description for blue" }
];
//for styling
const colourStyles = {
option: (styles, { data, isDisabled, isFocused, isSelected }) => {
// const color = chroma(data.color);
console.log({ data, isDisabled, isFocused, isSelected });
return {
...styles,
backgroundColor: isFocused ? "#00A3BE" : "#191D2F",
font: "Segoe UI",
color: "#F9FAFC"
};
}
};
export default () => (
<Select
defaultValue={colourOptions[1]}
label="Single select"
options={colourOptions}
styles={colourStyles}
/>
);
【问题讨论】:
-
您的图片链接设置不正确,请重新检查
标签: reactjs bootstrap-4 drop-down-menu dropdown react-select