From 4bfd8a2cbcb10610b4078cefa45756b4a96301a0 Mon Sep 17 00:00:00 2001 From: GeoSot Date: Wed, 28 Jul 2021 17:39:32 +0300 Subject: Use a streamlined way to trigger component dismiss (#34170) * use a streamlined way to trigger component dismiss * add documentation Co-authored-by: XhmikosR --- site/content/docs/5.0/components/alerts.md | 12 +----------- site/content/docs/5.0/components/modal.md | 11 +---------- site/content/docs/5.0/components/offcanvas.md | 10 ++++++++++ site/content/docs/5.0/components/toasts.md | 4 ++++ 4 files changed, 16 insertions(+), 21 deletions(-) (limited to 'site/content/docs') diff --git a/site/content/docs/5.0/components/alerts.md b/site/content/docs/5.0/components/alerts.md index e3862de48..338976323 100644 --- a/site/content/docs/5.0/components/alerts.md +++ b/site/content/docs/5.0/components/alerts.md @@ -204,17 +204,7 @@ See the [triggers](#triggers) section for more details. ### Triggers -Dismissal can be achieved with `data` attributes on a button **within the alert** as demonstrated above: - -```html - -``` - -or on a button **outside the alert** using the `data-bs-target` as demonstrated above: - -```html - -``` +{{% js-dismiss "alert" %}} **Note that closing an alert will remove it from the DOM.** diff --git a/site/content/docs/5.0/components/modal.md b/site/content/docs/5.0/components/modal.md index 7ba55b3b5..56fad0297 100644 --- a/site/content/docs/5.0/components/modal.md +++ b/site/content/docs/5.0/components/modal.md @@ -840,17 +840,8 @@ Activate a modal without writing JavaScript. Set `data-bs-toggle="modal"` on a c ``` #### Dismiss -Dismissal can be achieved with `data` attributes on a button **within the modal** as demonstrated below: +{{% js-dismiss "modal" %}} -```html - -``` - -or on a button **outside the modal** using the `data-bs-target` as demonstrated below: - -```html - -``` {{< 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 >}} 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 dc9501b67..d17d8b3df 100644 --- a/site/content/docs/5.0/components/toasts.md +++ b/site/content/docs/5.0/components/toasts.md @@ -341,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=""`. -- cgit v1.2.3