Pa'u i lalo
Fa'afeso'ota'i fa'amaufa'ailoga mo le fa'aalia o lisi o feso'ota'iga ma isi mea fa'atasi ma le Bootstrap dropdown plugin.
Pa'u i lalo e mafai ona fesuia'i, fa'alava fa'atatau mo le fa'aalia o lisi o so'otaga ma isi mea. O lo'o fa'afeso'ota'i fa'atasi ma le fa'apipi'i fa'apipi'i a le Bootstrap dropdown JavaScript. E fesuia'i i le kiliki, ae le o le fa'afefe; ose fa'ai'uga faufau fa'amoemoeina.
Dropdowns e fausia i luga o se faletusi vaega lona tolu, Popper.js , lea e maua ai le tulaga faʻamalosi ma le vaʻaia vaʻaia. Ia mautinoa e aofia ai popper.min.js i luma o le Bootstrap's JavaScript poʻo le faʻaoga bootstrap.bundle.min.js
/ bootstrap.bundle.js
lea e iai Popper.js. E le fa'aogaina le Popper.js e fa'atulaga ai fa'alalo i lalo i luga o navbars e ui e le mana'omia se tulaga fa'amalosi.
Afai o loʻo e fausiaina la matou JavaScript mai le puna, e manaʻomiautil.js
.
O le WAI ARIA standard o loʻo faʻamatalaina se role="menu"
widget moni , ae o lenei mea e faʻapitoa i faʻaoga-pei o menus e faʻaosoina ai gaioiga poʻo galuega. ARIA menus e mafai ona i ai na'o mea fa'aitu, pusa siaki mea lisi, mea fa'aitula'i fa'amau, fa'alapotopotoga fa'amau leitio, ma sub-menu.
Bootstrap's dropdowns, i le isi itu, ua mamanuina ina ia lautele ma talafeagai i tulaga eseese ma fausaga faʻailoga. Mo se fa'ata'ita'iga, e mafai ona fa'atupu fa'amaulalo o lo'o iai mea fa'aopoopo ma fa'atonutonu fomu, e pei o fanua su'esu'e po'o fomu saini. Mo lenei mafuaʻaga, e le faʻamoemoeina e Bootstrap (pe faʻaopoopoina otometi) soʻo se role
ma aria-
uiga manaʻomia mo menus ARIA moni. E tatau i le au tusitala ona aofia ai nei uiga sili atu ona patino.
Ae ui i lea, e faʻaopoopoina e Bootstrap le lagolago faʻapipiʻi mo le tele o fesoʻotaʻiga lisi lisi, e pei o le mafai ona faʻaogaina .dropdown-item
elemene taʻitasi e faʻaaoga ai ki ma tapuni le lisi ma le ESCki.
Afifi le koli o le pa'u i lalo (lou faamau po'o le so'oga) ma le lisi fa'alalo i totonu .dropdown
, po'o se isi elemene e fa'ailoa mai position: relative;
. E mafai ona fa'aosoina mai <a>
po'o <button>
elemene e fetaui lelei ma ou mana'oga.
So'o se mea e tasi .btn
e mafai ona liua i se pa'u i lalo toggle ma nisi suiga fa'ailoga. O le auala lenei e mafai ai ona e faʻaogaina i latou i <button>
elemene e lua:
<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>
Ma faʻatasi ai ma <a>
elemene:
<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>
O le vaega pito sili ona lelei e mafai ona e faia lenei mea i soʻo se suiga faʻamau, foi:
E fa'apena fo'i, fa'atupu fa'amaufa'ailoga vaelua fa'atasi ma fa'ailoga tutusa ma fa'amau fa'amau tasi, ae fa'atasi ai ma le fa'aopoopoina .dropdown-toggle-split
mo le avanoa talafeagai i le fa'amaufa'ailoga.
Matou te fa'aogaina lenei vasega fa'aopoopo e fa'aitiitia ai le fa'alava padding
i itu uma e lua o le fa'ailoga i le 25% ma aveese le margin-left
fa'aopoopo mo fa'amau fa'amau fa'amau. O na suiga fa'aopoopo e fa'amautu ai le fa'amaufa'ailoga i le ki vaelua ma tu'u ai se vaega e sili atu le lapopo'a ta i tafatafa o le ki autu.
O fa'amau fa'amau e galue i fa'amau o so'o se lapo'a, e aofia ai fa'amau fa'aletonu ma vaevae fa'amau.
Fa'aoso lisi fa'alalo i luga o elemene e ala i le fa'aopoopo .dropup
i le elemene matua.
Fa'aoso menus pa'u i le itu taumatau o elemene e ala i le fa'aopoopo .dropright
i le elemene matua.
Fa'aoso menus pa'u i le agavale o elemene e ala i le fa'aopoopo .dropleft
i le elemene matua.
O mea o lo'o i lalo ole lisi fa'asolopito e tatau ona avea ma so'otaga, ae e le o toe fa'apea le v4. Ole taimi nei e mafai ona e fa'aogaina <button>
elemene i lau pa'u i lalo nai lo na'o <a>
le 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>
Ona o le faaletonu, e otometi lava ona tu'u 100% mai le pito i luga ma le itu agavale o lona matua. Fa'aopoopo .dropdown-menu-right
i le .dropdown-menu
fa'aoga i le taumatau le lisi o le pa'u i lalo.
Ulu i luga! Fa'ato'a fa'atulaga fa'afetai i Popper.js (sei vagana ai ua i ai i totonu o le 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>
Fa'aopoopo se ulutala e fa'ailoga vaega o gaioioiga i so'o se lisi fa'alalo.
<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>
Vaevae vaega o mea fa'aitu fa'atasi ma se vaeluaga.
<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>
Tu'u se fomu i totonu o le lisi o le pa'u i lalo, pe fai i totonu o le lisi o le pa'u i lalo, ma fa'aoga le pito i lalo po'o le padding utilities e tu'u ai le avanoa leaga e te mana'omia.
<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>
Faaopoopo .active
i aitema i le pa'ū i lalo e fa'avasega ai e pei o le gaioi .
<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>
Faaopoopo .disabled
i aitema i le pa'ū i lalo e fa'apena e le atoatoa .
<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>
E ala i fa'amatalaga uiga po'o le JavaScript, o le pa'ū fa'apipi'i fa'apipi'i mea natia (pa'u i lalo menus) e ala i le fa'anofoina o le .show
vasega i le lisi o matua. O le data-toggle="dropdown"
uiga e fa'alagolago i ai mo le tapunia o menus dropdown i se tulaga o talosaga, o se manatu lelei le fa'aaogaina i taimi uma.
I luga o masini e mafai ona pa'i, o le tatalaina o se pa'u i lalo e fa'aopoopoina ai le gaogao ( $.noop
) mouseover
fa'atonu i tamaiti vave o le <body>
elemene. O lenei hack e ta'utinoina mataga e mana'omia e galue fa'ata'amilo i se fa'alavelave i le tu'uina atu o mea e fai a iOS , lea e ono taofia ai se pa'i i so'o se mea i fafo atu o le pa'u i lalo mai le fa'aosoina o le code e tapuni ai le pa'ū. O le taimi lava e tapuni ai le pa'u i lalo, o nei isi fa'aoga gaogao mouseover
e aveese.
Fa'aopoopo data-toggle="dropdown"
i se so'oga po'o se fa'amau e fa'asolo i lalo.
Valaau le to'alalo e ala i le JavaScript:
data-toggle="dropdown"
manaomia pea
Tusa lava pe e te valaʻau lau pa'ū i lalo e ala i le JavaScript pe faʻaaoga le data-api, data-toggle="dropdown"
e manaʻomia i taimi uma le i ai i luga o le elemene faʻaoso.
O filifiliga e mafai ona pasia e ala i faʻamatalaga uiga poʻo le JavaScript. Mo fa'amatalaga uiga, fa'aopoopo le igoa filifiliga i le data-
, pei o le data-offset=""
.
Igoa | Ituaiga | Fa'atonu | Fa'amatalaga |
---|---|---|---|
fa'apena | numera | manoa | galuega faatino | 0 | Offset o le pa'u i lalo e fa'atatau i lona fa'amoemoe. Mo nisi fa'amatalaga va'ai ile Popper.js's offset docs . |
liliu | boolean | moni | Fa'ataga le Pa'u i lalo e fa'ase'e pe a o'o i luga o le elemene fa'asino. Mo nisi fa'amatalaga va'ai ile Popper.js's flip docs . |
tuaoi | manoa | elemene | 'scrollParent' | Fa'agata tapula'a tuaoi o le lisi e to'a i lalo. Talia le taua o le 'viewport' , 'window' , 'scrollParent' , poʻo se HTMLElement reference (JavaScript naʻo). Mo nisi fa'amatalaga va'ai ile Popper.js's preventOverflow docs . |
Manatua pe a boundary
seti i soʻo se tau e ese mai i le 'scrollParent'
, o le sitaili position: static
e faʻaoga i le .dropdown
koneteina.
Metotia | Fa'amatalaga |
---|---|
$().dropdown('toggle') |
Fa'asolo i lalo le lisi o le navbar ua tu'uina atu po'o le fa'atautaiga fa'apipi'i. |
$().dropdown('update') |
Fa'afou le tulaga o le pa'u i lalo o se elemene. |
$().dropdown('dispose') |
Fa'aleagaina le pa'u i lalo o se elemene. |
O mea uma e pa'u i lalo o lo'o fa'ao i le .dropdown-menu
'elemene matua ma e iai se relatedTarget
meatotino, o lona tau o le elemene taula ta'amilo.
Mea na tupu | Fa'amatalaga |
---|---|
show.bs.dropdown |
E mu vave lenei mea pe a valaau le auala fa'ata'ita'iga. |
shown.bs.dropdown |
O lenei mea e tupu pe a faʻaalia le pa'ū i lalo i le tagata faʻaoga (o le a faʻatali mo suiga CSS, e faʻamaeʻa). |
hide.bs.dropdown |
O lenei mea e tupu e faʻamalo vave pe a valaʻau le auala faʻataʻitaʻiga natia. |
hidden.bs.dropdown |
O lenei mea e tupu pe a maeʻa ona natia le pa'ū i lalo mai le tagata faʻaoga (o le a faʻatali mo suiga CSS, e faʻamaeʻa). |