Toggle contextual overlays ma ɛkyerɛ links a wɔahyehyɛ ne nea ɛkeka ho denam Bootstrap dropdown plugin no so.
Nsɛm a Wɔaka abom
Dropdowns yɛ toggleable, nsɛm a ɛfa ho a wɔde kata so a wɔde kyerɛ link ahorow a wɔahyehyɛ ne nea ɛkeka ho. Wɔde Bootstrap dropdown JavaScript plugin a ɛka ho no ayɛ nkitahodi. Wɔnam klik so na ɛsakra wɔn, na ɛnyɛ sɛ wɔde wɔn ho to so; eyi yɛ gyinaesi a wɔahyɛ da ayɛ wɔ nhyehyɛe ho.
Wɔasi dropdowns wɔ nhomakorabea a ɛto so abiɛsa, Popper.js , a ɛma gyinabea a ɛyɛ nnam ne viewport detection. Hwɛ sɛ wode popper.min.js bɛka ho ansa na Bootstrap JavaScript no aba anaa fa bootstrap.bundle.min.js/ bootstrap.bundle.jsa Popper.js wom no di dwuma. Popper.js nnyɛ mfa nsi dropdowns wɔ navbars ɛwom sɛ sɛ dynamic positioning nhia.
WAI ARIA gyinapɛn no kyerɛkyerɛ widget ankasa mu role="menu", nanso eyi yɛ pɔtee ma application-te sɛ menus a ɛkanyan nneyɛe anaa dwumadi ahorow. ARIA menu ahorow no betumi akura menu nneɛma, checkbox menu nneɛma, radio bɔtn menu nneɛma, radio bɔtn akuw, ne menu nketewa nkutoo.
Nanso, wɔayɛ Bootstrap dropdowns no sɛnea ɛbɛyɛ a ɛbɛyɛ nea ɛfa biribiara ho na ɛyɛ adwuma wɔ tebea horow ne agyiraehyɛde nhyehyɛe ahorow mu. Sɛ nhwɛso no, wobetumi ayɛ dropdowns a ɛwɔ inputs foforo ne form controls, te sɛ search fields anaa login forms. Esiane eyi nti, Bootstrap nhwɛ kwan (anaasɛ ɛde bɛka ho ankasa) rolene aria-su ahorow a ɛho hia ma nokware ARIA menu ahorow no mu biara. Ɛsɛ sɛ akyerɛwfo ankasa de saa su ahorow a ɛyɛ pɔtee kɛse yi ka ho.
Nanso, Bootstrap de mmoa a wɔasisi mu ka ho ma keyboard menu nkitahodi dodow no ara a ɛyɛ gyinapɛn, te sɛ tumi a wode bɛfa nneɛma ankorankoro .dropdown-itemmu denam cursor safoa no so na wode safoa no ato menu no mu ESC.
Nhwɛso ahorow
Fa dropdown no toggle (wo button anaa link) ne dropdown menu no kyekyere .dropdown, anaa element foforo a ɛpae mu ka position: relative;. Wobetumi akanyan dropdowns afi <a>anaa <button>elements mu ma ɛne w’ahiade ahorow a ebetumi aba no ahyia yiye.
Bɔton biako pɛ
.btnWobetumi adan single biara ayɛ no dropdown toggle a markup nsakrae ahorow bi wom. Sɛnea wubetumi de wɔn ayɛ adwuma ne <button>elements abien no mu biara ni:
Saa ara nso na yɛ split button dropdowns a ɛkame ayɛ sɛ markup koro no ara sɛ button dropdowns biako, nanso fa ka ho .dropdown-toggle-splitma kwan a ɛfata twa dropdown caret no ho hyia.
Yɛde saa adesua foforo yi di dwuma de tew horizontal paddinga ɛwɔ caret no afã abien no nyinaa so 25% na yɛayi nea margin-leftwɔde aka ho ama daa button dropdowns no. Saa nsakrae afoforo no ma caret no kɔ mfinimfini wɔ split button no mu na ɛma hit area a ne kɛse fata kɛse wɔ button titiriw no nkyɛn.
Abakɔsɛm mu no na ɛsɛ sɛ dropdown menu mu nsɛm yɛ links, nanso ɛnyɛ saa bio wɔ v4 ho. Afei wobɛtumi de <button>elements adi dwuma wɔ wo dropdowns no mu sen sɛ wode <a>s kɛkɛ bedi dwuma.
Wubetumi nso de .dropdown-item-text. Fa ahofadi de CSS anaa nsɛm a wɔde di dwuma a wɔahyɛ da ayɛ no kyerɛw kɔ akyiri.
Sɛnea wɔahyɛ no, wɔde menu a ɛba fam no si hɔ ankasa 100% fi soro ne ne wofo no benkum so. Fa ka .dropdown-menu-righta ho .dropdown-menukɔ nifa so hyɛ dropdown menu no mu.
Ti a ɛwɔ soro! Dropdowns no wɔ gyinabea aseda Popper.js (gye sɛ bere a ɛwɔ navbar mu).
Menu mu nsɛm
Nsɛmti a wɔde kyerɛw nsɛm
Fa asɛmti bi ka ho na fa nkyerɛwde afã horow a ɛfa nneyɛe ho wɔ dropdown menu biara mu.
Fa freeform text biara gu dropdown menu a nsɛm wom mu na fa spacing utilities di dwuma . Hyɛ no nsow sɛ ɛda adi sɛ wubehia sizing styles foforo de asiw menu no trɛw ano.
Ebinom nhwɛso nsɛm a ɛyɛ free-flowing wɔ dropdown menu no mu.
Ɛnam data attributes anaa JavaScript so no, dropdown plugin no dannan nneɛma a ahintaw (dropdown menus) denam .showadesuakuw no a ɛsakra wɔ ɔwofo list ade no so. Wɔde data-toggle="dropdown"wɔn ho to su no so de to dropdown menus mu wɔ application level bi so, enti ɛyɛ adwene pa sɛ wode bedi dwuma bere nyinaa.
Wɔ mfiri a wɔde nsa ka so no, sɛ wubue dropdown a, ɛde handlers a hwee nni mu ( $.noop) ka element mouseoverno mma a wɔbɛn wɔn ntɛm ara no ho. <body>This admittedly ugly hack is necessary to work around a quirk in iOS’ event delegation , a anka ɛbɛma tap biara a ɛwɔ dropdown no akyi a ɛbɛkanyan code a ɛto dropdown no. Sɛ wɔto dropdown no mu wie a, woyi saa mouseoverhandlers foforo a hwee nni mu yi fi hɔ.
Via data su ahorow so
Fa ka data-toggle="dropdown"link anaa button bi ho na dannan dropdown bi.
Ɛdenam JavaScript so
Frɛ nsɛm a ɛwɔ ase hɔ no denam JavaScript so:
data-toggle="dropdown"wɔda so ara hwehwɛ
Ɛmfa ho sɛ ebia wobɛfrɛ wo dropdown no denam JavaScript so anaasɛ wode data-api no bedi dwuma mmom no, data-toggle="dropdown"ɛhwehwɛ sɛ ɛwɔ hɔ bere nyinaa wɔ dropdown no trigger element no so.
Nneɛma a wubetumi apaw
Wobetumi afa data attributes anaa JavaScript so de nneɛma a wobɛpaw no akɔ. Sɛ wopɛ data su ahorow a, fa option din no ka ho data-, sɛnea ɛwɔ data-offset="".
Din
Korɔ
Mfiaseɛ
Nkyerɛmu
offset a wɔde hyɛ mu
nɔma | ahama | dwumadie
0 na ɛwɔ hɔ
Offset a ɛfa dropdown no ho a ɛfa ne botae ho. Sɛ wopɛ nsɛm pii a hwɛ Popper.js offset docs .
dane
boolean ho asɛm
nokorɛ
Ma Dropdown no kwan ma ɛndannan sɛ ɛba sɛ biribi akata so wɔ reference element no so a. Sɛ wopɛ nsɛm pii a hwɛ Popper.js flip docs .
ɔhye so
ahama | adeɛ
'scrollƆwofo'.
Overflow anohyeto hye a ɛwɔ dropdown menu no mu. Gye 'viewport', 'window', 'scrollParent', anaa HTMLElement nkyerɛkyerɛmu bi (JavaScript nkutoo) botae ahorow tom. Sɛ wopɛ nsɛm pii a hwɛ Popper.js preventOverflow docs .
mmoa nwoma
ahama | adeɛ
'toggle' ho asɛm.
Nkyerɛkyerɛmu element a ɛwɔ dropdown menu no mu. Gye 'toggle', 'parent', anaa HTMLElement nkyerɛkyerɛmu bi botae ahorow tom. Sɛ wopɛ nsɛm pii a hwɛ Popper.js referenceObject docs .
da no adi
ahoma
'nsɛm a ɛyɛ nnam'.
Sɛnea wɔahyɛ no, yɛde Popper.js di dwuma ma gyinabea a ɛyɛ nnam. Ma eyi nyɛ adwuma wɔ static.
Hyɛ no nsow bere boundarya wɔde ato botae biara a ɛnyɛ 'scrollParent', wɔde ɔkwan position: staticno di dwuma wɔ .dropdownade no so.
Akwan a wɔfa so yɛ
Ɔkwan
Nkyerɛmu
$().dropdown('toggle')
Toggles dropdown menu a ɛwɔ navbar anaa tabbed navigation a wɔde ama no mu.
$().dropdown('update')
Ɔyɛ element bi a ɛwɔ dropdown no gyinabea foforo.
$().dropdown('dispose')
Ɔsɛe element bi a ɛwɔ dropdown no.
Nsɛm a esisi
Wɔde dropdown nsɛm a esisi nyinaa tow wɔ .dropdown-menu's awofo element no so na ɛwɔ relatedTargetagyapade, a ne bo yɛ toggling anchor element. hide.bs.dropdownna hidden.bs.dropdownnsɛm a esisi no wɔ clickEventagyapade (bere a mfitiase adeyɛ no su no nkutoo yɛ click) a ɛwɔ Event Object ma click event no.
Dwumadie
Nkyerɛmu
show.bs.dropdown
Saa adeyɛ yi tow ntɛm ara bere a wɔfrɛ show instance kwan no.
shown.bs.dropdown
Wɔtow saa adeyɛ yi bere a wɔayɛ dropdown no ahu nea ɔde di dwuma no (bɛtwɛn ma CSS nsakrae ahorow, awie).
hide.bs.dropdown
Wɔtow saa adeyɛ yi ntɛm ara bere a wɔafrɛ hide instance kwan no.
hidden.bs.dropdown
Wɔtow saa adeyɛ yi bere a wɔawie dropdown no a wɔde asie ama ɔdefo no (bɛtwɛn ma CSS nsakrae ahorow, awie).