Ba dropdowns ya kokita
Bobongola ba superpositions contextuelles mpo na kolakisa ba liste ya ba liens mpe mingi na plugin ya kokita ya Bootstrap.
Ba dropdowns ezali toggleable, ba overlays contextuels mpo na kolakisa ba liste ya ba liens mpe mingi mosusu. Bazali kosala interactive na plugin ya JavaScript oyo ezali kokita ya Bootstrap oyo ezali na kati. Bazali ko toggled na ko cliquer, na ko hover te; oyo ezali ekateli ya kosala na mokano.
Ba dropdowns etongami na bibliothèque ya troisième partie, Popper.js , oyo epesaka positionnement dynamique mpe détection ya port de vue. Sala makasi otia popper.min.js liboso ya JavaScript ya Bootstrap to salela bootstrap.bundle.min.js
/ bootstrap.bundle.js
oyo ezali na Popper.js. Popper.js esalelamaka te mpo na ko positionner ba dropdowns na ba navbars atako lokola positionnement dynamique esengeli te.
Soki ozali kotonga JavaScript na biso uta na source, esengiutil.js
.
Norme WAI ARIA elimboli role="menu"
widget ya solo , kasi oyo ezali ya sikisiki na ba menu lokola ya bosaleli oyo ebandisaka misala to misala. Ba menu ya ARIA ekoki kozala kaka na biloko ya menu, biloko ya menu ya case ya kotiya elembo, biloko ya menu ya bouton ya radio, bituluku ya bouton ya radio, mpe ba sous-menu.
Ba dropdowns ya Bootstrap, na ngambo mosusu, esalemi mpo na kozala générique mpe ekoki kosalelama na ba situations ndenge na ndenge mpe na ba structures ya marquage. Na ndakisa, ezali na nzela ya kosala ba dropdowns oyo ezali na ba entrées ya kobakisa mpe ba contrôles ya formulaire, lokola ba champs ya recherche to ba formulaires ya login. Mpo na ntina oyo, Bootstrap ezali kozela te (to kobakisa na ndenge ya automatique) moko ya role
mpe aria-
bizaleli oyo esengeli mpo na ba menu ya solosolo ya ARIA . Bakomi bakosengela kokɔtisa bango moko bizaleli wana ya sikisiki mingi.
Kasi, Bootstrap ebakisi lisungi oyo etongami na kati mpo na mingi ya boyokani ya menu ya klaviatware ya momesano, lokola makoki ya kotambola na kati ya .dropdown-item
biloko mokomoko na kosaleláká bafungola ya kursɛrɛ mpe kokanga menu na ESCfungola.
Envelopper toggle ya dropdown (bouton to lien na yo) mpe menu ya dropdown na kati ya .dropdown
, to élément mosusu oyo esakoli position: relative;
. Ba dropdowns ekoki kozala déclenché à partir ya <a>
to <button>
ba éléments mpo na ko correspondre malamu na ba besoins na yo potentiels.
Single nyonso .btn
ekoki kobongwana na toggle ya kokita na mwa mbongwana ya bilembo. Tala ndenge okoki kotia bango na mosala na ba <button>
éléments moko to mosusu:
<div class="dropdown">
<button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown button
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</div>
Mpe na <a>
biloko oyo:
<div class="dropdown show">
<a class="btn btn-secondary dropdown-toggle" href="#" role="button" id="dropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown link
</a>
<div class="dropdown-menu" aria-labelledby="dropdownMenuLink">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</div>
Eteni ya malamu ezali ete okoki kosala yango na variante nyonso ya bouton, mpe:
Ndenge moko mpe, sala ba dropdowns ya bouton split na marque presque moko na ba dropdowns ya bouton moko, kasi na kobakisa ya .dropdown-toggle-split
mpo na espacement malamu zingazinga ya caret ya dropdown.
Tosalelaka kelasi oyo ya likolo mpo na kokitisa horizontal padding
na ngambo nyonso mibale ya caret na 25% mpe kolongola margin-left
oyo ebakisami mpo na ba dropdowns ya bouton ya mbala na mbala. Mbongwana wana ya kobakisa ebatelaka caret na katikati na bouton ya kokabola mpe epesaka esika ya kobɛta oyo ezali na bonene oyo ebongi mpenza pembeni ya bouton monene.
Ba boutons oyo ezali kokita esalaka na ba boutons ya bonene nyonso, bakisa mpe ba boutons oyo ezali kokita mpe oyo ekabwani.
Déclenchez ba menu déroulant likolo ya ba éléments na kobakisa .dropup
na élément parent.
Déclenchez ba menu déroulant na droite ya ba éléments na kobakisa .dropright
na élément parent.
Déclenchez ba menu déroulant na gauche ya ba éléments na kobakisa .dropleft
na élément parent.
Historiquement ba contenus ya menu déroulant esengelaki ezala ba liens, mais ezali lisusu bongo te na v4. Sikoyo okoki kosalela optionnellement ba <button>
éléments na ba dropdowns na yo au lieu ya kaka <a>
s.
<div class="dropdown">
<button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenu2" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenu2">
<button class="dropdown-item" type="button">Action</button>
<button class="dropdown-item" type="button">Another action</button>
<button class="dropdown-item" type="button">Something else here</button>
</div>
</div>
Na ndenge ya libela, menu oyo ezali kokita ezali kotyama automatiquement 100% kobanda na likoló mpe na ngámbo ya lobɔkɔ ya mwasi ya moboti na yango. Bakisa .dropdown-menu-right
na a .dropdown-menu
na droite aligner menu oyo ezali kokita.
Mitó likoló! Ba dropdowns e positionné grâce na Popper.js (sauf soki ezali na kati ya navbar).
<div class="btn-group">
<button type="button" class="btn btn-secondary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Right-aligned menu
</button>
<div class="dropdown-menu dropdown-menu-right">
<button class="dropdown-item" type="button">Action</button>
<button class="dropdown-item" type="button">Another action</button>
<button class="dropdown-item" type="button">Something else here</button>
</div>
</div>
Bakisa motó mpo na kotya bilembo na biteni ya misala na menu nyonso oyo ezali kokita.
<div class="dropdown-menu">
<h6 class="dropdown-header">Dropdown header</h6>
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
</div>
Kabola bituluku ya biloko ya menu oyo ezali na boyokani na yango na nzela ya kokabola.
<div class="dropdown-menu">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Separated link</a>
</div>
Tia formulaire moko na kati ya menu oyo ezali kokita, to sala yango na menu oyo ezali kokita, mpe salelá ba utilitaires ya marge to ya padding mpo na kopesa yango esika ya mabe oyo osengeli na yango.
<div class="dropdown-menu">
<form class="px-4 py-3">
<div class="form-group">
<label for="exampleDropdownFormEmail1">Email address</label>
<input type="email" class="form-control" id="exampleDropdownFormEmail1" placeholder="[email protected]">
</div>
<div class="form-group">
<label for="exampleDropdownFormPassword1">Password</label>
<input type="password" class="form-control" id="exampleDropdownFormPassword1" placeholder="Password">
</div>
<div class="form-check">
<input type="checkbox" class="form-check-input" id="dropdownCheck">
<label class="form-check-label" for="dropdownCheck">
Remember me
</label>
</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="form-group">
<label for="exampleDropdownFormEmail2">Email address</label>
<input type="email" class="form-control" id="exampleDropdownFormEmail2" placeholder="[email protected]">
</div>
<div class="form-group">
<label for="exampleDropdownFormPassword2">Password</label>
<input type="password" class="form-control" id="exampleDropdownFormPassword2" placeholder="Password">
</div>
<div class="form-check">
<input type="checkbox" class="form-check-input" id="dropdownCheck2">
<label class="form-check-label" for="dropdownCheck2">
Remember me
</label>
</div>
<button type="submit" class="btn btn-primary">Sign in</button>
</form>
Bakisa .active
na biloko oyo ezali na dropdown mpo na kosala style na yango lokola active .
<div class="dropdown-menu">
<a class="dropdown-item" href="#">Regular link</a>
<a class="dropdown-item active" href="#">Active link</a>
<a class="dropdown-item" href="#">Another link</a>
</div>
Bakisa .disabled
na biloko na dropdown mpo na kosala style na yango lokola désactivé .
<div class="dropdown-menu">
<a class="dropdown-item" href="#">Regular link</a>
<a class="dropdown-item disabled" href="#">Disabled link</a>
<a class="dropdown-item" href="#">Another link</a>
</div>
Na nzela ya ba attributs ya ba données to JavaScript, plugin oyo ezali kokita ebalusaka makambo oyo ebombami (ba menu oyo ezali kokita) na kobongola .show
kelasi na eloko ya liste ya baboti. Attribut data-toggle="dropdown"
etie motema mpo na kokanga ba menu ya kokita na niveau ya application, yango wana ezali likanisi malamu kosalela yango ntango nyonso.
Na ba appareils oyo ekoki ko toucher, kofungola dropdown ebakisi ba handlers ya pamba ( $.noop
) na bana ya mbala moko ya élément. This admittedly ugly hack is necessary to work around a quirk in iOS’ event delegation , oyo soki te elingaki kopekisa robinet esika nyonso libanda ya dropdown e déclencher code oyo ekanga dropdown. Soki kaka dropdown ekangami, ba handlers oyo ya pamba ya kobakisa elongolamaka.mouseover
<body>
mouseover
Bakisa data-toggle="dropdown"
na lien to na bouton mpo na kobongola esika oyo ezali kokita.
Benga ba dropdowns na nzela ya JavaScript:
data-toggle="dropdown"
esɛngami naino
Indépendamment soki obengi dropdown na yo na nzela ya JavaScript to na esika na yango kosalela data-api, data-toggle="dropdown"
esengeli ntango nyonso kozala présent na élément déclencheur ya dropdown.
Ba options ekoki koleka na nzela ya ba attributs ya ba données to JavaScript. Mpo na ba attributs ya ba données, bakisa kombo ya option na data-
, lokola na data-offset=""
.
Nkombo | Lolenge | Mbeba | Ndimbola |
---|---|---|---|
offset ya kosala | motango | molongo ya molongo | mosala | 0. | Offset ya dropdown par rapport na cible na yango. Mpo na koyeba makambo mingi tala Docs ya offset ya Popper.js . |
kobalusa | boolean | ya solo | Tika Dropdown ebalusa na cas ya superposition na élément ya référence. Mpo na koyeba makambo mingi tala na flip docs ya Popper.js . |
ndelo ya mboka | molongo ya molongo | eloko | 'moboti ya défilement'. | Frontière ya contrainte ya débordement ya menu oyo ezali kokita. Endimi motuya ya 'viewport' , 'window' , 'scrollParent' , to référence ya HTMLElement (JavaScript kaka). Mpo na koyeba makambo mingi tala ba docs ya preventOverflow ya Popper.js . |
Yeba ntango boundary
etiamaki na motuya mosusu longola se 'scrollParent'
, lolenge position: static
esalelami na eloko ya .dropdown
kobomba.
Metode | Ndimbola |
---|---|
$().dropdown('toggle') |
Ezali kobongola menu oyo ezali kokita ya navbar to navigation oyo ezali na onglet oyo epesami. |
$().dropdown('update') |
Ezali kosala mikolo oyo position ya dropdown ya élément moko. |
$().dropdown('dispose') |
Ebebisaka dropdown ya élément moko. |
Ba événements nionso ya dropdown ezo betama na .dropdown-menu
élément parent ya 's pe eza na relatedTarget
propriété, oyo valeur na yango eza élément anchor toggling.
Likambo | Ndimbola |
---|---|
show.bs.dropdown |
Evenement oyo ezo beta mbala moko tango méthode ya instance ya kolakisa ebengami. |
shown.bs.dropdown |
Evenement oyo ezo beta tango dropdown esalemi komonana na mosaleli (ekozela ba transitions ya CSS, mpo esila). |
hide.bs.dropdown |
Evenement oyo ezo beta mbala moko tango méthode ya instance ya kobomba ebengami. |
hidden.bs.dropdown |
Evenement oyo ezo beta tango dropdown esili kobombama na mosaleli (ekozela ba transitions ya CSS, mpo esila). |