aboutsummaryrefslogtreecommitdiff
path: root/docs/components/dropdowns.md
diff options
context:
space:
mode:
authorMark Otto <[email protected]>2017-05-27 15:26:48 -0700
committerMark Otto <[email protected]>2017-05-27 15:26:48 -0700
commit8f67ac19a761b8d3ecc80485c3f54aa6ba4fa910 (patch)
treed5a2aba4e2e762b283e7cfe60f00e1f239105bbe /docs/components/dropdowns.md
parent6c3f833076a9fa68601741e3e21bd07ad79b7d8a (diff)
parentdb44e4b311317ef760f8412cc33c84146959b248 (diff)
downloadbootstrap-8f67ac19a761b8d3ecc80485c3f54aa6ba4fa910.tar.xz
bootstrap-8f67ac19a761b8d3ecc80485c3f54aa6ba4fa910.zip
Merge branch 'v4-dev' into v4-docs-streamlined
Diffstat (limited to 'docs/components/dropdowns.md')
-rw-r--r--docs/components/dropdowns.md119
1 files changed, 85 insertions, 34 deletions
diff --git a/docs/components/dropdowns.md b/docs/components/dropdowns.md
index d26de6eef..13f49a32f 100644
--- a/docs/components/dropdowns.md
+++ b/docs/components/dropdowns.md
@@ -12,16 +12,33 @@ Dropdowns are toggleable, contextual overlays for displaying lists of links and
* Will be replaced with the ToC, excluding the "Contents" header
{:toc}
+## Overview
+
+Things to know when using the popover plugin:
+
+- Dropdown rely on the 3rd party library [Popper.js](https://popper.js.org) for positioning. You must include [popper.min.js](https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.9.9/umd/popper.min.js) before bootstrap.js in order for dropdowns to work!
+- Popper.js handle natively the flip of Dropdown when it's outside the viewport, if you want to disable that's behavior use `flip` attribute
+
## Examples
Wrap the dropdown's toggle (your button or link) and the dropdown menu within `.dropdown`, or another element that declares `position: relative;`. Dropdowns can be triggered from `<a>` or `<button>` elements to better fit your potential needs.
+{% callout info %}
+### Dropdown menu accessibility
+
+The [<abbr title="Web Accessibility Initiative">WAI</abbr> <abbr title="Accessible Rich Internet Applications">ARIA</abbr>](https://www.w3.org/TR/wai-aria/) standard defines an actual [`role="menu"` widget](https://www.w3.org/TR/wai-aria/roles#menu), but this is specific to application-like menus which trigger actions or functions. <abbr title="Accessible Rich Internet Applications">ARIA</abbr> menus can only contain menu items, checkbox menu items, radio button menu items, radio button groups, and sub-menus.
+
+Bootstrap's dropdowns, on the other hand, are designed to be generic and applicable to a variety of situations and markup structures. For instance, it is possible to create dropdowns that contain additional inputs and form controls, such as search fields or login forms. For this reason, Bootstrap does not expect (nor automatically add) any of the `role` and `aria-` attributes required for true <abbr title="Accessible Rich Internet Applications">ARIA</abbr> menus. Authors will have to include these more specific attributes themselves.
+
+However, Bootstrap does add built-in support for most standard keyboard menu interactions, such as the ability to move through individual `.dropdown-item` elements using the cursor keys and close the menu with the <kbd>ESC</kbd> key.
+{% endcallout %}
+
### Single button dropdowns
Any single `.btn` can be turned into a dropdown toggle with some markup changes. Here's how you can put them to work with either `<button>` elements:
{% example html %}
-<div class="dropdown show">
+<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>
@@ -37,7 +54,7 @@ And with `<a>` elements:
{% example html %}
<div class="dropdown show">
- <a class="btn btn-secondary dropdown-toggle" href="https://example.com" id="dropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
+ <a class="btn btn-secondary dropdown-toggle" href="#" role="button" id="dropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown link
</a>
@@ -252,7 +269,7 @@ Button dropdowns work with buttons of all sizes, including default and split dro
<a class="dropdown-item" href="#">Separated link</a>
</div>
</div><!-- /btn-group -->
- <div class="btn-group">
+ <div class="btn-group ml-2">
<button type="button" class="btn btn-lg btn-secondary">Large split button</button>
<button type="button" class="btn btn-lg btn-secondary dropdown-toggle dropdown-toggle-split" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="sr-only">Toggle Dropdown</span>
@@ -279,7 +296,7 @@ Button dropdowns work with buttons of all sizes, including default and split dro
<a class="dropdown-item" href="#">Separated link</a>
</div>
</div><!-- /btn-group -->
- <div class="btn-group">
+ <div class="btn-group ml-2">
<button type="button" class="btn btn-sm btn-secondary">Small split button</button>
<button type="button" class="btn btn-sm btn-secondary dropdown-toggle dropdown-toggle-split" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="sr-only">Toggle Dropdown</span>
@@ -344,34 +361,32 @@ Button dropdowns work with buttons of all sizes, including default and split dro
Trigger dropdown menus above elements by adding `.dropup` to the parent element.
<div class="bd-example">
- <div class="btn-toolbar" role="toolbar">
- <div class="btn-group dropup">
- <button type="button" class="btn btn-secondary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
- Dropup
- </button>
- <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>
+ <div class="btn-group dropup">
+ <button type="button" class="btn btn-secondary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
+ Dropup
+ </button>
+ <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>
+ </div>
- <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-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
- <span class="sr-only">Toggle Dropdown</span>
- </button>
- <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>
+ <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-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
+ <span class="sr-only">Toggle Dropdown</span>
+ </button>
+ <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>
</div>
</div>
@@ -407,7 +422,7 @@ Trigger dropdown menus above elements by adding `.dropup` to the parent element.
Historically dropdown menu contents *had* to be links, but that's no longer the case with v4. Now you can optionally use `<button>` elements in your dropdowns instead of just `<a>`s.
{% example html %}
-<div class="dropdown show">
+<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>
@@ -482,7 +497,9 @@ Add `.disabled` to items in the dropdown to **style them as disabled**.
Via data attributes or JavaScript, the dropdown plugin toggles hidden content (dropdown menus) by toggling the `.show` class on the parent list item.
-On mobile devices, opening a dropdown adds a `.dropdown-backdrop` as a tap area for closing dropdown menus when tapping outside the menu, a requirement for proper iOS support. **This means that switching from an open dropdown menu to a different dropdown menu requires an extra tap on mobile.**
+{% callout info %}
+On touch-enabled devices, opening a dropdown adds empty (`$.noop`) `mouseover` handlers to the immediate children of the `<body>` element. This admittedly ugly hack is necessary to work around a [quirk in iOS' event delegation](https://www.quirksmode.org/blog/archives/2014/02/mouse_event_bub.html), which would otherwise prevent a tap anywhere outside of the dropdown from triggering the code that closes the dropdown. Once the dropdown is closed, these additional empty `mouseover` handlers are removed.
+{% endcallout %}
Note: The `data-toggle="dropdown"` attribute is relied on for closing dropdown menus at an application level, so it's a good idea to always use it.
@@ -510,20 +527,54 @@ $('.dropdown-toggle').dropdown()
{% endhighlight %}
{% callout info %}
-#### `data-toggle="dropdown"` still required
+##### `data-toggle="dropdown"` still required
Regardless of whether you call your dropdown via JavaScript or instead use the data-api, `data-toggle="dropdown"` is always required to be present on the dropdown's trigger element.
{% endcallout %}
### Options
-*None.*
+Options can be passed via data attributes or JavaScript. For data attributes, append the option name to `data-`, as in `data-placement=""`.
+
+<table class="table table-bordered table-striped table-responsive">
+ <thead>
+ <tr>
+ <th style="width: 100px;">Name</th>
+ <th style="width: 100px;">Type</th>
+ <th style="width: 50px;">Default</th>
+ <th>Description</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>placement</td>
+ <td>string</td>
+ <td>'bottom'</td>
+ <td>
+ <p>How to position the popover - top | bottom.</p>
+ </td>
+ </tr>
+ <tr>
+ <td>offset</td>
+ <td>number | string</td>
+ <td>0</td>
+ <td>Offset of the dropdown relative to its target. For more information refer to Popper.js's <a href="https://popper.js.org/popper-documentation.html#modifiers..offset.offset">offset docs</a>.</td>
+ </tr>
+ <tr>
+ <td>flip</td>
+ <td>boolean</td>
+ <td>true</td>
+ <td>Allow Dropdown to flip in case of an overlapping on the reference element. For more information refer to Popper.js's <a href="https://popper.js.org/popper-documentation.html#modifiers..flip.enabled">flip docs</a>.</td>
+ </tr>
+ </tbody>
+</table>
### Methods
| Method | Description |
| --- | --- |
| `$().dropdown('toggle')` | Toggles the dropdown menu of a given navbar or tabbed navigation. |
+| `$().dropdown('update')` | Updates the position of an element's dropdown. |
### Events