React-Bootstrap如何将下拉列表分开?

发布于 01-22 16:02 字数 3346 浏览 4 评论 0原文

我正在使用 react-bootstrap 使用<< 使用<<代码>下拉组件。

尽管我可以轻松工作,但我想进一步将其中一个选项分为拆分按钮。

这是我尝试拆分任何东西之前的工作代码...

<DropdownButton 
    variant="light" 
    title={ <><MdFilterListAlt />&nbsp;&nbsp;<span className="text-muted">Filters</span></> }
    >
    <Dropdown.Item eventKey="1">My Invoices</Dropdown.Item>
    <Dropdown.Divider />
    <Dropdown.Item eventKey="2">Draft</Dropdown.Item>
    <Dropdown.Item eventKey="3">Posted</Dropdown.Item>
    <Dropdown.Item eventKey="4">Cancelled</Dropdown.Item>
    <Dropdown.Divider />
    <Dropdown.Item eventKey="5">To Check</Dropdown.Item>
    <Dropdown.Divider />
    <Dropdown.Item eventKey="6">Unpaid</Dropdown.Item>
    <Dropdown.Item eventKey="7">Paid</Dropdown.Item>
    <Dropdown.Item eventKey="8">Overdue</Dropdown.Item>
    <Dropdown.Divider />
    <Dropdown.Item eventKey="9">Invoice Date</Dropdown.Item>
    <Dropdown.Item eventKey="10">Due Date</Dropdown.Item>
    <Dropdown.Divider />
    <Dropdown.Item eventKey="11">Add Custom Filter</Dropdown.Item>
</DropdownButton>

这是我的代码(不起作用,但我试图更好地说明概念):

<DropdownButton 
    variant="light" 
    title={ <><MdFilterListAlt />&nbsp;&nbsp;<span className="text-muted">Filters</span></> }
    >
    <Dropdown.Item eventKey="1">My Invoices</Dropdown.Item>
    <Dropdown.Divider />
    <Dropdown.Item eventKey="2">Draft</Dropdown.Item>
    <Dropdown.Item eventKey="3">Posted</Dropdown.Item>
    <Dropdown.Item eventKey="4">Cancelled</Dropdown.Item>
    <Dropdown.Divider />
    <Dropdown.Item eventKey="5">To Check</Dropdown.Item>
    <Dropdown.Divider />
    <Dropdown.Item eventKey="6">Unpaid</Dropdown.Item>
    <Dropdown.Item eventKey="7">Paid</Dropdown.Item>
    <Dropdown.Item eventKey="8">Overdue</Dropdown.Item>
    <Dropdown.Divider />
    <Dropdown.Item eventKey="9" as={ ButtonGroup }>
        <Dropdown>
            <Button variant="light">Invoice Date</Button>
            <Dropdown.Toggle split variant="light" id="dropdown-split-basic" />
            <Dropdown.Menu>
                <Dropdown.Item eventKey="12">Action</Dropdown.Item>
                <Dropdown.Item eventKey="13">Another action</Dropdown.Item>
                <Dropdown.Item eventKey="14">Something else here</Dropdown.Item>
            </Dropdown.Menu>
        </Dropdown>
    </Dropdown.Item>
    <Dropdown.Item eventKey="10">Due Date</Dropdown.Item>
    <Dropdown.Divider />
    <Dropdown.Item eventKey="11">Add Custom Filter</Dropdown.Item>
</DropdownButton>`

我已经浏览了文档在拆分按钮下拉列表上,但没有一个dropdown.item被转换为此的示例在我的用例中。

有什么办法做到这一点吗?

I am using react-bootstrap to create a dropdown menu using the Dropdown component.

Although I can get the dropdown to easily work, I want to further split one of the options to be a Split button.

Here is the working code before I attempt to split anything...

<DropdownButton 
    variant="light" 
    title={ <><MdFilterListAlt />  <span className="text-muted">Filters</span></> }
    >
    <Dropdown.Item eventKey="1">My Invoices</Dropdown.Item>
    <Dropdown.Divider />
    <Dropdown.Item eventKey="2">Draft</Dropdown.Item>
    <Dropdown.Item eventKey="3">Posted</Dropdown.Item>
    <Dropdown.Item eventKey="4">Cancelled</Dropdown.Item>
    <Dropdown.Divider />
    <Dropdown.Item eventKey="5">To Check</Dropdown.Item>
    <Dropdown.Divider />
    <Dropdown.Item eventKey="6">Unpaid</Dropdown.Item>
    <Dropdown.Item eventKey="7">Paid</Dropdown.Item>
    <Dropdown.Item eventKey="8">Overdue</Dropdown.Item>
    <Dropdown.Divider />
    <Dropdown.Item eventKey="9">Invoice Date</Dropdown.Item>
    <Dropdown.Item eventKey="10">Due Date</Dropdown.Item>
    <Dropdown.Divider />
    <Dropdown.Item eventKey="11">Add Custom Filter</Dropdown.Item>
</DropdownButton>

Here is my code (not working but I am trying to illustrate the concept better ):

<DropdownButton 
    variant="light" 
    title={ <><MdFilterListAlt />  <span className="text-muted">Filters</span></> }
    >
    <Dropdown.Item eventKey="1">My Invoices</Dropdown.Item>
    <Dropdown.Divider />
    <Dropdown.Item eventKey="2">Draft</Dropdown.Item>
    <Dropdown.Item eventKey="3">Posted</Dropdown.Item>
    <Dropdown.Item eventKey="4">Cancelled</Dropdown.Item>
    <Dropdown.Divider />
    <Dropdown.Item eventKey="5">To Check</Dropdown.Item>
    <Dropdown.Divider />
    <Dropdown.Item eventKey="6">Unpaid</Dropdown.Item>
    <Dropdown.Item eventKey="7">Paid</Dropdown.Item>
    <Dropdown.Item eventKey="8">Overdue</Dropdown.Item>
    <Dropdown.Divider />
    <Dropdown.Item eventKey="9" as={ ButtonGroup }>
        <Dropdown>
            <Button variant="light">Invoice Date</Button>
            <Dropdown.Toggle split variant="light" id="dropdown-split-basic" />
            <Dropdown.Menu>
                <Dropdown.Item eventKey="12">Action</Dropdown.Item>
                <Dropdown.Item eventKey="13">Another action</Dropdown.Item>
                <Dropdown.Item eventKey="14">Something else here</Dropdown.Item>
            </Dropdown.Menu>
        </Dropdown>
    </Dropdown.Item>
    <Dropdown.Item eventKey="10">Due Date</Dropdown.Item>
    <Dropdown.Divider />
    <Dropdown.Item eventKey="11">Add Custom Filter</Dropdown.Item>
</DropdownButton>`

I have looked through the documentation on split button dropdowns but there is no example of a Dropdown.Item being converted into this but I need this in my use case.

Is there any way to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

野生奥特曼 2025-01-29 16:02:08

您的示例正在起作用。单击内部时,仅在默认情况下关闭下拉菜单。您可以通过调整属性 AutoClose 来改变此行为。在我的示例中,我将其设置为false:

https://codesandbox.io/s/flamboyant-taboyantbox.io/s/flamboyant-taaussig -6NQJ1K

  • 使用 show ontoggle onSelect 来管理所需的可见性行为。
  • 根据需要的样式

Your example is working. It's just by default dropdown menu is closed when you click inside. You can change this behaviour by adjusting the property autoClose. In my example I set it to false:

https://codesandbox.io/s/flamboyant-taussig-6nqj1k

  • Manage the desired visibility behaviour with show, onToggle and onSelect.
  • Style as needed
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文