Ibitonyanga
Kuzuza ibice byuzuye kugirango werekane urutonde rwihuza nibindi hamwe na Bootstrap yamanutse.
Ibitonyanga birashobora guhindagurika, guhuza ibice kugirango werekane urutonde rwihuza nibindi byinshi. Byakozwe muburyo bwimikorere ya Bootstrap yamanutse plugin ya JavaScript. Barahindurwa mukanda, ntabwo ari ukuzunguruka; iki nicyemezo cyo gushushanya nkana.
Ibitonyanga byubatswe kububiko bwibitabo byabandi, Popper.js , itanga umwanya uhagaze hamwe no kureba ibintu. Wemeze gushyiramo popper.min.js mbere ya JavaScript ya Bootstrap cyangwa ukoreshe bootstrap.bundle.min.js
/ bootstrap.bundle.js
irimo Popper.js. Popper.js ntabwo ikoreshwa mugushira ibitonyanga muri navbars nubwo nkibikorwa bya dinamike bidasabwa.
Niba wubaka JavaScript yacu kuva isoko, birasabautil.js
.
Igipimo cya WAI ARIA gisobanura role="menu"
widget ifatika , ariko ibi birihariye kubisabwa-nkibikubiyemo bitera ibikorwa cyangwa imikorere. Ibikubiyemo bya ARIA birashobora gusa kuba bikubiyemo ibintu, kugenzura agasanduku k'ibikubiyemo, ibintu bya radiyo buto ya menu, amatsinda ya buto ya radio, na sub-menus.
Ibitonyanga bya Bootstrap, kurundi ruhande, byashizweho kugirango bibe rusange kandi bikurikizwa mubihe bitandukanye no kuranga imiterere. Kurugero, birashoboka gukora ibitonyanga birimo inyongeramusaruro ninyongera kugenzura, nkibice byo gushakisha cyangwa ifishi yinjira. Kubwiyi mpamvu, Bootstrap ntabwo yiteze (cyangwa guhita yongeraho) icyaricyo cyose role
nibiranga aria-
bisabwa kuri ARIA nyayo . Abanditsi bagomba gushyiramo ibi biranga byihariye ubwabo.
Ariko, Bootstrap yongeramo inkunga-yubufasha bwa menu ya clavier isanzwe ikora, nkubushobozi bwo kunyura .dropdown-item
mubintu bitandukanye ukoresheje urufunguzo rwa indanga no gufunga menu ESCnurufunguzo.
Kuzuza ibimanuka (buto yawe cyangwa ihuza) na menu yamanutse imbere .dropdown
, cyangwa ikindi kintu gitangaza position: relative;
. Ibitonyanga birashobora gukururwa bivuye <a>
cyangwa <button>
ibintu kugirango bihuze neza nibyo ukeneye.
Ikintu icyo aricyo cyose .btn
gishobora guhinduka kumanuka uhindagurika hamwe nibimenyetso byahindutse. Dore uburyo ushobora kubashyira mubikorwa hamwe <button>
nibintu:
<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>
Kandi hamwe <a>
nibintu:
<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>
Igice cyiza nuko ushobora kubikora ukoresheje buto iyo ariyo yose, nayo:
Mu buryo busa nabwo, kora ibice bitandukanya ibice byamanutse hamwe nikimenyetso kimwe kimwe na buto imwe yamanutse, ariko hamwe no kongeramo .dropdown-toggle-split
umwanya ukwiye hafi yigitonyanga.
Dukoresha iri somo ryinyongera kugirango tugabanye horizontal padding
kumpande zombi za caret kuri 25% hanyuma dukureho margin-left
ibyo byongeweho kubisanzwe bya buto. Izo mpinduka zinyongera zituma caret yibanze muri bouton igabanijwe kandi igatanga ahantu hanini cyane hit hitabwa kuruhande rwa buto nkuru.
Utubuto tumanuka dukorana na buto yubunini bwose, harimo nibisanzwe no kugabanura ibitonyanga.
Imbarutso yamanutse iboneka hejuru yibintu wongeyeho .dropup
kubabyeyi.
Imbarutso yamanutse iboneka iburyo bwibintu wongeyeho .dropright
kubabyeyi.
Imbarutso yamanutse iboneka ibumoso bwibintu wongeyeho .dropleft
kubabyeyi.
Amateka yamanutse yibirimo yagombaga kuba amahuza, ariko ibyo ntibikiri kuri v4. Noneho urashobora guhitamo gukoresha <button>
ibintu mumanuka aho gukoresha <a>
s gusa.
<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>
Mburabuzi, menu yamanutse ihita ishyirwa 100% uhereye hejuru no kuruhande rwibumoso rwababyeyi. Ongeraho iburyo .dropdown-menu-right
kugirango .dropdown-menu
uhuze menu yamanutse.
Umutwe! Ibitonyanga byashyizwe kumurongo dukesha Popper.js (usibye iyo bikubiye muri 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>
Ongeraho umutwe kumurango ibice byibikorwa muri menu yamanutse.
<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>
Tandukanya amatsinda yibintu bifitanye isano nibice.
<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>
Shira ifishi muri menu yamanutse, cyangwa uyigire muri menu yamanutse, hanyuma ukoreshe margin cyangwa padding utanga kugirango uhe umwanya mubi ukeneye.
<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>
Ongeraho .active
mubintu mumanuka kugirango ubitondere nkibikorwa .
<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>
Ongeraho .disabled
mubintu biri kumanuka kugirango ubitondere nkuko byahagaritswe .
<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>
Binyuze muri data ibiranga cyangwa JavaScript, plugin yamanutse ihinduranya ibintu byihishe (ibimanuka byamanutse) muguhindura .show
icyiciro kurutonde rwababyeyi. Ikiranga data-toggle="dropdown"
gishingiye ku gufunga ibimanuka kurutonde rwa porogaramu, nibyiza rero guhora tuyikoresha.
Kubikoresho bifasha gukoraho, gufungura ibitonyanga byongeramo ubusa ( $.noop
) mouseover
imashini kubana bahita ba <body>
element. Ibi byemewe ko ari hack birakenewe kugirango dukore hafi yikinamico mu ntumwa za iOS , ibyo bikaba byabuza gukanda ahantu hose hanze y’igitonyanga gukurura code ifunga ibitonyanga. Iyo ibitonyanga bimaze gufungwa, ibyo byongeweho ubusa mouseover
bikurwaho.
Ongeraho data-toggle="dropdown"
kumurongo cyangwa buto kugirango uhindure ibitonyanga.
Hamagara ibitonyanga ukoresheje JavaScript:
data-toggle="dropdown"
biracyasabwa
Utitaye ko wahamagaye ibitonyanga ukoresheje JavaScript cyangwa ugakoresha data-api, data-toggle="dropdown"
burigihe birasabwa kuba uhari kubintu byamanutse.
Amahitamo arashobora kunyuzwa kumurongo wamakuru cyangwa JavaScript. Kubiranga Ibyatanzwe, Ongeraho Ihitamo Izina Kuri data-
, Nka Muri data-offset=""
.
Izina | Andika | Mburabuzi | Ibisobanuro |
---|---|---|---|
offset | umubare | umugozi | imikorere | 0 | Kureka kugabanuka ugereranije nintego yayo. Kubindi bisobanuro reba popper.js ya offset ya doc . |
flip | boolean | ni ukuri | Emerera Ibitonyanga guhindagurika mugihe habaye guhuzagurika kubintu bifatika. Kubindi bisobanuro reba flip docs ya Popper.js . |
imbibi | umugozi | element | 'umuzingoParent' | Kurenga imipaka imbibi za menu yamanutse. Emera indangagaciro za ,,, 'viewport' cyangwa HTMLElement yerekana (JavaScript gusa). Kubindi bisobanuro reba Popper.js yo gukumiraOverflow docs .'window' 'scrollParent' |
Icyitonderwa mugihe boundary
gishyizwe kumurongo uwo ariwo wose usibye 'scrollParent'
, imiterere position: static
ikoreshwa kuri .dropdown
kontineri.
Uburyo | Ibisobanuro |
---|---|
$().dropdown('toggle') |
Kuzuza menu yamanutse ya navbar yatanzwe cyangwa kugendagenda. |
$().dropdown('update') |
Kuvugurura umwanya wibintu byamanutse. |
$().dropdown('dispose') |
Gusenya ikintu cyamanutse. |
Ibintu byose byamanutse birasa kuri .dropdown-menu
'ababyeyi bababyeyi kandi bafite relatedTarget
umutungo, agaciro kabo ni uguhindura icyuma.
Icyabaye | Ibisobanuro |
---|---|
show.bs.dropdown |
Ibirori birasa ako kanya iyo kwerekana urugero uburyo bwitwa. |
shown.bs.dropdown |
Ibirori birukanwa mugihe ibitonyanga byakozwe kugaragara kubakoresha (bizategereza inzibacyuho ya CSS, kugirango birangire). |
hide.bs.dropdown |
Ibi birori birahita bisohoka mugihe uburyo bwo guhisha bwahamagawe. |
hidden.bs.dropdown |
Ibirori birukanwa mugihe ibitonyanga byarangije guhishwa kubakoresha (bizategereza inzibacyuho ya CSS, kugirango birangire). |