Mbelata
Gbanwee ihe mkpuchi gburugburu maka igosipụta ndepụta njikọ yana ihe ndị ọzọ na ngwa mgbakwunye Bootstrap.
Nchịkọta
Mbudata bụ mgbanwe mgbanwe, machie gburugburu maka igosipụta ndepụta njikọ yana ndị ọzọ. Ejiri ngwa mgbakwunye Bootstrap dropdown Javascript mekọrịta ha. A na-atụgharị ha site na ịpị, ọ bụghị site na ịnyagharị; Nke a bụ mkpebi imewe nke a kpachapụrụ anya .
A na-ewu mkpọda n'ọbá akwụkwọ nke ndị ọzọ, Popper , nke na-enye ọnọdụ dị ike na nchọpụta nlele. Jide n'aka na ị gụnyere popper.min.js tupu Bootstrap's JavaScript ma ọ bụ jiri bootstrap.bundle.min.js
/ bootstrap.bundle.js
nke nwere Popper. A naghị eji popper dobe dropdowns na navbars n'agbanyeghị na ọ dịghị mkpa n'ọnọdu ike.
Nnweta
Ọkọlọtọ WAI ARIA na -akọwapụta role="menu"
wijetị n'ezie , mana nke a bụ kpọmkwem maka ngwa-dị ka ngwa na-akpalite omume ma ọ bụ ọrụ. Nchịkọta ARIA nwere ike ịnwe naanị ihe nchịkọta nhọrọ, ihe nchịkọta nhọrọ igbe igbe, ihe nchịkọta nhọrọ bọtịnụ redio, otu bọtịnụ redio, na obere menus.
N'aka nke ọzọ, emebere bootstrap's dropdowns ka ọ bụrụ ọnụọgụ na ọdabara n'ọnọdụ dị iche iche yana nhazi akara. Dịka ọmụmaatụ, ọ ga-ekwe omume ịmepụta mkpọda nwere ntinye agbakwunyere yana njikwa ụdị, dị ka mpaghara ọchụchọ ma ọ bụ ụdị nbanye. N'ihi nke a, Bootstrap anaghị atụ anya (ma ọ bụ tinye ya ozugbo) nke ọ bụla role
na aria-
njirimara achọrọ maka ezigbo menus ARIA . Ndị ode akwụkwọ ga-etinyerịrị njirimara ndị a n'onwe ha.
Agbanyeghị, Bootstrap na-agbakwunye nkwado arụnyere n'ime ọtụtụ mmekọrịta menu nke ahụigodo, dị ka ike iji .dropdown-item
igodo cursor mechie menu site na ihe ESCdị iche iche.
Ihe atụ
Kechie ngbanwe nke dropdown (bọtịnụ gị ma ọ bụ njikọ gị) yana menu ndọpụta n'ime .dropdown
, ma ọ bụ ihe ọzọ na-ekwupụta position: relative;
. Enwere ike ịkpalite mbelata site na <a>
ma ọ bụ <button>
ihe iji kwado mkpa gị nke ọma. Ọmụmatụ egosiri ebe a na-eji semantic semantic <ul>
, mana a na-akwado akara ngosi omenala.
Otu bọtịnụ
Enwere .btn
ike ịtụgharị otu ọ bụla ka ọ bụrụ ntụgharị mkpọda nwere ụfọdụ mgbanwe akara. Nke a bụ otu ị ga-esi tinye ha ka ha jiri <button>
ihe abụọ ọ bụla rụọ ọrụ:
<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>
ihe ndị a:
<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>
Akụkụ kachasị mma bụ na ị nwere ike ime nke a site na iji ụdị bọtịnụ ọ bụla, kwa:
<!-- 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>
bọtịnụ gbawara
N'otu aka ahụ, mepụta mkpọda bọtịnụ nkewa nwere ihe fọrọ nke nta ka ọ bụrụ otu akara dị ka otu ndetu bọtịnụ, mana yana mgbakwunye .dropdown-toggle-split
maka oghere kwesịrị ekwesị n'akụkụ ebe nchekwa dropdown.
Anyị na-eji klaasị mgbakwunye a iji belata kehoraizin padding
n'akụkụ ọ bụla nke nlekọta ahụ site na 25% wee wepụ margin-left
nke ahụ agbakwunyere maka ndetu bọtịnụ oge niile. Mgbanwe ndị ahụ na-eme ka nlekọta ahụ dabere na bọtịnụ gbawara agbawa wee wepụta mpaghara kụrụ nke ọma karịa n'akụkụ bọtịnụ isi.
<!-- 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>
Nha nha
Mbelata bọtịnụ na-arụ ọrụ na bọtịnụ nha niile, gụnyere ndabara na bọtịnụ mwụda gbawara agbawa.
<!-- 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>
Mwụda gbara ọchịchịrị
Wepụ n'ime mkpọda gbara ọchịchịrị iji dakọọ navbar gbara ọchịchịrị ma ọ bụ ụdị omenala site na ịgbakwunye .dropdown-menu-dark
na nke dị adị .dropdown-menu
. Enweghị mgbanwe ọ bụla achọrọ na ihe ndọpụta.
<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 itinye ya n'ọrụ na navbar:
<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>
Ntuziaka
RTL
A na-egosipụta ntụzịaka mgbe ị na-eji Bootstrap na RTL, nke pụtara .dropstart
ga-apụta n'akụkụ aka nri.
Mbupu
Kpalite menu ndọda n'elu ihe site na ịgbakwunye .dropup
na mmewere nne na nna.
<!-- 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
Kpalite menu ndọda n'aka nri nke ihe ndị ahụ site na ịgbakwunye .dropend
na mmewere nne na nna.
<!-- 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>
Mbupu
Kpalite menu ndọda n'aka ekpe nke ihe ndị ahụ site na ịgbakwunye .dropstart
na mmewere nne na nna.
<!-- 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>
Ihe nchịkọta nhọrọ
Ị nwere ike iji <a>
ma ọ bụ <button>
ihe dị ka ihe mwụda.
<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>
Ị nwekwara ike iji .dropdown-item-text
. Na-enwere onwe gị ịke ọzọ site na iji CSS omenala ma ọ bụ ngwa ederede.
<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>
Na-arụ ọrụ
Tinye .active
na ihe ndị dị na ndọpụta iji mee ka ha dị ka ndị na-arụ ọrụ . Iji bufee steeti nọ n'ọrụ na teknụzụ enyemaka, jiri aria-current
njirimara - iji page
uru maka ibe dị ugbu a, ma ọ bụ true
maka ihe dị ugbu a na setịpụ.
<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>
Agbanyụrụ
Tinye .disabled
na ihe ndị dị na ndọpụta iji mee ka ha nwee nkwarụ .
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="#">Regular link</a></li>
<li><a class="dropdown-item disabled">Disabled link</a></li>
<li><a class="dropdown-item" href="#">Another link</a></li>
</ul>
Nhazi menu
Site na ndabara, a na-edobe menu ndetu ozugbo 100% site na elu yana n'akụkụ aka ekpe nke nne na nna ya. Ị nwere ike ịgbanwe nke a site na .drop*
klaasị ntụzịaka, mana ị nwekwara ike ijikwa klaasị mgbanwe ndị ọzọ.
Tinye .dropdown-menu-end
na a .dropdown-menu
n'aka nri kwado menu ndọpụta. A na-egosipụta ntụzịaka mgbe ị na-eji Bootstrap na RTL, nke pụtara .dropdown-menu-end
ga-apụta n'akụkụ aka ekpe.
<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>
Nkwekọrịta na-anabata
Ọ bụrụ n’ịchọrọ iji nzizi na-anabata, gbanyụọ ndoro-ndoro siri ike site n'ịgbakwunye data-bs-display="static"
njirimara wee jiri klaasị mgbanwe na-anabata.
Ka ịtọọ nri ndakpọ menu na ebe ezumike enyere ma ọ bụ ka ukwuu, tinye .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>
Iji dokwaa menu ndọpụta aka ekpe.dropdown-menu-end
yana ebe nkwụsịtụ enyere ma ọ bụ ka ukwuu, gbakwunye 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>
Rịba ama na ịkwesighi ịgbakwunye data-bs-display="static"
àgwà na bọtịnụ dropdown na navbars, ebe ọ bụ na ejighị Popper na navbars.
Nhọrọ nhazi
Na-ewere ọtụtụ nhọrọ egosiri n'elu, ebe a bụ obere ihe ngosi sink kichin nke nhọrọ nhazi ndọtị dị iche iche n'otu ebe.
<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>
Ọdịnaya menu
nkụnye eji isi mee
Tinye nkụnye eji isi mee ka aha ngalaba omume na nchịkọta nhọrọ ọ bụla.
<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>
Ndị nkesa
Kewapụ iche nke ihe nchịkọta nhọrọ nwere nkesa.
<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>
Ederede
Debe ederede freeform ọ bụla n'ime menu ndọpụta nwere ederede wee jiri akụrụngwa oghere . Mara na ị ga-achọ ụdị nha nha ọzọ iji gbochie obosara menu.
<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>
Ụdị
Tinye mpempe akwụkwọ n'ime menu ndọpụta, ma ọ bụ mee ya ka ọ bụrụ menu ndọpụta, ma jiri oke ma ọ bụ ihe nkpuchi iji nye ya ohere na-adịghị mma ịchọrọ.
<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>
Nhọrọ nkwụsị
Jiri data-bs-offset
ma ọ bụ data-bs-reference
gbanwee ebe ndọpụta ahụ.
<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>
Omume nsochi akpaaka
Site na ndabara, a na-emechi menu ndọpụta mgbe ịpị n'ime ma ọ bụ na mpụga menu ndọpụta. Ị nwere ike iji autoClose
nhọrọ ịgbanwe omume a nke dropdown.
<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
Mgbanwe
Mgbanwe maka ndapụta niile:
$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($dropdown-link-color, 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;
Mgbanwe maka ndapụta ọchịchịrị :
$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;
Ọdịiche maka nlekọta dabere na CSS nke na-egosi mmekọrịta nke ndapụta:
$caret-width: .3em;
$caret-vertical-align: $caret-width * .85;
$caret-spacing: $caret-width * .85;
Ngwakọta
A na-eji mixins na-emepụta nlekọta ndị dabeere na CSS na enwere ike ịhụ na 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;
}
}
}
Ojiji
Site na njirimara data ma ọ bụ Javascript, ngwa mgbakwunye na-atụgharị ọdịnaya zoro ezo (nchịkọta mkpọda) site na ịtụgharị .show
klas na nne na nna .dropdown-menu
. A data-bs-toggle="dropdown"
na-adabere na njirimara a maka imechi menus dropdown na ọkwa ngwa, yabụ ọ dị mma iji ya mgbe niile.
mouseover
na ụmụaka nke
<body>
mmewere ahụ. Nke a na-ekweta jọrọ njọ mbanye anataghị ikike dị mkpa na-arụ ọrụ gburugburu a
quirk na iOS' event nnọchiteanya , nke ga-ma ọ bụghị gbochie a mgbata n'ebe ọ bụla n'èzí dropdown si ịkpalite koodu na-emechi dropdown. Ozugbo emechiri ndọpụta ahụ, a
mouseover
ga-ewepụ ndị njikwa efu ndị ọzọ.
Site na njirimara data
Tinye data-bs-toggle="dropdown"
na njikọ ma ọ bụ bọtịnụ ka ịgbanwee mkpọda.
<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>
Site JavaScript
Kpọọ dropdowns site na Javascript:
var dropdownElementList = [].slice.call(document.querySelectorAll('.dropdown-toggle'))
var dropdownList = dropdownElementList.map(function (dropdownToggleEl) {
return new bootstrap.Dropdown(dropdownToggleEl)
})
data-bs-toggle="dropdown"
ka achọrọ
N'agbanyeghị ma ị na-akpọ dropdown gị site na Javascript ma ọ bụ kama iji data-api, data-bs-toggle="dropdown"
a na-achọrọ mgbe niile ịnọ na ihe mkpalite dropdown.
Nhọrọ
Enwere ike ịfefe nhọrọ site na njirimara data ma ọ bụ Javascript. Maka njirimara data, tinye aha nhọrọ na data-bs-
, dị ka ọ dị na data-bs-offset=""
. Gbaa mbọ hụ na ị gbanwee ụdị ikpe nke aha nhọrọ site na camelCase gaa na kebab-case mgbe ị na-agafe nhọrọ site na njirimara data. Dịka ọmụmaatụ, kama iji data-bs-autoClose="false"
, jiri data-bs-auto-close="false"
.
Aha | Ụdị | Ọdabara | Nkọwa |
---|---|---|---|
boundary |
eriri | mmewere | 'clippingParents' |
Oke oke mmachi oke nke menu ndọpụta (na-emetụta naanị Popper's preventOverflow modifier). Site na ndabara ọ 'clippingParents' nwere ike nabata ntụaka HTMLElement (site na Javascript naanị). Maka ozi ndị ọzọ rụtụ aka na docs detectOverflow nke Popper . |
reference |
eriri | mmewere | ihe | 'toggle' |
Ihe nrụtụ aka nke menu ndọpụta. Nabata ụkpụrụ nke 'toggle' , 'parent' , HTMLElement ntụaka ma ọ bụ ihe na-enye getBoundingClientRect . Maka ozi ndị ọzọ rụtụ aka na docs constructor Popper na mebere elementrị docs . |
display |
eriri | 'dynamic' |
Site na ndabara, anyị na-eji Popper maka idobe ike. Gbanyụọ nke a na static . |
offset |
n'usoro | eriri | ọrụ | [0, 2] |
Nkwụsị nke ndapụta n'akụkụ ebumnuche ya. Ị nwere ike ịnyefe eriri n'ime njirimara data yana ụkpụrụ kewapụrụ rịkọm dị ka: Mgbe a na-eji ọrụ chọpụta nkwụghachi ụgwọ, a na-akpọ ya na ihe nwere ntinye popper, akwụkwọ ntụaka, na popper rects dị ka arụmụka mbụ ya. A na-agafe oghere DOM na-akpalite dị ka arụmụka nke abụọ. Ọrụ ahụ ga-eweghachite n'usoro nwere ọnụọgụ abụọ: . Maka ozi ndị ọzọ rụtụ aka na docs offset Popper . |
autoClose |
boolean | eriri | true |
Hazie omume nso akpaaka nke dropdown:
|
popperConfig |
efu | ihe | ọrụ | null |
Ka ịgbanwee ndabara Bootstrap Popper config, hụ nhazi nke Popper . Mgbe a na-eji ọrụ mepụta nhazi Popper, a na-akpọ ya na ihe nwere nhazi ndabara nke Bootstrap. Ọ na-enyere gị aka iji ma jikọta ndabara na nhazi nke gị. Ọrụ ahụ ga-eweghachite ihe nhazi maka Popper. |
Iji ọrụ napopperConfig
var dropdown = new bootstrap.Dropdown(element, {
popperConfig: function (defaultBsPopperConfig) {
// var newPopperConfig = {...}
// use defaultBsPopperConfig if needed...
// return newPopperConfig
}
})
Ụzọ
Usoro | Nkọwa |
---|---|
toggle |
Na-atụgharị menu mwụda nke navbar enyere ma ọ bụ igodo taabụ. |
show |
Na-egosi ndetu mwepu nke ihe navbar enyere ma ọ bụ igodo taabụ. |
hide |
Na-ezobe menu mwụda nke navbar enyere ma ọ bụ igodo taabụ. |
update |
Na-emelite ọnọdụ nke dropdown element. |
dispose |
Na-ebibi ihe ndapụta nke mmewere. (Na-ewepụ data echekwara na mmewere DOM) |
getInstance |
Usoro static nke na-enye gị ohere ịnweta ihe atụ dropdown jikọtara na ihe DOM, ị nwere ike iji ya dị ka nke a:bootstrap.Dropdown.getInstance(element) |
getOrCreateInstance |
Ụzọ kwụ ọtọ nke na-eweghachi ihe atụ ndapụta jikọtara na mmewere DOM ma ọ bụ mepụta nke ọhụrụ ma ọ bụrụ na ebidoghị ya. Ị nwere ike iji ya dị ka nke a:bootstrap.Dropdown.getOrCreateInstance(element) |
Ihe omume
A na-agbapụ mmemme mwụda niile na mmewere na-atụgharị wee gbapụta. Yabụ ị nwekwara ike ịgbakwunye ndị na-ege ihe omume na .dropdown-menu
mmemme nne na nna. hide.bs.dropdown
na hidden.bs.dropdown
ihe omume nwere ihe clickEvent
onwunwe (naanị mgbe ụdị ihe omume mbụ bụ click
) nke nwere ihe omume maka ihe omume pịa.
Usoro | Nkọwa |
---|---|
show.bs.dropdown |
Ọkụ ozugbo a na-akpọ usoro ihe ngosi. |
shown.bs.dropdown |
Achụpụrụ mgbe onye ọrụ mere ka ndọpụta ahụ pụta ìhè yana ngbanwe CSS agwụla. |
hide.bs.dropdown |
Ọkụ ozugbo mgbe akpọchara usoro ihe nleba anya. |
hidden.bs.dropdown |
Achụpụ mgbe ezoro ezoro ya n'aka onye ọrụ ahụ ma ngbanwe CSS agwụla. |
var myDropdown = document.getElementById('myDropdown')
myDropdown.addEventListener('show.bs.dropdown', function () {
// do something...
})