Kunjuzi
Geuza viwekeleo vya muktadha kwa ajili ya kuonyesha orodha za viungo na zaidi ukitumia programu-jalizi ya kunjuzi ya Bootstrap.
Muhtasari
Kunjuzi zinaweza kugeuzwa, ziwekelezwe za kimuktadha kwa ajili ya kuonyesha orodha za viungo na zaidi. Yamefanywa kuingiliana na programu-jalizi ya kunjuzi ya Bootstrap iliyojumuishwa ya JavaScript. Zinabadilishwa kwa kubofya, sio kwa kuelea; huu ni uamuzi wa kimakusudi wa kubuni .
Kunjuzi hujengwa kwenye maktaba ya wahusika wengine, Popper , ambayo hutoa nafasi inayobadilika na ugunduzi wa sehemu ya kutazama. Hakikisha kuwa umejumuisha popper.min.js kabla ya JavaScript ya Bootstrap au tumia bootstrap.bundle.min.js
/ bootstrap.bundle.js
ambayo ina Popper. Popper haitumiwi kuweka menyu kunjuzi katika pau za urambazaji ingawa kwa vile nafasi inayobadilika haihitajiki.
Ufikivu
Kiwango cha WAI ARIA kinafafanua role="menu"
wijeti halisi , lakini hii ni mahususi kwa menyu zinazofanana na programu ambazo huanzisha vitendo au utendakazi. Menyu za ARIA zinaweza tu kuwa na vipengee vya menyu, vipengee vya menyu ya kisanduku cha kuteua, vipengee vya menyu ya vitufe vya redio, vikundi vya vitufe vya redio na menyu ndogo.
Kunjuzi za Bootstrap, kwa upande mwingine, zimeundwa kuwa za jumla na zinazotumika kwa hali mbalimbali na miundo ya kuashiria. Kwa mfano, inawezekana kuunda menyu kunjuzi ambazo zina pembejeo za ziada na vidhibiti vya fomu, kama vile sehemu za utafutaji au fomu za kuingia. Kwa sababu hii, Bootstrap haitarajii (wala kuongeza kiotomatiki) yoyote ya role
na aria-
sifa zinazohitajika kwa menyu za kweli za ARIA . Waandishi watalazimika kujumuisha sifa hizi mahususi wenyewe.
Walakini, Bootstrap haiongezei usaidizi uliojumuishwa ndani kwa mwingiliano mwingi wa menyu ya kibodi, kama vile uwezo wa kusogea kupitia .dropdown-item
vipengee mahususi kwa kutumia vitufe vya kishale na kufunga menyu kwa ESCufunguo.
Mifano
Funga kigeuzi cha menyu kunjuzi (kitufe au kiungo chako) na menyu kunjuzi ndani ya .dropdown
, au kipengele kingine kinachotangaza position: relative;
. Kunjuzi kunaweza kuanzishwa kutoka <a>
au <button>
vipengee ili kutosheleza mahitaji yako yanayoweza kutokea. Mifano iliyoonyeshwa hapa hutumia <ul>
vipengele vya kisemantiki inapofaa, lakini uwekaji alama maalum unaauniwa.
Kitufe kimoja
Single yoyote .btn
inaweza kugeuzwa kuwa menyu kunjuzi na mabadiliko kadhaa ya alama. Hivi ndivyo unavyoweza kuziweka kufanya kazi na <button>
vipengele vyovyote:
<div class="dropdown">
<button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton1" data-bs-toggle="dropdown" aria-expanded="false">
Dropdown button
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenuButton1">
<li><a class="dropdown-item" href="#">Action</a></li>
<li><a class="dropdown-item" href="#">Another action</a></li>
<li><a class="dropdown-item" href="#">Something else here</a></li>
</ul>
</div>
Na <a>
vipengele:
<div class="dropdown">
<a class="btn btn-secondary dropdown-toggle" href="#" role="button" id="dropdownMenuLink" data-bs-toggle="dropdown" aria-expanded="false">
Dropdown link
</a>
<ul class="dropdown-menu" aria-labelledby="dropdownMenuLink">
<li><a class="dropdown-item" href="#">Action</a></li>
<li><a class="dropdown-item" href="#">Another action</a></li>
<li><a class="dropdown-item" href="#">Something else here</a></li>
</ul>
</div>
Sehemu bora ni kwamba unaweza kufanya hivyo na lahaja yoyote ya kitufe, pia:
<!-- Example single danger button -->
<div class="btn-group">
<button type="button" class="btn btn-danger dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
Action
</button>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="#">Action</a></li>
<li><a class="dropdown-item" href="#">Another action</a></li>
<li><a class="dropdown-item" href="#">Something else here</a></li>
<li><hr class="dropdown-divider"></li>
<li><a class="dropdown-item" href="#">Separated link</a></li>
</ul>
</div>
Kitufe cha kugawanya
Vile vile, unda menyu kunjuzi ya vitufe vya mgawanyiko kwa karibu alama sawa na menyu kunjuzi ya kitufe kimoja, lakini kwa kuongezwa .dropdown-toggle-split
kwa nafasi ifaayo kuzunguka sehemu ya kunjuzi.
Tunatumia darasa hili la ziada ili kupunguza mlalo padding
kwa kila upande wa caret kwa 25% na kuondoa margin-left
ile iliyoongezwa kwa kunjuzi za vitufe vya kawaida. Mabadiliko hayo ya ziada huweka caret katikati ya kitufe cha mgawanyiko na kutoa eneo la kugonga la ukubwa unaofaa zaidi karibu na kitufe kikuu.
<!-- Example split danger button -->
<div class="btn-group">
<button type="button" class="btn btn-danger">Action</button>
<button type="button" class="btn btn-danger dropdown-toggle dropdown-toggle-split" data-bs-toggle="dropdown" aria-expanded="false">
<span class="visually-hidden">Toggle Dropdown</span>
</button>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="#">Action</a></li>
<li><a class="dropdown-item" href="#">Another action</a></li>
<li><a class="dropdown-item" href="#">Something else here</a></li>
<li><hr class="dropdown-divider"></li>
<li><a class="dropdown-item" href="#">Separated link</a></li>
</ul>
</div>
Ukubwa
Vitufe kunjuzi hufanya kazi na vitufe vya ukubwa wote, ikiwa ni pamoja na vitufe vya chaguo-msingi na vilivyogawanyika.
<!-- Large button groups (default and split) -->
<div class="btn-group">
<button class="btn btn-secondary btn-lg dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
Large button
</button>
<ul class="dropdown-menu">
...
</ul>
</div>
<div class="btn-group">
<button class="btn btn-secondary btn-lg" type="button">
Large split button
</button>
<button type="button" class="btn btn-lg btn-secondary dropdown-toggle dropdown-toggle-split" data-bs-toggle="dropdown" aria-expanded="false">
<span class="visually-hidden">Toggle Dropdown</span>
</button>
<ul class="dropdown-menu">
...
</ul>
</div>
<div class="btn-group">
<button class="btn btn-secondary btn-sm dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
Small button
</button>
<ul class="dropdown-menu">
...
</ul>
</div>
<div class="btn-group">
<button class="btn btn-secondary btn-sm" type="button">
Small split button
</button>
<button type="button" class="btn btn-sm btn-secondary dropdown-toggle dropdown-toggle-split" data-bs-toggle="dropdown" aria-expanded="false">
<span class="visually-hidden">Toggle Dropdown</span>
</button>
<ul class="dropdown-menu">
...
</ul>
</div>
Kushuka kwa giza
Chagua katika menyu kunjuzi nyeusi zaidi ili kulinganisha upau wa urambazaji wa giza au mtindo maalum kwa kuongeza .dropdown-menu-dark
kwenye iliyopo .dropdown-menu
. Hakuna mabadiliko yanayohitajika kwa vipengee kunjuzi.
<div class="dropdown">
<button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton2" data-bs-toggle="dropdown" aria-expanded="false">
Dropdown button
</button>
<ul class="dropdown-menu dropdown-menu-dark" aria-labelledby="dropdownMenuButton2">
<li><a class="dropdown-item active" href="#">Action</a></li>
<li><a class="dropdown-item" href="#">Another action</a></li>
<li><a class="dropdown-item" href="#">Something else here</a></li>
<li><hr class="dropdown-divider"></li>
<li><a class="dropdown-item" href="#">Separated link</a></li>
</ul>
</div>
Na kuiweka kutumia kwenye upau wa urambazaji:
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container-fluid">
<a class="navbar-brand" href="#">Navbar</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNavDarkDropdown" aria-controls="navbarNavDarkDropdown" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNavDarkDropdown">
<ul class="navbar-nav">
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDarkDropdownMenuLink" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Dropdown
</a>
<ul class="dropdown-menu dropdown-menu-dark" aria-labelledby="navbarDarkDropdownMenuLink">
<li><a class="dropdown-item" href="#">Action</a></li>
<li><a class="dropdown-item" href="#">Another action</a></li>
<li><a class="dropdown-item" href="#">Something else here</a></li>
</ul>
</li>
</ul>
</div>
</div>
</nav>
Maelekezo
RTL
Maelekezo yanaangaziwa wakati wa kutumia Bootstrap katika RTL, maana .dropstart
itaonekana upande wa kulia.
Kuacha
Anzisha menyu kunjuzi zilizo juu ya vipengee kwa kuongeza .dropup
kwenye kipengee kikuu.
<!-- Default dropup button -->
<div class="btn-group dropup">
<button type="button" class="btn btn-secondary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
Dropup
</button>
<ul class="dropdown-menu">
<!-- Dropdown menu links -->
</ul>
</div>
<!-- Split dropup button -->
<div class="btn-group dropup">
<button type="button" class="btn btn-secondary">
Split dropup
</button>
<button type="button" class="btn btn-secondary dropdown-toggle dropdown-toggle-split" data-bs-toggle="dropdown" aria-expanded="false">
<span class="visually-hidden">Toggle Dropdown</span>
</button>
<ul class="dropdown-menu">
<!-- Dropdown menu links -->
</ul>
</div>
Dropright
Anzisha menyu kunjuzi zilizo upande wa kulia wa vipengee kwa kuongeza .dropend
kwenye kipengele kikuu.
<!-- Default dropend button -->
<div class="btn-group dropend">
<button type="button" class="btn btn-secondary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
Dropright
</button>
<ul class="dropdown-menu">
<!-- Dropdown menu links -->
</ul>
</div>
<!-- Split dropend button -->
<div class="btn-group dropend">
<button type="button" class="btn btn-secondary">
Split dropend
</button>
<button type="button" class="btn btn-secondary dropdown-toggle dropdown-toggle-split" data-bs-toggle="dropdown" aria-expanded="false">
<span class="visually-hidden">Toggle Dropright</span>
</button>
<ul class="dropdown-menu">
<!-- Dropdown menu links -->
</ul>
</div>
Dropleft
Anzisha menyu kunjuzi zilizo upande wa kushoto wa vipengee kwa kuongeza .dropstart
kwenye kipengele kikuu.
<!-- Default dropstart button -->
<div class="btn-group dropstart">
<button type="button" class="btn btn-secondary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
Dropstart
</button>
<ul class="dropdown-menu">
<!-- Dropdown menu links -->
</ul>
</div>
<!-- Split dropstart button -->
<div class="btn-group">
<div class="btn-group dropstart" role="group">
<button type="button" class="btn btn-secondary dropdown-toggle dropdown-toggle-split" data-bs-toggle="dropdown" aria-expanded="false">
<span class="visually-hidden">Toggle Dropstart</span>
</button>
<ul class="dropdown-menu">
<!-- Dropdown menu links -->
</ul>
</div>
<button type="button" class="btn btn-secondary">
Split dropstart
</button>
</div>
Vipengee vya menyu
Unaweza kutumia <a>
au <button>
vipengele kama vitu kunjuzi.
<div class="dropdown">
<button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenu2" data-bs-toggle="dropdown" aria-expanded="false">
Dropdown
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenu2">
<li><button class="dropdown-item" type="button">Action</button></li>
<li><button class="dropdown-item" type="button">Another action</button></li>
<li><button class="dropdown-item" type="button">Something else here</button></li>
</ul>
</div>
Unaweza pia kuunda vipengee kunjuzi visivyoingiliana ukitumia .dropdown-item-text
. Jisikie huru kuweka mtindo zaidi ukitumia CSS maalum au huduma za maandishi.
<ul class="dropdown-menu">
<li><span class="dropdown-item-text">Dropdown item text</span></li>
<li><a class="dropdown-item" href="#">Action</a></li>
<li><a class="dropdown-item" href="#">Another action</a></li>
<li><a class="dropdown-item" href="#">Something else here</a></li>
</ul>
Inayotumika
Ongeza .active
kwa vipengee katika menyu kunjuzi ili kuvifanya kuwa vinavyotumika . Ili kuwasilisha hali amilifu kwa teknolojia saidizi, tumia aria-current
sifa - kwa kutumia page
thamani ya ukurasa wa sasa, au true
kwa kipengee cha sasa katika seti.
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="#">Regular link</a></li>
<li><a class="dropdown-item active" href="#" aria-current="true">Active link</a></li>
<li><a class="dropdown-item" href="#">Another link</a></li>
</ul>
Imezimwa
Ongeza .disabled
kwa vipengee katika menyu kunjuzi ili kuvifanya kuwa vimezimwa .
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="#">Regular link</a></li>
<li><a class="dropdown-item disabled" href="#" tabindex="-1" aria-disabled="true">Disabled link</a></li>
<li><a class="dropdown-item" href="#">Another link</a></li>
</ul>
Mpangilio wa menyu
Kwa chaguomsingi, menyu kunjuzi huwekwa kiotomatiki 100% kutoka juu na upande wa kushoto wa mzazi wake. Unaweza kubadilisha hii na .drop*
madarasa ya mwelekeo, lakini unaweza pia kuwadhibiti na madarasa ya ziada ya kurekebisha.
Ongeza .dropdown-menu-end
kwenye a .dropdown-menu
panga menyu kunjuzi. Maelekezo yanaangaziwa wakati wa kutumia Bootstrap katika RTL, maana .dropdown-menu-end
itaonekana kwenye upande wa kushoto.
<div class="btn-group">
<button type="button" class="btn btn-secondary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
Right-aligned menu example
</button>
<ul class="dropdown-menu dropdown-menu-end">
<li><button class="dropdown-item" type="button">Action</button></li>
<li><button class="dropdown-item" type="button">Another action</button></li>
<li><button class="dropdown-item" type="button">Something else here</button></li>
</ul>
</div>
Mpangilio wa kuitikia
Iwapo ungependa kutumia upatanishi unaoitikia, zima uwekaji unaobadilika kwa kuongeza data-bs-display="static"
sifa na utumie aina za utofauti zinazoitikia.
Ili kuoanisha menyu kunjuzi na kikomo ulichopewa au kubwa zaidi, ongeza .dropdown-menu{-sm|-md|-lg|-xl|-xxl}-end
.
<div class="btn-group">
<button type="button" class="btn btn-secondary dropdown-toggle" data-bs-toggle="dropdown" data-bs-display="static" aria-expanded="false">
Left-aligned but right aligned when large screen
</button>
<ul class="dropdown-menu dropdown-menu-lg-end">
<li><button class="dropdown-item" type="button">Action</button></li>
<li><button class="dropdown-item" type="button">Another action</button></li>
<li><button class="dropdown-item" type="button">Something else here</button></li>
</ul>
</div>
Ili kupangilia kushoto menyu kunjuzi na kikomo ulichopewa au kubwa zaidi, ongeza .dropdown-menu-end
na .dropdown-menu{-sm|-md|-lg|-xl|-xxl}-start
.
<div class="btn-group">
<button type="button" class="btn btn-secondary dropdown-toggle" data-bs-toggle="dropdown" data-bs-display="static" aria-expanded="false">
Right-aligned but left aligned when large screen
</button>
<ul class="dropdown-menu dropdown-menu-end dropdown-menu-lg-start">
<li><button class="dropdown-item" type="button">Action</button></li>
<li><button class="dropdown-item" type="button">Another action</button></li>
<li><button class="dropdown-item" type="button">Something else here</button></li>
</ul>
</div>
Kumbuka kuwa hauitaji kuongeza data-bs-display="static"
sifa kwenye vitufe vya kunjuzi kwenye pau za urambazaji, kwa kuwa Popper haitumiki kwenye upau wa urambazaji.
Chaguzi za upatanishi
Kwa kuchukua chaguo nyingi zilizoonyeshwa hapo juu, hapa kuna onyesho dogo la sinki la jikoni la chaguo mbalimbali za kupanga kunjuzi katika sehemu moja.
<div class="btn-group">
<button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-bs-toggle="dropdown" aria-expanded="false">
Dropdown
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<li><a class="dropdown-item" href="#">Menu item</a></li>
<li><a class="dropdown-item" href="#">Menu item</a></li>
<li><a class="dropdown-item" href="#">Menu item</a></li>
</ul>
</div>
<div class="btn-group">
<button type="button" class="btn btn-secondary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
Right-aligned menu
</button>
<ul class="dropdown-menu dropdown-menu-end">
<li><a class="dropdown-item" href="#">Menu item</a></li>
<li><a class="dropdown-item" href="#">Menu item</a></li>
<li><a class="dropdown-item" href="#">Menu item</a></li>
</ul>
</div>
<div class="btn-group">
<button type="button" class="btn btn-secondary dropdown-toggle" data-bs-toggle="dropdown" data-bs-display="static" aria-expanded="false">
Left-aligned, right-aligned lg
</button>
<ul class="dropdown-menu dropdown-menu-lg-end">
<li><a class="dropdown-item" href="#">Menu item</a></li>
<li><a class="dropdown-item" href="#">Menu item</a></li>
<li><a class="dropdown-item" href="#">Menu item</a></li>
</ul>
</div>
<div class="btn-group">
<button type="button" class="btn btn-secondary dropdown-toggle" data-bs-toggle="dropdown" data-bs-display="static" aria-expanded="false">
Right-aligned, left-aligned lg
</button>
<ul class="dropdown-menu dropdown-menu-end dropdown-menu-lg-start">
<li><a class="dropdown-item" href="#">Menu item</a></li>
<li><a class="dropdown-item" href="#">Menu item</a></li>
<li><a class="dropdown-item" href="#">Menu item</a></li>
</ul>
</div>
<div class="btn-group dropstart">
<button type="button" class="btn btn-secondary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
Dropstart
</button>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="#">Menu item</a></li>
<li><a class="dropdown-item" href="#">Menu item</a></li>
<li><a class="dropdown-item" href="#">Menu item</a></li>
</ul>
</div>
<div class="btn-group dropend">
<button type="button" class="btn btn-secondary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
Dropend
</button>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="#">Menu item</a></li>
<li><a class="dropdown-item" href="#">Menu item</a></li>
<li><a class="dropdown-item" href="#">Menu item</a></li>
</ul>
</div>
<div class="btn-group dropup">
<button type="button" class="btn btn-secondary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
Dropup
</button>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="#">Menu item</a></li>
<li><a class="dropdown-item" href="#">Menu item</a></li>
<li><a class="dropdown-item" href="#">Menu item</a></li>
</ul>
</div>
Maudhui ya menyu
Vichwa vya habari
Ongeza kichwa ili kuweka lebo sehemu za vitendo katika menyu kunjuzi yoyote.
<ul class="dropdown-menu">
<li><h6 class="dropdown-header">Dropdown header</h6></li>
<li><a class="dropdown-item" href="#">Action</a></li>
<li><a class="dropdown-item" href="#">Another action</a></li>
</ul>
Wagawanyaji
Tenganisha vikundi vya vipengee vya menyu vinavyohusiana na kigawanyaji.
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="#">Action</a></li>
<li><a class="dropdown-item" href="#">Another action</a></li>
<li><a class="dropdown-item" href="#">Something else here</a></li>
<li><hr class="dropdown-divider"></li>
<li><a class="dropdown-item" href="#">Separated link</a></li>
</ul>
Maandishi
Weka maandishi yoyote ya muundo huria ndani ya menyu kunjuzi yenye maandishi na utumie huduma za kuweka nafasi . Kumbuka kuwa utahitaji mitindo ya ziada ya kuweka ukubwa ili kubana upana wa menyu.
<div class="dropdown-menu p-4 text-muted" style="max-width: 200px;">
<p>
Some example text that's free-flowing within the dropdown menu.
</p>
<p class="mb-0">
And this is more example text.
</p>
</div>
Fomu
Weka fomu ndani ya menyu kunjuzi, au uifanye kuwa menyu kunjuzi, na utumie huduma za ukingo au padding ili kuipa nafasi hasi unayohitaji.
<div class="dropdown-menu">
<form class="px-4 py-3">
<div class="mb-3">
<label for="exampleDropdownFormEmail1" class="form-label">Email address</label>
<input type="email" class="form-control" id="exampleDropdownFormEmail1" placeholder="[email protected]">
</div>
<div class="mb-3">
<label for="exampleDropdownFormPassword1" class="form-label">Password</label>
<input type="password" class="form-control" id="exampleDropdownFormPassword1" placeholder="Password">
</div>
<div class="mb-3">
<div class="form-check">
<input type="checkbox" class="form-check-input" id="dropdownCheck">
<label class="form-check-label" for="dropdownCheck">
Remember me
</label>
</div>
</div>
<button type="submit" class="btn btn-primary">Sign in</button>
</form>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">New around here? Sign up</a>
<a class="dropdown-item" href="#">Forgot password?</a>
</div>
<form class="dropdown-menu p-4">
<div class="mb-3">
<label for="exampleDropdownFormEmail2" class="form-label">Email address</label>
<input type="email" class="form-control" id="exampleDropdownFormEmail2" placeholder="[email protected]">
</div>
<div class="mb-3">
<label for="exampleDropdownFormPassword2" class="form-label">Password</label>
<input type="password" class="form-control" id="exampleDropdownFormPassword2" placeholder="Password">
</div>
<div class="mb-3">
<div class="form-check">
<input type="checkbox" class="form-check-input" id="dropdownCheck2">
<label class="form-check-label" for="dropdownCheck2">
Remember me
</label>
</div>
</div>
<button type="submit" class="btn btn-primary">Sign in</button>
</form>
Chaguo kunjuzi
Tumia data-bs-offset
au data-bs-reference
kubadilisha eneo la menyu kunjuzi.
<div class="d-flex">
<div class="dropdown me-1">
<button type="button" class="btn btn-secondary dropdown-toggle" id="dropdownMenuOffset" data-bs-toggle="dropdown" aria-expanded="false" data-bs-offset="10,20">
Offset
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenuOffset">
<li><a class="dropdown-item" href="#">Action</a></li>
<li><a class="dropdown-item" href="#">Another action</a></li>
<li><a class="dropdown-item" href="#">Something else here</a></li>
</ul>
</div>
<div class="btn-group">
<button type="button" class="btn btn-secondary">Reference</button>
<button type="button" class="btn btn-secondary dropdown-toggle dropdown-toggle-split" id="dropdownMenuReference" data-bs-toggle="dropdown" aria-expanded="false" data-bs-reference="parent">
<span class="visually-hidden">Toggle Dropdown</span>
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenuReference">
<li><a class="dropdown-item" href="#">Action</a></li>
<li><a class="dropdown-item" href="#">Another action</a></li>
<li><a class="dropdown-item" href="#">Something else here</a></li>
<li><hr class="dropdown-divider"></li>
<li><a class="dropdown-item" href="#">Separated link</a></li>
</ul>
</div>
</div>
Tabia ya kufunga kiotomatiki
Kwa chaguo-msingi, menyu kunjuzi hufungwa unapobofya ndani au nje ya menyu kunjuzi. Unaweza kutumia autoClose
chaguo kubadilisha tabia hii ya menyu kunjuzi.
<div class="btn-group">
<button class="btn btn-secondary dropdown-toggle" type="button" id="defaultDropdown" data-bs-toggle="dropdown" data-bs-auto-close="true" aria-expanded="false">
Default dropdown
</button>
<ul class="dropdown-menu" aria-labelledby="defaultDropdown">
<li><a class="dropdown-item" href="#">Menu item</a></li>
<li><a class="dropdown-item" href="#">Menu item</a></li>
<li><a class="dropdown-item" href="#">Menu item</a></li>
</ul>
</div>
<div class="btn-group">
<button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuClickableOutside" data-bs-toggle="dropdown" data-bs-auto-close="inside" aria-expanded="false">
Clickable outside
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenuClickableOutside">
<li><a class="dropdown-item" href="#">Menu item</a></li>
<li><a class="dropdown-item" href="#">Menu item</a></li>
<li><a class="dropdown-item" href="#">Menu item</a></li>
</ul>
</div>
<div class="btn-group">
<button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuClickableInside" data-bs-toggle="dropdown" data-bs-auto-close="outside" aria-expanded="false">
Clickable inside
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenuClickableInside">
<li><a class="dropdown-item" href="#">Menu item</a></li>
<li><a class="dropdown-item" href="#">Menu item</a></li>
<li><a class="dropdown-item" href="#">Menu item</a></li>
</ul>
</div>
<div class="btn-group">
<button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuClickable" data-bs-toggle="dropdown" data-bs-auto-close="false" aria-expanded="false">
Manual close
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenuClickable">
<li><a class="dropdown-item" href="#">Menu item</a></li>
<li><a class="dropdown-item" href="#">Menu item</a></li>
<li><a class="dropdown-item" href="#">Menu item</a></li>
</ul>
</div>
Sass
Vigezo
Vigeu kwa menyu kunjuzi zote:
$dropdown-min-width: 10rem;
$dropdown-padding-x: 0;
$dropdown-padding-y: .5rem;
$dropdown-spacer: .125rem;
$dropdown-font-size: $font-size-base;
$dropdown-color: $body-color;
$dropdown-bg: $white;
$dropdown-border-color: rgba($black, .15);
$dropdown-border-radius: $border-radius;
$dropdown-border-width: $border-width;
$dropdown-inner-border-radius: subtract($dropdown-border-radius, $dropdown-border-width);
$dropdown-divider-bg: $dropdown-border-color;
$dropdown-divider-margin-y: $spacer * .5;
$dropdown-box-shadow: $box-shadow;
$dropdown-link-color: $gray-900;
$dropdown-link-hover-color: shade-color($gray-900, 10%);
$dropdown-link-hover-bg: $gray-200;
$dropdown-link-active-color: $component-active-color;
$dropdown-link-active-bg: $component-active-bg;
$dropdown-link-disabled-color: $gray-500;
$dropdown-item-padding-y: $spacer * .25;
$dropdown-item-padding-x: $spacer;
$dropdown-header-color: $gray-600;
$dropdown-header-padding: $dropdown-padding-y $dropdown-item-padding-x;
Vigezo vya kushuka kwa giza :
$dropdown-dark-color: $gray-300;
$dropdown-dark-bg: $gray-800;
$dropdown-dark-border-color: $dropdown-border-color;
$dropdown-dark-divider-bg: $dropdown-divider-bg;
$dropdown-dark-box-shadow: null;
$dropdown-dark-link-color: $dropdown-dark-color;
$dropdown-dark-link-hover-color: $white;
$dropdown-dark-link-hover-bg: rgba($white, .15);
$dropdown-dark-link-active-color: $dropdown-link-active-color;
$dropdown-dark-link-active-bg: $dropdown-link-active-bg;
$dropdown-dark-link-disabled-color: $gray-500;
$dropdown-dark-header-color: $gray-500;
Vigezo vya matunzo kulingana na CSS ambavyo vinaonyesha mwingiliano wa menyu kunjuzi:
$caret-width: .3em;
$caret-vertical-align: $caret-width * .85;
$caret-spacing: $caret-width * .85;
Mchanganyiko
Mchanganyiko hutumika kutengeneza matunzo yenye msingi wa CSS na yanaweza kupatikana katika scss/mixins/_caret.scss
.
@mixin caret-down {
border-top: $caret-width solid;
border-right: $caret-width solid transparent;
border-bottom: 0;
border-left: $caret-width solid transparent;
}
@mixin caret-up {
border-top: 0;
border-right: $caret-width solid transparent;
border-bottom: $caret-width solid;
border-left: $caret-width solid transparent;
}
@mixin caret-end {
border-top: $caret-width solid transparent;
border-right: 0;
border-bottom: $caret-width solid transparent;
border-left: $caret-width solid;
}
@mixin caret-start {
border-top: $caret-width solid transparent;
border-right: $caret-width solid;
border-bottom: $caret-width solid transparent;
}
@mixin caret($direction: down) {
@if $enable-caret {
&::after {
display: inline-block;
margin-left: $caret-spacing;
vertical-align: $caret-vertical-align;
content: "";
@if $direction == down {
@include caret-down();
} @else if $direction == up {
@include caret-up();
} @else if $direction == end {
@include caret-end();
}
}
@if $direction == start {
&::after {
display: none;
}
&::before {
display: inline-block;
margin-right: $caret-spacing;
vertical-align: $caret-vertical-align;
content: "";
@include caret-start();
}
}
&:empty::after {
margin-left: 0;
}
}
}
Matumizi
Kupitia sifa za data au JavaScript, programu-jalizi kunjuzi hugeuza maudhui yaliyofichwa (menu kunjuzi) kwa kugeuza .show
darasa kwenye mzazi .dropdown-menu
. Sifa data-bs-toggle="dropdown"
hiyo inategemewa kwa kufunga menyu kunjuzi katika kiwango cha programu, kwa hivyo ni wazo nzuri kuitumia kila wakati.
mouseover
vidhibiti tupu kwa watoto wa karibu wa
<body>
kipengele. Udukuzi huu mbaya unaokubalika ni muhimu ili kutatua tatizo
katika ujumbe wa tukio la iOS , ambalo lingezuia kugusa popote nje ya menyu kunjuzi kuanzisha msimbo unaofunga menyu kunjuzi. Mara tu menyu kunjuzi itakapofungwa, vidhibiti tupu hivi vya ziada
mouseover
huondolewa.
Kupitia sifa za data
Ongeza data-bs-toggle="dropdown"
kwenye kiungo au kitufe ili kugeuza menyu kunjuzi.
<div class="dropdown">
<button id="dLabel" type="button" data-bs-toggle="dropdown" aria-expanded="false">
Dropdown trigger
</button>
<ul class="dropdown-menu" aria-labelledby="dLabel">
...
</ul>
</div>
Kupitia JavaScript
Piga kushuka kupitia JavaScript:
var dropdownElementList = [].slice.call(document.querySelectorAll('.dropdown-toggle'))
var dropdownList = dropdownElementList.map(function (dropdownToggleEl) {
return new bootstrap.Dropdown(dropdownToggleEl)
})
data-bs-toggle="dropdown"
bado inahitajika
Bila kujali ikiwa unapiga simu kunjuzi yako kupitia JavaScript au badala yake utumie data-api, data-bs-toggle="dropdown"
inahitajika kila wakati kuwepo kwenye kichochezi cha menyu kunjuzi.
Chaguo
Chaguzi zinaweza kupitishwa kupitia sifa za data au JavaScript. Kwa sifa za data, ongeza jina la chaguo kwa data-bs-
, kama katika data-bs-offset=""
. Hakikisha umebadilisha aina ya kipochi cha jina la chaguo kutoka kwa camelCase hadi kebab-kesi wakati wa kupitisha chaguo kupitia sifa za data. Kwa mfano, badala ya kutumia data-bs-autoClose="false"
, tumia data-bs-auto-close="false"
.
Jina | Aina | Chaguomsingi | Maelezo |
---|---|---|---|
boundary |
kamba | kipengele | 'clippingParents' |
Kizuizi cha vipengee vya ziada vya menyu kunjuzi (inatumika tu kwa kirekebishaji cha Popper cha preventOverflow). Kwa chaguo-msingi ni 'clippingParents' na inaweza kukubali rejeleo la HTMLElement (kupitia JavaScript pekee). Kwa maelezo zaidi rejelea hati za detectOverflow za Popper . |
reference |
kamba | kipengele | kitu | 'toggle' |
Kipengele cha marejeleo cha menyu kunjuzi. Hukubali thamani za 'toggle' , 'parent' , rejeleo la Kipengele cha HTML au kitu kinachotoa getBoundingClientRect . Kwa maelezo zaidi rejelea hati za kijenzi za Popper na hati za kipengele pepe . |
display |
kamba | 'dynamic' |
Kwa chaguo-msingi, tunatumia Popper kwa nafasi inayobadilika. Zima hii na static . |
offset |
safu | kamba | kazi | [0, 2] |
Kukabiliana na menyu kunjuzi kulingana na lengo lake. Unaweza kupitisha kamba katika sifa za data na maadili yaliyotenganishwa kwa koma kama: Wakati kipengele cha chaguo za kukokotoa kinapotumiwa kubainisha urekebishaji, huitwa na kitu kilicho na uwekaji wa popper, rejeleo, na miondoko ya popper kama hoja yake ya kwanza. Kipengele cha kuchochea nodi ya DOM hupitishwa kama hoja ya pili. Chaguo la kukokotoa lazima lirudishe safu iliyo na nambari mbili: . Kwa maelezo zaidi rejelea hati za kukabiliana na Popper . |
autoClose |
boolean | kamba | true |
Sanidi tabia ya kufunga kiotomatiki ya menyu kunjuzi:
|
popperConfig |
null | kitu | kazi | null |
Ili kubadilisha usanidi chaguo-msingi wa Bootstrap wa Popper, angalia usanidi wa Popper . Chaguo za kukokotoa zinapotumiwa kuunda usanidi wa Popper, huitwa na kitu ambacho kina usanidi chaguo-msingi wa Bootstrap wa Popper. Inakusaidia kutumia na kuunganisha chaguo-msingi na usanidi wako mwenyewe. Chaguo la kukokotoa lazima lirudishe kipengee cha usanidi kwa Popper. |
Kutumia kipengele napopperConfig
var dropdown = new bootstrap.Dropdown(element, {
popperConfig: function (defaultBsPopperConfig) {
// var newPopperConfig = {...}
// use defaultBsPopperConfig if needed...
// return newPopperConfig
}
})
Mbinu
Njia | Maelezo |
---|---|
toggle |
Hugeuza menyu kunjuzi ya upau wa urambazaji au urambazaji wa kichupo. |
show |
Inaonyesha menyu kunjuzi ya upau wa urambazaji au urambazaji wa kichupo. |
hide |
Huficha menyu kunjuzi ya upau wa urambazaji au urambazaji wa kichupo. |
update |
Husasisha nafasi ya menyu kunjuzi ya kipengee. |
dispose |
Huharibu menyu kunjuzi ya kipengele. (Huondoa data iliyohifadhiwa kwenye kipengele cha DOM) |
getInstance |
Njia tuli ambayo hukuruhusu kupata mfano wa kushuka unaohusishwa na kipengee cha DOM, unaweza kuitumia kama hii:bootstrap.Dropdown.getInstance(element) |
getOrCreateInstance |
Mbinu tuli ambayo inarejesha mfano kunjuzi unaohusishwa na kipengele cha DOM au kuunda kipya endapo hakijaanzishwa. Unaweza kuitumia kama hii:bootstrap.Dropdown.getOrCreateInstance(element) |
Matukio
Matukio yote ya menyu kunjuzi huwashwa kwenye kipengee cha kugeuza na kisha kuwekewa viputo. Kwa hivyo unaweza pia kuongeza wasikilizaji wa tukio kwenye .dropdown-menu
kipengele cha mzazi. hide.bs.dropdown
na hidden.bs.dropdown
matukio yana sifa clickEvent
(tu wakati aina ya Tukio asili ni click
) ambayo ina Kitu cha Tukio cha tukio la kubofya.
Njia | Maelezo |
---|---|
show.bs.dropdown |
Inawaka mara moja wakati njia ya mfano wa onyesho inaitwa. |
shown.bs.dropdown |
Huwashwa wakati menyu kunjuzi imefanywa kuonekana kwa mtumiaji na mabadiliko ya CSS yamekamilika. |
hide.bs.dropdown |
Moto mara moja wakati njia ya mfano wa kujificha imeitwa. |
hidden.bs.dropdown |
Huwashwa wakati menyu kunjuzi imekamilika kufichwa kutoka kwa mtumiaji na ubadilishaji wa CSS umekamilika. |
var myDropdown = document.getElementById('myDropdown')
myDropdown.addEventListener('show.bs.dropdown', function () {
// do something...
})