我可以在语义 UI React 的选项数组中为下拉组件指定分隔符或 Header 吗?

Can I specify a Divider or Header in Semantic UI React's options array for the dropdown component?

我正在使用 ReactJS 并使用 ReactJS 的 SemanticUI 来设置前端样式,

是否可以从 objects 的选项数组中为下拉组件指定 header or divider

我从文档中得到的印象是这还不受支持。

我通过将选项数组中的 object 更改为具有更多属性(允许您自定义内容)来解决此问题:

        {
            text: "YouGov Filters",
            value: "yougov-header",
            content: <Header content="YouGov Filters" color="teal" size="small" />,
            disabled: true
        },

这可能不是实现我想要的理想方式,因为我必须将 disabled 设置为 true(我不希望它成为一个可选选项),这意味着它采用灰色 'disabled' 样式.我试图通过为 header 指定一种颜色来解决这个问题,这导致禁用样式被应用到青色上,虽然不完美,但现在可以了。

另一种解决方法是通过映射数组来完成:

const options = [
    {
        text: "note",
        icon: 'sticky note outline',
        description: 'test',
    },
    {
        divider: true
    },
    {
        text: "task",
        icon: 'calendar check outline',
        description: 'test',
    },

];

return (
    <Dropdown className='multicontent__button' text='add new' button>
        <Dropdown.Menu>
            <Dropdown.Header icon='tags' content='Tag Label' />
            {options.map((option, i) => {
                if (option.divider === true) return (<Dropdown.Divider key={i}/>);
                return (
                    <Dropdown.Item
                        key={i}
                        text={option.text}
                        icon={option.icon}
                        description={option.description}
                        action={option.action}
                        onClick={this.handleOption}
                    />
                );
            })}
        </Dropdown.Menu>
    </Dropdown>
);

B 先生的解决方案是天才。而且他的稍微修改一下就可以更干净了:

function FragmentWithoutWarning({key, children}) {
  // to get rid of the warning:
  // "React.Fragment can only have `key` and `children` props."
  return <React.Fragment key={key}>{children}</React.Fragment>;
}

// then just:

{
  as: FragmentWithoutWarning,
  content: <Header content="YouGov Filters" color="teal" size="small" />
}

由于 <React.Fragment /> 无法捕获任何事件,您甚至不必禁用该项目。