aboutsummaryrefslogtreecommitdiff
path: root/site/content/docs/5.0/components
diff options
context:
space:
mode:
authorXhmikosR <[email protected]>2021-07-29 09:14:40 +0300
committerGitHub <[email protected]>2021-07-29 09:14:40 +0300
commitef5336373fc2431b3d1d37cde85cd262210a1dc6 (patch)
treee325fb4c5532b464d05780c731d0f118f2a88d7f /site/content/docs/5.0/components
parent62edf07d7491684fe67a9c1e9439ed2bd10ca741 (diff)
parentc6c0bbb0b67fe89b55740a63fd10d4ad79044970 (diff)
downloadbootstrap-main-fod-simpler-table-structure.tar.xz
bootstrap-main-fod-simpler-table-structure.zip
Merge branch 'main' into main-fod-simpler-table-structuremain-fod-simpler-table-structure
Diffstat (limited to 'site/content/docs/5.0/components')
-rw-r--r--site/content/docs/5.0/components/alerts.md69
-rw-r--r--site/content/docs/5.0/components/collapse.md25
-rw-r--r--site/content/docs/5.0/components/modal.md9
-rw-r--r--site/content/docs/5.0/components/navbar.md64
-rw-r--r--site/content/docs/5.0/components/navs-tabs.md8
-rw-r--r--site/content/docs/5.0/components/offcanvas.md10
-rw-r--r--site/content/docs/5.0/components/toasts.md34
7 files changed, 190 insertions, 29 deletions
diff --git a/site/content/docs/5.0/components/alerts.md b/site/content/docs/5.0/components/alerts.md
index a7e52f5f8..338976323 100644
--- a/site/content/docs/5.0/components/alerts.md
+++ b/site/content/docs/5.0/components/alerts.md
@@ -23,6 +23,45 @@ Alerts are available for any length of text, as well as an optional close button
{{< partial "callout-warning-color-assistive-technologies.md" >}}
{{< /callout >}}
+### Live example
+
+Click the button below to show an alert (hidden with inline styles to start), then dismiss (and destroy) it with the built-in close button.
+
+<div id="liveAlertPlaceholder"></div>
+
+<div class="bd-example">
+ <button type="button" class="btn btn-primary" id="liveAlertBtn">Show live alert</button>
+</div>
+
+```html
+<button type="button" class="btn btn-primary" id="liveAlertBtn">Show live alert</button>
+
+<div class="alert alert-primary alert-dismissible" role="alert" id="liveAlert">
+ <strong>Nice!</strong> You've triggered this alert.
+ <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
+</div>
+```
+
+We use the following JavaScript to trigger our live alert demo:
+
+```js
+var alertPlaceholder = document.getElementById('liveAlertPlaceholder')
+var alertTrigger = document.getElementById('liveAlertBtn')
+
+function alert(message, type) {
+ var wrapper = document.createElement('div')
+ wrapper.innerHTML = '<div class="alert alert-' + type + ' alert-dismissible" role="alert">' + message + '<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button></div>'
+
+ alertPlaceholder.append(wrapper)
+}
+
+if (alertTrigger) {
+ alertTrigger.addEventListener('click', function () {
+ alert('Nice, you triggered this alert message!', 'success')
+ })
+}
+```
+
### Link color
Use the `.alert-link` utility class to quickly provide matching colored links within any alert.
@@ -147,35 +186,29 @@ Loop that generates the modifier classes with the `alert-variant()` mixin.
## JavaScript behavior
-### Triggers
+### Initialize
-Enable dismissal of an alert via JavaScript:
+Initialize elements as alerts
```js
var alertList = document.querySelectorAll('.alert')
-alertList.forEach(function (alert) {
- new bootstrap.Alert(alert)
+var alerts = [].slice.call(alertList).map(function (element) {
+ return new bootstrap.Alert(element)
})
```
+{{< callout info >}}
+For the sole purpose of dismissing an alert, it isn't necessary to initialize the component manually via the JS API. By making use of `data-bs-dismiss="alert"`, the component will be initialized automatically and properly dismissed.
-Or with `data` attributes on a button **within the alert**, as demonstrated above:
-
-```html
-<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
-```
-
-Note that closing an alert will remove it from the DOM.
+See the [triggers](#triggers) section for more details.
+{{< /callout >}}
-### Methods
+### Triggers
-You can create an alert instance with the alert constructor, for example:
+{{% js-dismiss "alert" %}}
-```js
-var myAlert = document.getElementById('myAlert')
-var bsAlert = new bootstrap.Alert(myAlert)
-```
+**Note that closing an alert will remove it from the DOM.**
-This makes an alert listen for click events on descendant elements which have the `data-bs-dismiss="alert"` attribute. (Not necessary when using the data-api's auto-initialization.)
+### Methods
<table class="table">
<thead>
diff --git a/site/content/docs/5.0/components/collapse.md b/site/content/docs/5.0/components/collapse.md
index ac84ca964..5d413ad75 100644
--- a/site/content/docs/5.0/components/collapse.md
+++ b/site/content/docs/5.0/components/collapse.md
@@ -40,6 +40,29 @@ Generally, we recommend using a button with the `data-bs-target` attribute. Whil
</div>
{{< /example >}}
+## Horizontal
+
+The collapse plugin also supports horizontal collapsing. Add the `.collapse-horizontal` modifier class to transition the `width` instead of `height` and set a `width` on the immediate child element. Feel free to write your own custom Sass, use inline styles, or use our [width utilities]({{< docsref "/utilities/sizing" >}}).
+
+{{< callout info >}}
+Please note that while the example below has a `min-height` set to avoid excessive repaints in our docs, this is not explicitly required. **Only the `width` on the child element is required.**
+{{< /callout >}}
+
+{{< example >}}
+<p>
+ <button class="btn btn-primary" type="button" data-bs-toggle="collapse" data-bs-target="#collapseWidthExample" aria-expanded="false" aria-controls="collapseWidthExample">
+ Toggle width collapse
+ </button>
+</p>
+<div style="min-height: 120px;">
+ <div class="collapse collapse-horizontal" id="collapseWidthExample">
+ <div class="card card-body" style="width: 300px;">
+ This is some placeholder content for a horizontal collapse. It's hidden by default and shown when triggered.
+ </div>
+ </div>
+</div>
+{{< /example >}}
+
## Multiple targets
A `<button>` or `<a>` can show and hide multiple elements by referencing them with a selector in its `href` or `data-bs-target` attribute.
@@ -103,7 +126,7 @@ These classes can be found in `_transitions.scss`.
Just add `data-bs-toggle="collapse"` and a `data-bs-target` to the element to automatically assign control of one or more collapsible elements. The `data-bs-target` attribute accepts a CSS selector to apply the collapse to. Be sure to add the class `collapse` to the collapsible element. If you'd like it to default open, add the additional class `show`.
-To add accordion-like group management to a collapsible area, add the data attribute `data-bs-parent="#selector"`. Refer to the demo to see this in action.
+To add accordion-like group management to a collapsible area, add the data attribute `data-bs-parent="#selector"`. Refer to the [accordion page]({{< docsref "/components/accordion" >}}) for more information.
### Via JavaScript
diff --git a/site/content/docs/5.0/components/modal.md b/site/content/docs/5.0/components/modal.md
index e6a838aac..56fad0297 100644
--- a/site/content/docs/5.0/components/modal.md
+++ b/site/content/docs/5.0/components/modal.md
@@ -831,11 +831,20 @@ The modal plugin toggles your hidden content on demand, via data attributes or J
### Via data attributes
+#### Toggle
+
Activate a modal without writing JavaScript. Set `data-bs-toggle="modal"` on a controller element, like a button, along with a `data-bs-target="#foo"` or `href="#foo"` to target a specific modal to toggle.
```html
<button type="button" data-bs-toggle="modal" data-bs-target="#myModal">Launch modal</button>
```
+#### Dismiss
+
+{{% js-dismiss "modal" %}}
+
+{{< callout warning >}}
+While both ways to dismiss a modal are supported, keep in mind that dismissing from outside a modal does not match [the WAI-ARIA modal dialog design pattern](https://www.w3.org/TR/wai-aria-practices-1.1/#dialog_modal). Do this at your own risk.
+{{< /callout >}}
### Via JavaScript
diff --git a/site/content/docs/5.0/components/navbar.md b/site/content/docs/5.0/components/navbar.md
index 7b57fd5c6..1abfcd16c 100644
--- a/site/content/docs/5.0/components/navbar.md
+++ b/site/content/docs/5.0/components/navbar.md
@@ -655,6 +655,70 @@ Sometimes you want to use the collapse plugin to trigger a container element for
When you do this, we recommend including additional JavaScript to move the focus programmatically to the container when it is opened. Otherwise, keyboard users and users of assistive technologies will likely have a hard time finding the newly revealed content - particularly if the container that was opened comes *before* the toggler in the document's structure. We also recommend making sure that the toggler has the `aria-controls` attribute, pointing to the `id` of the content container. In theory, this allows assistive technology users to jump directly from the toggler to the container it controls–but support for this is currently quite patchy.
+### Offcanvas
+
+Transform your expanding and collapsing navbar into an offcanvas drawer with the offcanvas plugin. We extend both the offcanvas default styles and use our `.navbar-expand-*` classes to create a dynamic and flexible navigation sidebar.
+
+In the example below, to create an offcanvas navbar that is always collapsed across all breakpoints, omit the `.navbar-expand-*` class entirely.
+
+{{< example >}}
+<nav class="navbar navbar-light bg-light fixed-top">
+ <div class="container-fluid">
+ <a class="navbar-brand" href="#">Offcanvas navbar</a>
+ <button class="navbar-toggler" type="button" data-bs-toggle="offcanvas" data-bs-target="#offcanvasNavbar" aria-controls="offcanvasNavbar">
+ <span class="navbar-toggler-icon"></span>
+ </button>
+ <div class="offcanvas offcanvas-end" tabindex="-1" id="offcanvasNavbar" aria-labelledby="offcanvasNavbarLabel">
+ <div class="offcanvas-header">
+ <h5 class="offcanvas-title" id="offcanvasNavbarLabel">Offcanvas</h5>
+ <button type="button" class="btn-close text-reset" data-bs-dismiss="offcanvas" aria-label="Close"></button>
+ </div>
+ <div class="offcanvas-body">
+ <ul class="navbar-nav justify-content-end flex-grow-1 pe-3">
+ <li class="nav-item">
+ <a class="nav-link active" aria-current="page" href="#">Home</a>
+ </li>
+ <li class="nav-item">
+ <a class="nav-link" href="#">Link</a>
+ </li>
+ <li class="nav-item dropdown">
+ <a class="nav-link dropdown-toggle" href="#" id="offcanvasNavbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
+ Dropdown
+ </a>
+ <ul class="dropdown-menu" aria-labelledby="offcanvasNavbarDropdown">
+ <li><a class="dropdown-item" href="#">Action</a></li>
+ <li><a class="dropdown-item" href="#">Another action</a></li>
+ <li>
+ <hr class="dropdown-divider">
+ </li>
+ <li><a class="dropdown-item" href="#">Something else here</a></li>
+ </ul>
+ </li>
+ </ul>
+ <form class="d-flex">
+ <input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
+ <button class="btn btn-outline-success" type="submit">Search</button>
+ </form>
+ </div>
+ </div>
+ </div>
+</nav>
+{{< /example >}}
+
+To create an offcanvas navbar that expands into a normal navbar at a specific breakpoint like `lg`, use `.navbar-expand-lg`.
+
+```html
+<nav class="navbar navbar-light navbar-expand-lg bg-light fixed-top">
+ <a class="navbar-brand" href="#">Offcanvas navbar</a>
+ <button class="navbar-toggler" type="button" data-bs-toggle="offcanvas" data-bs-target="#navbarOffcanvasLg" aria-controls="navbarOffcanvasLg">
+ <span class="navbar-toggler-icon"></span>
+ </button>
+ <div class="offcanvas offcanvas-end" tabindex="-1" id="navbarOffcanvasLg" aria-labelledby="navbarOffcanvasLgLabel">
+ ...
+ </div>
+</nav>
+```
+
## Sass
### Variables
diff --git a/site/content/docs/5.0/components/navs-tabs.md b/site/content/docs/5.0/components/navs-tabs.md
index b839f9754..dd5a3e08a 100644
--- a/site/content/docs/5.0/components/navs-tabs.md
+++ b/site/content/docs/5.0/components/navs-tabs.md
@@ -525,7 +525,7 @@ You can activate a tab or pill navigation without writing any JavaScript by simp
Enable tabbable tabs via JavaScript (each tab needs to be activated individually):
```js
-var triggerTabList = [].slice.call(document.querySelectorAll('#myTab a'))
+var triggerTabList = [].slice.call(document.querySelectorAll('#myTab button'))
triggerTabList.forEach(function (triggerEl) {
var tabTrigger = new bootstrap.Tab(triggerEl)
@@ -539,10 +539,10 @@ triggerTabList.forEach(function (triggerEl) {
You can activate individual tabs in several ways:
```js
-var triggerEl = document.querySelector('#myTab a[href="#profile"]')
+var triggerEl = document.querySelector('#myTab button[data-bs-target="#profile"]')
bootstrap.Tab.getInstance(triggerEl).show() // Select tab by name
-var triggerFirstTabEl = document.querySelector('#myTab li:first-child a')
+var triggerFirstTabEl = document.querySelector('#myTab li:first-child button')
bootstrap.Tab.getInstance(triggerFirstTabEl).show() // Select first tab
```
@@ -593,7 +593,7 @@ Activates a tab element and content container. Tab should have either a `data-bs
</div>
<script>
- var firstTabEl = document.querySelector('#myTab li:last-child a')
+ var firstTabEl = document.querySelector('#myTab li:last-child button')
var firstTab = new bootstrap.Tab(firstTabEl)
firstTab.show()
diff --git a/site/content/docs/5.0/components/offcanvas.md b/site/content/docs/5.0/components/offcanvas.md
index d0c60db2b..c28e005e6 100644
--- a/site/content/docs/5.0/components/offcanvas.md
+++ b/site/content/docs/5.0/components/offcanvas.md
@@ -194,8 +194,18 @@ Add a dismiss button with the `data-bs-dismiss="offcanvas"` attribute, which tri
### Via data attributes
+#### Toggle
+
Add `data-bs-toggle="offcanvas"` and a `data-bs-target` or `href` to the element to automatically assign control of one offcanvas element. The `data-bs-target` attribute accepts a CSS selector to apply the offcanvas to. Be sure to add the class `offcanvas` to the offcanvas element. If you'd like it to default open, add the additional class `show`.
+#### Dismiss
+
+{{% js-dismiss "offcanvas" %}}
+
+{{< callout warning >}}
+While both ways to dismiss an offcanvas are supported, keep in mind that dismissing from outside an offcanvas does not match [the WAI-ARIA modal dialog design pattern](https://www.w3.org/TR/wai-aria-practices-1.1/#dialog_modal). Do this at your own risk.
+{{< /callout >}}
+
### Via JavaScript
Enable manually with:
diff --git a/site/content/docs/5.0/components/toasts.md b/site/content/docs/5.0/components/toasts.md
index 2dde09f5b..d17d8b3df 100644
--- a/site/content/docs/5.0/components/toasts.md
+++ b/site/content/docs/5.0/components/toasts.md
@@ -41,12 +41,16 @@ Toasts are as flexible as you need and have very little required markup. At a mi
</div>
{{< /example >}}
-### Live
+{{< callout warning >}}
+Previously, our scripts dynamically added the `.hide` class to completely hide a toast (with `display:none`, rather than just with `opacity:0`). This is now not necessary anymore. However, for backwards compatibility, our script will continue to toggle the class (even though there is no practical need for it) until the next major version.
+{{< /callout >}}
+
+### Live example
-Click the button below to show a toast (positioned with our utilities in the lower right corner) that has been hidden by default with `.hide`.
+Click the button below to show a toast (positioned with our utilities in the lower right corner) that has been hidden by default.
<div class="position-fixed bottom-0 end-0 p-3" style="z-index: 11">
- <div id="liveToast" class="toast hide" role="alert" aria-live="assertive" aria-atomic="true">
+ <div id="liveToast" class="toast" role="alert" aria-live="assertive" aria-atomic="true">
<div class="toast-header">
{{< placeholder width="20" height="20" background="#007aff" class="rounded me-2" text="false" title="false" >}}
<strong class="me-auto">Bootstrap</strong>
@@ -67,7 +71,7 @@ Click the button below to show a toast (positioned with our utilities in the low
<button type="button" class="btn btn-primary" id="liveToastBtn">Show live toast</button>
<div class="position-fixed bottom-0 end-0 p-3" style="z-index: 11">
- <div id="liveToast" class="toast hide" role="alert" aria-live="assertive" aria-atomic="true">
+ <div id="liveToast" class="toast" role="alert" aria-live="assertive" aria-atomic="true">
<div class="toast-header">
<img src="..." class="rounded me-2" alt="...">
<strong class="me-auto">Bootstrap</strong>
@@ -81,6 +85,20 @@ Click the button below to show a toast (positioned with our utilities in the low
</div>
```
+We use the following JavaScript to trigger our live toast demo:
+
+```js
+var toastTrigger = document.getElementById('liveToastBtn')
+var toastLiveExample = document.getElementById('liveToast')
+if (toastTrigger) {
+ toastTrigger.addEventListener('click', function () {
+ var toast = new bootstrap.Toast(toastLiveExample)
+
+ toast.show()
+ })
+}
+```
+
### Translucent
Toasts are slightly translucent to blend in with what's below them.
@@ -323,6 +341,10 @@ var toastList = toastElList.map(function (toastEl) {
})
```
+### Triggers
+
+{{% js-dismiss "toast" %}}
+
### Options
Options can be passed via data attributes or JavaScript. For data attributes, append the option name to `data-bs-`, as in `data-bs-animation=""`.
@@ -393,7 +415,7 @@ toast.dispose()
#### getInstance
-*Static* method which allows you to get the scrollspy instance associated with a DOM element
+*Static* method which allows you to get the toast instance associated with a DOM element
```js
var myToastEl = document.getElementById('myToastEl')
@@ -402,7 +424,7 @@ var myToast = bootstrap.Toast.getInstance(myToastEl) // Returns a Bootstrap toas
#### getOrCreateInstance
-*Static* method which allows you to get the scrollspy instance associated with a DOM element, or create a new one in case it wasn't initialised
+*Static* method which allows you to get the toast instance associated with a DOM element, or create a new one in case it wasn't initialised
```js
var myToastEl = document.getElementById('myToastEl')