"use strict";(self.webpackChunkreact_bootstrap_website=self.webpackChunkreact_bootstrap_website||[]).push([[1675],{25443:(n,o,e)=>{e.r(o),e.d(o,{assets:()=>B,contentTitle:()=>j,default:()=>M,frontMatter:()=>b,metadata:()=>y,toc:()=>k});var t=e(85893),r=e(11151);const d='import Dropdown from \'react-bootstrap/Dropdown\';\n\nfunction BasicExample() {\n return (\n \n \n Dropdown Button\n \n\n \n Action\n Another action\n Something else\n \n \n );\n}\n\nexport default BasicExample;\n',i='import Dropdown from \'react-bootstrap/Dropdown\';\nimport DropdownButton from \'react-bootstrap/DropdownButton\';\n\nfunction BasicButtonExample() {\n return (\n \n Action\n Another action\n Something else\n \n );\n}\n\nexport default BasicButtonExample;\n',p='import Button from \'react-bootstrap/Button\';\nimport ButtonGroup from \'react-bootstrap/ButtonGroup\';\nimport Dropdown from \'react-bootstrap/Dropdown\';\n\nfunction ButtonCustomExample() {\n return (\n <>\n \n Pow! Zoom!\n \n Action\n Another action\n \n Active Item\n \n \n Separated link\n \n {\' \'}\n \n \n \n \n Action\n Another action\n \n Active Item\n \n \n Separated link\n \n \n \n );\n}\n\nexport default ButtonCustomExample;\n',a='import React, { useState } from \'react\';\nimport Dropdown from \'react-bootstrap/Dropdown\';\nimport Form from \'react-bootstrap/Form\';\n\n// The forwardRef is important!!\n// Dropdown needs access to the DOM node in order to position the Menu\nconst CustomToggle = React.forwardRef(({ children, onClick }, ref) => (\n {\n e.preventDefault();\n onClick(e);\n }}\n >\n {children}\n ▼\n \n));\n\n// forwardRef again here!\n// Dropdown needs access to the DOM of the Menu to measure it\nconst CustomMenu = React.forwardRef(\n ({ children, style, className, \'aria-labelledby\': labeledBy }, ref) => {\n const [value, setValue] = useState(\'\');\n\n return (\n \n setValue(e.target.value)}\n value={value}\n />\n
    \n {React.Children.toArray(children).filter(\n (child) =>\n !value || child.props.children.toLowerCase().startsWith(value),\n )}\n
\n \n );\n },\n);\n\nrender(\n \n \n Custom toggle\n \n\n \n Red\n Blue\n \n Orange\n \n Red-Orange\n \n ,\n);\n',s='import ButtonGroup from \'react-bootstrap/ButtonGroup\';\nimport Dropdown from \'react-bootstrap/Dropdown\';\nimport DropdownButton from \'react-bootstrap/DropdownButton\';\nimport SplitButton from \'react-bootstrap/SplitButton\';\n\nfunction ButtonSizesExample() {\n return (\n <>\n
\n {[DropdownButton, SplitButton].map((DropdownType, idx) => (\n \n Action\n Another action\n Something else here\n \n Separated link\n \n ))}\n
\n
\n {[DropdownButton, SplitButton].map((DropdownType, idx) => (\n \n Action\n Another action\n Something else here\n \n Separated link\n \n ))}\n
\n \n );\n}\n\nexport default ButtonSizesExample;\n',l="import Dropdown from 'react-bootstrap/Dropdown';\nimport DropdownButton from 'react-bootstrap/DropdownButton';\nimport SplitButton from 'react-bootstrap/SplitButton';\n\nfunction DropDirectioExample() {\n return (\n <>\n
\n {['up', 'up-centered', 'down', 'down-centered', 'start', 'end'].map(\n (direction) => (\n \n Action\n Another action\n Something else here\n \n Separated link\n \n ),\n )}\n
\n\n
\n {['up', 'up-centered', 'down', 'down-centered', 'start', 'end'].map(\n (direction) => (\n \n Action\n Another action\n Something else here\n \n Separated link\n \n ),\n )}\n
\n \n );\n}\n\nexport default DropDirectioExample;\n",c='import Dropdown from \'react-bootstrap/Dropdown\';\nimport DropdownButton from \'react-bootstrap/DropdownButton\';\n\nfunction DropdownItemTagsExample() {\n return (\n \n Dropdown item text\n Action\n Another action\n Something else\n \n );\n}\n\nexport default DropdownItemTagsExample;\n',m='import Dropdown from \'react-bootstrap/Dropdown\';\nimport DropdownButton from \'react-bootstrap/DropdownButton\';\n\nfunction MenuAlignEndExample() {\n return (\n \n Action\n Another action\n Something else here\n \n Separated link\n \n );\n}\n\nexport default MenuAlignEndExample;\n',w='import Dropdown from \'react-bootstrap/Dropdown\';\nimport DropdownButton from \'react-bootstrap/DropdownButton\';\nimport SplitButton from \'react-bootstrap/SplitButton\';\n\nfunction MenuAlignResponsiveExample() {\n return (\n <>\n
\n \n Action 1\n Action 2\n \n
\n
\n \n Action 1\n Action 2\n \n
\n \n );\n}\n\nexport default MenuAlignResponsiveExample;\n',u='import Dropdown from \'react-bootstrap/Dropdown\';\n\nfunction MenuDividersExample() {\n return (\n \n Action\n Another action\n Something else here\n \n Separated link\n \n );\n}\n\nexport default MenuDividersExample;\n',D='import Dropdown from \'react-bootstrap/Dropdown\';\n\nfunction MenuHeadersExample() {\n return (\n \n Dropdown header\n Another action\n Something else here\n \n );\n}\n\nexport default MenuHeadersExample;\n',h='import Button from \'react-bootstrap/Button\';\nimport ButtonGroup from \'react-bootstrap/ButtonGroup\';\nimport Dropdown from \'react-bootstrap/Dropdown\';\n\nfunction SplitBasicExample() {\n return (\n \n \n\n \n\n \n Action\n Another action\n Something else\n \n \n );\n}\n\nexport default SplitBasicExample;\n',v="import Dropdown from 'react-bootstrap/Dropdown';\nimport SplitButton from 'react-bootstrap/SplitButton';\n\nfunction SplitVariantExample() {\n return (\n <>\n {['Primary', 'Secondary', 'Success', 'Info', 'Warning', 'Danger'].map(\n (variant) => (\n \n Action\n Another action\n \n Active Item\n \n \n Separated link\n \n ),\n )}\n \n );\n}\n\nexport default SplitVariantExample;\n",g="import ButtonGroup from 'react-bootstrap/ButtonGroup';\nimport Dropdown from 'react-bootstrap/Dropdown';\nimport DropdownButton from 'react-bootstrap/DropdownButton';\n\nfunction VariantsExample() {\n return (\n <>\n {['Primary', 'Secondary', 'Success', 'Info', 'Warning', 'Danger'].map(\n (variant) => (\n \n Action\n Another action\n \n Active Item\n \n \n Separated link\n \n ),\n )}\n \n );\n}\n\nexport default VariantsExample;\n",x='import Dropdown from \'react-bootstrap/Dropdown\';\nimport DropdownButton from \'react-bootstrap/DropdownButton\';\n\nfunction ButtonDarkExample() {\n return (\n <>\n \n \n Dropdown Button\n \n\n \n \n Action\n \n Another action\n Something else\n \n Separated link\n \n \n\n \n \n Action\n \n Another action\n Something else\n \n Separated link\n \n \n );\n}\n\nexport default ButtonDarkExample;\n',I='import Container from \'react-bootstrap/Container\';\nimport Nav from \'react-bootstrap/Nav\';\nimport Navbar from \'react-bootstrap/Navbar\';\nimport NavDropdown from \'react-bootstrap/NavDropdown\';\n\nfunction NavbarDarkExample() {\n return (\n \n \n React-Bootstrap\n \n \n \n \n \n \n );\n}\n\nexport default NavbarDarkExample;\n',f='import Dropdown from \'react-bootstrap/Dropdown\';\n\nfunction AutoCloseExample() {\n return (\n <>\n \n \n Default Dropdown\n \n\n \n Menu Item\n Menu Item\n Menu Item\n \n \n\n \n \n Clickable Outside\n \n\n \n Menu Item\n Menu Item\n Menu Item\n \n \n\n \n \n Clickable Inside\n \n\n \n Menu Item\n Menu Item\n Menu Item\n \n \n\n \n \n Manual Close\n \n\n \n Menu Item\n Menu Item\n Menu Item\n \n \n \n );\n}\n\nexport default AutoCloseExample;\n',b={title:"Dropdowns",description:"Toggle contextual overlays for displaying lists of links and more with the Bootstrap dropdown plugin"},j=void 0,y={id:"components/dropdowns",title:"Dropdowns",description:"Toggle contextual overlays for displaying lists of links and more with the Bootstrap dropdown plugin",source:"@site/docs/components/dropdowns.mdx",sourceDirName:"components",slug:"/components/dropdowns",permalink:"/docs/components/dropdowns",draft:!1,unlisted:!1,tags:[],version:"current",frontMatter:{title:"Dropdowns",description:"Toggle contextual overlays for displaying lists of links and more with the Bootstrap dropdown plugin"},sidebar:"sidebar",previous:{title:"Close Button",permalink:"/docs/components/close-button"},next:{title:"Figures",permalink:"/docs/components/figures"}},B={},k=[{value:"Overview",id:"overview",level:2},{value:"Accessibility",id:"accessibility",level:2},{value:"Examples",id:"examples",level:2},{value:"Single button dropdowns",id:"single-button-dropdowns",level:3},{value:"Split button dropdowns",id:"split-button-dropdowns",level:3},{value:"Sizing",id:"sizing",level:2},{value:"Dark dropdowns",id:"dark-dropdowns",level:2},{value:"Drop directions",id:"drop-directions",level:2},{value:"Dropdown items",id:"dropdown-items",level:2},{value:"Menu alignment",id:"menu-alignment",level:2},{value:"Responsive alignment",id:"responsive-alignment",level:3},{value:"Menu headers",id:"menu-headers",level:2},{value:"Menu dividers",id:"menu-dividers",level:2},{value:"AutoClose",id:"autoclose",level:2},{value:"Customization",id:"customization",level:2},{value:"Custom Dropdown Components",id:"custom-dropdown-components",level:3},{value:"API",id:"api",level:2},{value:"DropdownButton",id:"dropdownbutton",level:3},{value:"SplitButton",id:"splitbutton",level:3},{value:"Dropdown",id:"dropdown",level:3},{value:"DropdownToggle",id:"dropdowntoggle",level:3},{value:"DropdownMenu",id:"dropdownmenu",level:3},{value:"DropdownItem",id:"dropdownitem",level:3},{value:"DropdownHeader",id:"dropdownheader",level:3},{value:"DropdownDivider",id:"dropdowndivider",level:3}];function S(n){const o={a:"a",admonition:"admonition",code:"code",h2:"h2",h3:"h3",p:"p",strong:"strong",...(0,r.a)(),...n.components},{AriaAbbr:e,CodeBlock:b,PropsTable:j}=o;return e||A("AriaAbbr",!0),b||A("CodeBlock",!0),j||A("PropsTable",!0),(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(o.h2,{id:"overview",children:"Overview"}),"\n",(0,t.jsxs)(o.p,{children:["Dropdowns are toggleable, contextual overlays for displaying lists of\nlinks and more. Like overlays, Dropdowns are built using a third-party\nlibrary ",(0,t.jsx)("a",{href:"https://popper.js.org/",children:"Popper.js"}),", which provides\ndynamic positioning and viewport detection."]}),"\n",(0,t.jsx)(o.h2,{id:"accessibility",children:"Accessibility"}),"\n",(0,t.jsxs)(o.p,{children:["The ",(0,t.jsxs)("a",{href:"https://www.w3.org/TR/wai-aria/",children:[(0,t.jsx)("abbr",{title:"Web Accessibility Initiative",children:"WAI"})," ",(0,t.jsx)(e,{})]})," standard\ndefines a ",(0,t.jsxs)(o.a,{href:"https://www.w3.org/TR/wai-aria-1.1/#menu",children:[(0,t.jsx)(o.code,{children:'role="menu"'})," widget"]}),", but it's very specific to a certain kind of menu. ",(0,t.jsx)(e,{})," menus, must\nonly contain ",(0,t.jsx)(o.code,{children:'role="menuitem"'}),", ",(0,t.jsx)(o.code,{children:'role="menuitemcheckbox"'}),", or ",(0,t.jsx)(o.code,{children:'role="menuitemradio"'}),"."]}),"\n",(0,t.jsxs)(o.p,{children:["On the other hand, Bootstrap's dropdowns are designed to more generic\nand application in a variety of situations. For this reason we don't\nautomatically add the menu roles to the markup. We do implement some\nbasic keyboard navigation, and if you do provide the \"menu\" role,\nreact-bootstrap will do its best to ensure the focus management is\ncompliant with the ",(0,t.jsx)(e,{})," authoring guidelines for menus."]}),"\n",(0,t.jsx)(o.h2,{id:"examples",children:"Examples"}),"\n",(0,t.jsx)(o.h3,{id:"single-button-dropdowns",children:"Single button dropdowns"}),"\n",(0,t.jsxs)(o.p,{children:["The basic Dropdown is composed of a wrapping ",(0,t.jsx)(o.code,{children:"Dropdown"})," and\ninner ",(0,t.jsx)(o.code,{children:""}),", and ",(0,t.jsx)(o.code,{children:""}),". By\ndefault the ",(0,t.jsx)(o.code,{children:""})," will render a\n",(0,t.jsx)(o.code,{children:"Button"})," component and accepts all the same props."]}),"\n",(0,t.jsx)(b,{language:"jsx",live:!0,children:d}),"\n",(0,t.jsxs)(o.p,{children:["Since the above is such a common configuration react-bootstrap provides\nthe ",(0,t.jsx)(o.code,{children:""})," component to help reduce typing. Provide\na ",(0,t.jsx)(o.code,{children:"title"})," prop and some ",(0,t.jsx)(o.code,{children:""}),"s and you're\nready to go."]}),"\n",(0,t.jsx)(b,{language:"jsx",live:!0,children:i}),"\n",(0,t.jsx)(o.p,{children:"DropdownButton will forward Button props to the underlying Toggle\ncomponent"}),"\n",(0,t.jsx)(b,{language:"jsx",live:!0,children:g}),"\n",(0,t.jsx)(o.h3,{id:"split-button-dropdowns",children:"Split button dropdowns"}),"\n",(0,t.jsx)(o.p,{children:"Similarly, You create a split dropdown by combining the Dropdown\ncomponents with another Button and a ButtonGroup."}),"\n",(0,t.jsx)(b,{language:"jsx",live:!0,children:h}),"\n",(0,t.jsxs)(o.p,{children:["As with DropdownButton, ",(0,t.jsx)(o.code,{children:"SplitButton"})," is provided as\nconvenience component."]}),"\n",(0,t.jsx)(b,{language:"jsx",live:!0,children:v}),"\n",(0,t.jsx)(o.h2,{id:"sizing",children:"Sizing"}),"\n",(0,t.jsx)(o.p,{children:"Dropdowns work with buttons of all sizes."}),"\n",(0,t.jsx)(b,{language:"jsx",live:!0,children:s}),"\n",(0,t.jsx)(o.h2,{id:"dark-dropdowns",children:"Dark dropdowns"}),"\n",(0,t.jsxs)(o.p,{children:["Opt into darker dropdowns to match a dark navbar or custom style by adding\n",(0,t.jsx)(o.code,{children:'variant="dark"'})," onto an existing ",(0,t.jsx)(o.code,{children:"DropdownMenu"}),". Alternatively, use\n",(0,t.jsx)(o.code,{children:'menuVariant="dark"'})," when using the ",(0,t.jsx)(o.code,{children:"DropdownButton"})," component."]}),"\n",(0,t.jsx)(o.admonition,{title:"Heads up!",type:"caution",children:(0,t.jsxs)(o.p,{children:["Dark variants for components were deprecated in Bootstrap v5.3.0 with the introduction\nof color modes. Instead of adding ",(0,t.jsx)(o.code,{children:'variant="dark"'}),", set ",(0,t.jsx)(o.code,{children:'data-bs-theme="dark"'})," on the root\nelement, a parent wrapper, or the component itself."]})}),"\n",(0,t.jsx)(b,{language:"jsx",live:!0,children:x}),"\n",(0,t.jsxs)(o.p,{children:["Using ",(0,t.jsx)(o.code,{children:'menuVariant="dark"'})," in a ",(0,t.jsx)(o.code,{children:"NavDropdown"}),":"]}),"\n",(0,t.jsx)(b,{language:"jsx",live:!0,children:I}),"\n",(0,t.jsx)(o.h2,{id:"drop-directions",children:"Drop directions"}),"\n",(0,t.jsxs)(o.p,{children:["Trigger dropdown menus above, below, left, or to the right of their\ntoggle elements, with the ",(0,t.jsx)(o.code,{children:"drop"})," prop."]}),"\n",(0,t.jsx)(b,{language:"jsx",live:!0,children:l}),"\n",(0,t.jsx)(o.h2,{id:"dropdown-items",children:"Dropdown items"}),"\n",(0,t.jsxs)(o.p,{children:["Historically dropdown menu contents had to be links, but that\u2019s no\nlonger the case with v4. Now you can optionally use\n",(0,t.jsx)(o.code,{children:"