Mafere na isi ọdịnaya Gaa na ntugharị docs
Check
in English

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.jsnke 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 rolena 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-itemigodo 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 .btnike ị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ụ:

html
<div class="dropdown">
  <button class="btn btn-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
    Dropdown button
  </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>
  </ul>
</div>

Na <a>ihe ndị a:

html
<div class="dropdown">
  <a class="btn btn-secondary dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
    Dropdown link
  </a>

  <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>
  </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-splitmaka oghere kwesịrị ekwesị n'akụkụ ebe nchekwa dropdown.

Anyị na-eji klaasị mgbakwunye a iji belata kehoraizin paddingn'akụkụ ọ bụla nke nlekọta ahụ site na 25% wee wepụ margin-leftnke 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-darkna nke dị adị .dropdown-menu. Enweghị mgbanwe ọ bụla achọrọ na ihe ndọpụta.

html
<div class="dropdown">
  <button class="btn btn-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
    Dropdown button
  </button>
  <ul class="dropdown-menu dropdown-menu-dark">
    <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:

html
<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="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
            Dropdown
          </a>
          <ul class="dropdown-menu dropdown-menu-dark">
            <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 .dropstartga-apụta n'akụkụ aka nri.

Gbadoro anya

Mee ka menu ndọpụta ahụ dabere n'okpuru ntụgharị ya .dropdown-centerna mmewere nne na nna.

html
<div class="dropdown-center">
  <button class="btn btn-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
    Centered dropdown
  </button>
  <ul class="dropdown-menu">
    <li><a class="dropdown-item" href="#">Action</a></li>
    <li><a class="dropdown-item" href="#">Action two</a></li>
    <li><a class="dropdown-item" href="#">Action three</a></li>
  </ul>
</div>

Mbupu

Kpalite menu ndọda n'elu ihe site na ịgbakwunye .dropupna 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>

Mbupu gbadoro ụkwụ

Mee ka menu ndọpụta ahụ dabere n'elu ngbanwe na .dropup-centermmewere nne na nna.

html
<div class="dropup-center dropup">
  <button class="btn btn-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
    Centered dropup
  </button>
  <ul class="dropdown-menu">
    <li><a class="dropdown-item" href="#">Action</a></li>
    <li><a class="dropdown-item" href="#">Action two</a></li>
    <li><a class="dropdown-item" href="#">Action three</a></li>
  </ul>
</div>

Wetuo

Kpalite menu ndọda n'aka nri nke ihe ndị ahụ site na ịgbakwunye .dropendna 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">
    Dropend
  </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 Dropend</span>
  </button>
  <ul class="dropdown-menu">
    <!-- Dropdown menu links -->
  </ul>
</div>

mmalite mmalite

Kpalite menu ndọda n'aka ekpe nke ihe ndị ahụ site na ịgbakwunye .dropstartna 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 dropstart">
  <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>
  <button type="button" class="btn btn-secondary">
    Split dropstart
  </button>
</div>

Ị nwere ike iji <a>ma ọ bụ <button>ihe dị ka ihe mwụda.

html
<div class="dropdown">
  <button class="btn btn-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
    Dropdown
  </button>
  <ul class="dropdown-menu">
    <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.

html
<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 .activena 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-currentnjirimara - iji pageuru maka ibe dị ugbu a, ma ọ bụ truemaka ihe dị ugbu a na setịpụ.

html
<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 .disabledna ihe ndị dị na ndọpụta iji mee ka ha nwee nkwarụ .

html
<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>

Site na ndabara, a na-edobe menu ndetu ozugbo 100% site n'elu yana n'akụkụ aka ekpe nke nne na nna ya. Ị nwere ike ịgbanwe nke a site na ntuziaka.drop* klaasị ntụzịaka, mana ị nwekwara ike ijikwa klaasị mgbanwe ndị ọzọ.

Tinye .dropdown-menu-endna a .dropdown-menun'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-endga-apụta n'akụkụ aka ekpe.

Welie isi elu! A na-edobe ihe ndọghachi azụ n'ihi Popper belụsọ mgbe ọ dị na navbar.
html
<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.

html
<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.

html
<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.

html
<div class="btn-group">
  <button class="btn btn-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
    Dropdown
  </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">
  <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>

nkụnye eji isi mee

Tinye nkụnye eji isi mee ka aha ngalaba omume na nchịkọta nhọrọ ọ bụla.

html
<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.

html
<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.

html
<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ọ.

html
<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>
html
<div class="dropdown">
  <button type="button" class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false" data-bs-auto-close="outside">
    Dropdown form
  </button>
  <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>
</div>

Jiri data-bs-offsetma ọ bụ data-bs-referencegbanwee ebe ndọpụta ahụ.

html
<div class="d-flex">
  <div class="dropdown me-1">
    <button type="button" class="btn btn-secondary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false" data-bs-offset="10,20">
      Offset
    </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>
    </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" data-bs-toggle="dropdown" aria-expanded="false" data-bs-reference="parent">
      <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>
</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 autoClosenhọrọ ịgbanwe omume a nke dropdown.

html
<div class="btn-group">
  <button class="btn btn-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" data-bs-auto-close="true" aria-expanded="false">
    Default dropdown
  </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">
  <button class="btn btn-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" data-bs-auto-close="inside" aria-expanded="false">
    Clickable outside
  </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">
  <button class="btn btn-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" data-bs-auto-close="outside" aria-expanded="false">
    Clickable inside
  </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">
  <button class="btn btn-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" data-bs-auto-close="false" aria-expanded="false">
    Manual close
  </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>

CSS

Mgbanwe

Agbakwunyere na v5.2.0

Dịka akụkụ nke mgbanwe mgbanwe CSS Bootstrap na-agbanwe ugbu a, ndetu na-eji mgbanwe CSS mpaghara emelitere .dropdown-menumaka nhazi oge dị adị. A na-edozi ụkpụrụ maka mgbanwe CSS site na Sass, yabụ ka na-akwado nhazi Sass, kwa.

  --#{$prefix}dropdown-zindex: #{$zindex-dropdown};
  --#{$prefix}dropdown-min-width: #{$dropdown-min-width};
  --#{$prefix}dropdown-padding-x: #{$dropdown-padding-x};
  --#{$prefix}dropdown-padding-y: #{$dropdown-padding-y};
  --#{$prefix}dropdown-spacer: #{$dropdown-spacer};
  @include rfs($dropdown-font-size, --#{$prefix}dropdown-font-size);
  --#{$prefix}dropdown-color: #{$dropdown-color};
  --#{$prefix}dropdown-bg: #{$dropdown-bg};
  --#{$prefix}dropdown-border-color: #{$dropdown-border-color};
  --#{$prefix}dropdown-border-radius: #{$dropdown-border-radius};
  --#{$prefix}dropdown-border-width: #{$dropdown-border-width};
  --#{$prefix}dropdown-inner-border-radius: #{$dropdown-inner-border-radius};
  --#{$prefix}dropdown-divider-bg: #{$dropdown-divider-bg};
  --#{$prefix}dropdown-divider-margin-y: #{$dropdown-divider-margin-y};
  --#{$prefix}dropdown-box-shadow: #{$dropdown-box-shadow};
  --#{$prefix}dropdown-link-color: #{$dropdown-link-color};
  --#{$prefix}dropdown-link-hover-color: #{$dropdown-link-hover-color};
  --#{$prefix}dropdown-link-hover-bg: #{$dropdown-link-hover-bg};
  --#{$prefix}dropdown-link-active-color: #{$dropdown-link-active-color};
  --#{$prefix}dropdown-link-active-bg: #{$dropdown-link-active-bg};
  --#{$prefix}dropdown-link-disabled-color: #{$dropdown-link-disabled-color};
  --#{$prefix}dropdown-item-padding-x: #{$dropdown-item-padding-x};
  --#{$prefix}dropdown-item-padding-y: #{$dropdown-item-padding-y};
  --#{$prefix}dropdown-header-color: #{$dropdown-header-color};
  --#{$prefix}dropdown-header-padding-x: #{$dropdown-header-padding-x};
  --#{$prefix}dropdown-header-padding-y: #{$dropdown-header-padding-y};
  

Enwere ike ịhụ nhazi site na mgbanwe CSS na .dropdown-menu-darkklaasị ebe anyị na-ewepụ ụkpụrụ akọwapụtara na-agbakwunyeghị ndị na-ahọrọ CSS oyiri.

  --#{$prefix}dropdown-color: #{$dropdown-dark-color};
  --#{$prefix}dropdown-bg: #{$dropdown-dark-bg};
  --#{$prefix}dropdown-border-color: #{$dropdown-dark-border-color};
  --#{$prefix}dropdown-box-shadow: #{$dropdown-dark-box-shadow};
  --#{$prefix}dropdown-link-color: #{$dropdown-dark-link-color};
  --#{$prefix}dropdown-link-hover-color: #{$dropdown-dark-link-hover-color};
  --#{$prefix}dropdown-divider-bg: #{$dropdown-dark-divider-bg};
  --#{$prefix}dropdown-link-hover-bg: #{$dropdown-dark-link-hover-bg};
  --#{$prefix}dropdown-link-active-color: #{$dropdown-dark-link-active-color};
  --#{$prefix}dropdown-link-active-bg: #{$dropdown-dark-link-active-bg};
  --#{$prefix}dropdown-link-disabled-color: #{$dropdown-dark-link-disabled-color};
  --#{$prefix}dropdown-header-color: #{$dropdown-dark-header-color};
  

Sass variables

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:             var(--#{$prefix}border-color-translucent);
$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-x:         $dropdown-item-padding-x;
$dropdown-header-padding-y:         $dropdown-padding-y;
// fusv-disable
$dropdown-header-padding:           $dropdown-header-padding-y $dropdown-header-padding-x; // Deprecated in v5.2.0
// fusv-enable

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ị .showklas 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.

Na ngwaọrụ enyere aka, imepe ndọpụta na-agbakwunye ndị na-ahụ maka ihe efu mouseoverna ụ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 dropdown na-emechi, ndị a ọzọ efu 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 type="button" data-bs-toggle="dropdown" aria-expanded="false">
    Dropdown trigger
  </button>
  <ul class="dropdown-menu">
    ...
  </ul>
</div>

Site JavaScript

Kpọọ dropdowns site na Javascript:

const dropdownElementList = document.querySelectorAll('.dropdown-toggle')
const dropdownList = [...dropdownElementList].map(dropdownToggleEl => 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ọ

Dịka enwere ike ịfefe nhọrọ site na njirimara data ma ọ bụ Javascript, ị nwere ike itinye aha nhọrọ na data-bs-, dịka na data-bs-animation="{value}". 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 ihe atụ, jiri data-bs-custom-class="beautifier"kamadata-bs-customClass="beautifier" .

Dịka nke Bootstrap 5.2.0, akụrụngwa niile na-akwado njirimara data echekwara nnwaledata-bs-config nke nwere ike idobe nhazi akụrụngwa dị mfe dị ka eriri JSON. Mgbe mmewere nwere data-bs-config='{"delay":0, "title":123}'na data-bs-title="456"njiri mara, uru ikpeazụ titlega-abụ 456na njirimara data dị iche ga-ewepụ ụkpụrụ enyere na data-bs-config. Na mgbakwunye, njirimara data dị adị nwere ike idobe ụkpụrụ JSON dịka data-bs-delay='{"show":0,"hide":150}'.

Aha Ụdị Ọdabara Nkọwa
autoClose boolean, eriri true Hazie omume nso akpaaka nke dropdown:
  • true- A ga-emechi dropdown site na ịpị n'èzí ma ọ bụ n'ime menu ndọpụta.
  • false- A ga-emechi dropdown site na ịpị bọtịnụ ntụgharị na iji aka kpọọ hidema ọ bụ toggleusoro. (Ọzọkwa site na ịpị igodo agaghị emechi esc)
  • 'inside'- A ga-emechi dropdown (naanị) site na ịpị n'ime menu ndọpụta.
  • 'outside'- A ga-emechi dropdown (naanị) site na ịpị na mpụga menu ndọpụta.
Mara: Enwere ike iji ESCigodo mechie ndọpụta mgbe niile.
boundary eriri, element 'clippingParents' Oke oke mmachi oke nke menu ndọpụta (na-emetụta naanị Popper's preventOverflow modifier). Site na ndabara ọ clippingParentsnwere ike nabata ntụaka HTMLElement (site na Javascript naanị). Maka ozi ndị ọzọ rụtụ aka na docs detectOverflow nke Popper .
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 site na iji ụkpụrụ kewapụrụ rikoma dị ka: data-bs-offset="10,20". 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 usoro nwere ọnụọgụ abụọ: skidding , anya . Maka ozi ndị ọzọ rụtụ aka na docs offset Popper .
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.
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 .

Iji ọrụ napopperConfig

const dropdown = new bootstrap.Dropdown(element, {
  popperConfig(defaultBsPopperConfig) {
    // const newPopperConfig = {...}
    // use defaultBsPopperConfig if needed...
    // return newPopperConfig
  }
})

Ụzọ

Usoro Nkọwa
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 ndapụta ejikọta na mmewere 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):.
hide Na-ezobe menu mwụda nke navbar enyere ma ọ bụ igodo taabụ.
show Na-egosi ndetu mwepu nke ihe navbar enyere ma ọ bụ igodo taabụ.
toggle Na-atụgharị menu mwụda nke navbar enyere ma ọ bụ igodo taabụ.
update Na-emelite ọnọdụ nke dropdown 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-menummemme nne na nna. hide.bs.dropdownna hidden.bs.dropdownihe omume nwere ihe clickEventonwunwe (naanị mgbe ụdị ihe omume mbụ bụ click) nke nwere ihe omume maka ihe omume pịa.

Ụdị mmemme Nkọwa
hide.bs.dropdown Ọkụ ozugbo mgbe akpọrọ usoro hideihe atụ.
hidden.bs.dropdown Achụpụ mgbe ezoro ezoro ya n'aka onye ọrụ ahụ ma ngbanwe CSS agwụla.
show.bs.dropdown Ọkụ ozugbo showa na-akpọ usoro ihe atụ.
shown.bs.dropdown Achụpụrụ mgbe onye ọrụ mere ka ndọpụta ahụ pụta ìhè yana ngbanwe CSS agwụla.
const myDropdown = document.getElementById('myDropdown')
myDropdown.addEventListener('show.bs.dropdown', event => {
  // do something...
})