You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/content/components/offcanvas.md
+52-52Lines changed: 52 additions & 52 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,14 +10,14 @@ other_frameworks: offcanvas
10
10
11
11
## How it works
12
12
13
-
Offcanvas is a sidebar component that can be toggled via JavaScriptto appear from the left, right, top, or bottom edge of the viewport. Buttons or anchors are used as triggers that are attached to specific elements you toggle, and `data` attributes are used to invoke our JavaScript.
13
+
The Bootstrap Offcanvas component serves as a sidebar element that can be activated through JavaScript, allowing it to slide in from the left, right, top, or bottom of the viewport. Triggers, like buttons or anchors, are linked to the elements you want to toggle, and data attributes facilitate their activation in JavaScript.
14
14
15
-
- Offcanvas shares some of the same JavaScript code as modals. Conceptually, they are quite similar, but they are separate plugins.
16
-
-Similarly, some [source Sass](#sass) variables for offcanvas's styles and dimensions are inherited from the modal's variables.
17
-
- When shown, offcanvas includes a default backdrop that can be clicked to hide the offcanvas.
18
-
-Similar to modals, only one offcanvas can be shown at a time.
15
+
- Offcanvas shares some JavaScript code with modals. Conceptually, they are quite similar, but they remain separate plugins.
16
+
-Likewise, some [source Sass](#sass) variables for offcanvas styles and dimensions are derived from the modal variables.
17
+
- When displayed, offcanvas features a default backdrop that can be clicked to hide it.
18
+
-As with modals, only one offcanvas can be displayed at a time.
19
19
20
-
**Heads up!**Given how CSS handles animations, you cannot use `margin` or `translate`on an `.offcanvas` element. Instead, use the class as an independent wrapping element.
20
+
**Attention!**Due to CSS animation handling, `margin` or `translate`cannot be applied to an `.offcanvas` element. Instead, utilize the class as a separate wrapping element.
@@ -27,7 +27,7 @@ Offcanvas is a sidebar component that can be toggled via JavaScript to appear fr
27
27
28
28
### Offcanvas components
29
29
30
-
Below is an offcanvas example that is shown by default (via `.show` on `.offcanvas`). Offcanvas includes support for a header with a close button and an optional body class for some initial `padding`. We suggest that you include offcanvas headers with dismiss actions whenever possible, or provide an explicit dismiss action.
30
+
Below is a default offcanvas example (via `.show` on `.offcanvas`). Offcanvas supports a header with a close button and an optional body class for initial `padding`. We recommend including offcanvas headers with dismiss actions whenever possible, or providing an explicit dismiss action.
31
31
32
32
{{< example class="docs-example-offcanvas p-0 bg-light overflow-hidden" >}}
Content for the offcanvas goes here. You can place just about any Bootstrap component or custom elements here.
39
+
The content for the Bootstrap offcanvas goes here. You can place nearly any Bootstrap component or custom element here.
40
40
</div>
41
41
</div>
42
42
{{< /example >}}
43
43
44
44
### Live demo
45
45
46
-
Use the buttons below to show and hide an offcanvas element via JavaScript that toggles the `.show` class on an element with the `.offcanvas` class.
46
+
Utilize the buttons below to toggle the visibility of an offcanvas element using JavaScript, which adds or removes the `.show` class from an element with the `.offcanvas` class.
47
47
48
-
-`.offcanvas` hides content (default)
49
-
-`.offcanvas.show` shows content
48
+
-`.offcanvas` hides content.
49
+
-`.offcanvas.show` shows content.
50
50
51
-
You can use a link with the `href` attribute, or a button with the `data-coreui-target` attribute. In both cases, the`data-coreui-toggle="offcanvas"` is required.
51
+
You can employ a link with the `href` attribute or a button featuring the `data-coreui-target` attribute. In both instances, including`data-coreui-toggle="offcanvas"` is necessary.
@@ -83,7 +83,7 @@ You can use a link with the `href` attribute, or a button with the `data-coreui-
83
83
84
84
### Body scrolling
85
85
86
-
Scrolling the `<body>` elementis disabled when an offcanvas and its backdrop are visible. Use the `data-coreui-scroll` attribute to enable `<body>` scrolling.
86
+
The `<body>` element's scrolling is disabled when the Bootstrap offcanvas and its backdrop are visible. Utilize the `data-coreui-scroll` attribute to allow scrolling on the `<body>`.
87
87
88
88
{{< example >}}
89
89
<buttonclass="btn btn-primary"type="button"data-coreui-toggle="offcanvas"data-coreui-target="#offcanvasScrolling"aria-controls="offcanvasScrolling">Enable body scrolling</button>
@@ -94,7 +94,8 @@ Scrolling the `<body>` element is disabled when an offcanvas and its backdrop ar
Change the appearance of offcanvases with utilities to better match them to different contexts like dark navbars. Here we add `.text-bg-dark` to the `.offcanvas` and `.btn-close-white` to `.btn-close` for proper styling with a dark offcanvas. If you have dropdowns within, consider also adding `.dropdown-menu-dark` to `.dropdown-menu`.
146
+
Change the appearance of offcanvas elements using utilities to better match various contexts, such as dark navbars. Here, we add `.text-bg-dark` to the `.offcanvas` and `.btn-close-white` to `.btn-close` for proper styling with a dark offcanvas. If there are dropdowns inside, consider also adding `.dropdown-menu-dark` to `.dropdown-menu`.
147
147
148
148
{{< callout warning >}}
149
-
Heads up! Dark variants for components were deprecated in v5.3.0 with the introduction of color modes. Instead of manually adding classes mentioned above, set `data-coreui-theme="dark"` on the root element, a parent wrapper, or the component itself.
149
+
Attention! Dark variants for components are no longer supported as of v5.3.0 due to the introduction of color modes. Instead of manually adding the classes mentioned earlier, simply set `data-coreui-theme="dark"` on the root element, a parent wrapper, or the component itself.
150
150
{{< /callout >}}
151
151
152
152
{{< example class="docs-example-offcanvas p-0 bg-body-secondary overflow-hidden" >}}
@@ -165,7 +165,7 @@ Heads up! Dark variants for components were deprecated in v5.3.0 with the introd
165
165
166
166
{{< added-in "4.2.6" >}}
167
167
168
-
Responsive offcanvas classes hide content outside the viewport from a specified breakpoint and down. Above that breakpoint, the contents within will behave as usual. For example, `.offcanvas-lg` hides content in an offcanvas below the `lg` breakpoint, but shows the content above the `lg` breakpoint.
168
+
Responsive offcanvas classes hide content that is outside the viewport from a specified breakpoint and lower. Above that breakpoint, the content will behave normally. For example, `.offcanvas-lg` hides content in an offcanvas below the `lg` breakpoint, but displays the content above the `lg` breakpoint.
@@ -183,7 +183,7 @@ Responsive offcanvas classes hide content outside the viewport from a specified
183
183
</div>
184
184
{{< /example >}}
185
185
186
-
Responsive offcanvas classes are available across for each breakpoint.
186
+
Responsive offcanvas classes are available for each breakpoint.
187
187
188
188
-`.offcanvas`
189
189
-`.offcanvas-sm`
@@ -194,14 +194,14 @@ Responsive offcanvas classes are available across for each breakpoint.
194
194
195
195
## Placement
196
196
197
-
There's no default placement for offcanvas components, so you must add one of the modifier classes below.
197
+
Offcanvas components do not have a default position; therefore, you need to apply one of the modifier classes listed below.
198
198
199
-
-`.offcanvas-start` places offcanvas on the left of the viewport (shown above)
200
-
-`.offcanvas-end` places offcanvas on the right of the viewport
201
-
-`.offcanvas-top` places offcanvas on the top of the viewport
202
-
-`.offcanvas-bottom` places offcanvas on the bottom of the viewport
199
+
-`.offcanvas-start` places the offcanvas on the left side of the viewport (as shown above)
200
+
-`.offcanvas-end` places the offcanvas on the right side of the viewport
201
+
-`.offcanvas-top` places offcanvas at the top of the viewport
202
+
-`.offcanvas-bottom` places offcanvas at the bottom of the viewport
203
203
204
-
Try the top, right, and bottom examples out below.
204
+
Feel free to experiment with the top, right, and bottom examples below.
205
205
206
206
{{< example >}}
207
207
<buttonclass="btn btn-primary"type="button"data-coreui-toggle="offcanvas"data-coreui-target="#offcanvasTop"aria-controls="offcanvasTop">Toggle top offcanvas</button>
@@ -253,27 +253,27 @@ Since the offcanvas panel is conceptually a modal dialog, be sure to add `aria-l
253
253
254
254
{{< bootstrap-compatibility >}}
255
255
256
-
The offcanvas plugin utilizes a few classes and attributes to handle the heavy lifting:
256
+
The offcanvas plugin leverages several classes and attributes to perform its functions:
257
257
258
258
-`.offcanvas` hides the content
259
259
-`.offcanvas.show` shows the content
260
260
-`.offcanvas-start` hides the offcanvas on the left
261
261
-`.offcanvas-end` hides the offcanvas on the right
262
-
-`.offcanvas-top` hides the offcanvas on the top
263
-
-`.offcanvas-bottom` hides the offcanvas on the bottom
262
+
-`.offcanvas-top` hides the offcanvas at the top
263
+
-`.offcanvas-bottom` hides the offcanvas at the bottom
264
264
265
-
Add a dismiss button with the `data-coreui-dismiss="offcanvas"` attribute, which triggers the JavaScript functionality. Be sure to use the `<button>` element with it for proper behavior across all devices.
265
+
Include a dismiss button using the `data-coreui-dismiss="offcanvas"` attribute to activate the JavaScript functionality. Ensure you use the `<button>` element for consistent behavior across all devices.
266
266
267
267
### Via data attributes
268
268
269
-
Add`data-coreui-toggle="offcanvas"`and a `data-coreui-target` or `href`to the element to automatically assign control of one offcanvas element. The `data-coreui-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`.
269
+
Include`data-coreui-toggle="offcanvas"`along with a `data-coreui-target` or `href`in the element to automatically control a single offcanvas component. The `data-coreui-target` attribute allows you to specify a CSS selector for the associated offcanvas. Remember to apply the `offcanvas`class to the offcanvas element. To have it open by default, also add the `show` class.
270
270
271
271
#### Dismiss
272
272
273
273
{{% js-dismiss "offcanvas" %}}
274
274
275
275
{{< callout warning >}}
276
-
While both ways to dismiss an offcanvas are supported, keep in mind that dismissing from outside an offcanvas does not match the [ARIA Authoring Practices Guide dialog (modal) pattern](https://www.w3.org/WAI/ARIA/apg/patterns/dialogmodal/). Do this at your own risk.
276
+
While both methods for dismissing an offcanvas are supported, remember that dismissing from the outside of an offcanvas does not align with the [ARIA Authoring Practices Guide dialog (modal) pattern](https://www.w3.org/WAI/ARIA/apg/patterns/dialogmodal/). Proceed with caution.
|`backdrop`| boolean or the string `static`|`true`|Apply a backdrop on body while offcanvas is open. Alternatively, specify `static` for a backdrop which doesn't close the offcanvas when clicked. |
298
-
|`keyboard`| boolean |`true`| Closes the offcanvas when escape key is pressed |
299
-
|`scroll`| boolean |`false`|Allow body scrolling while offcanvas is open|
297
+
|`backdrop`| boolean or the string `static`|`true`|Applies a backdrop to the body while the Bootstrap offcanvas is open. Alternatively, specify `static` for a backdrop that doesn't close the offcanvas component when clicked. |
298
+
|`keyboard`| boolean |`true`| Closes the offcanvas when the escape key is pressed.|
299
+
| `scroll` | boolean | `false` | Allows body scrolling while the offcanvas is open.
|`getInstance`|*Static* method which allows you to get the offcanvas instance associated with a DOM element |
320
-
|`getOrCreateInstance`|*Static* method which allows you to get the offcanvas instance associated with a DOM element, or create a new one in case it wasn't initialized |
321
-
|`hide`| Hides an offcanvas element. **Returns to the caller before the offcanvas element has actually been hidden** (i.e. before the `hidden.coreui.offcanvas` event occurs).|
322
-
|`show`|Shows an offcanvas element. **Returns to the caller before the offcanvas element has actually been shown** (i.e. before the `shown.coreui.offcanvas` event occurs).|
323
-
|`toggle`|Toggles an offcanvas element to shown or hidden. **Returns to the caller before the offcanvas element has actually been shown or hidden** (i.e. before the `shown.coreui.offcanvas` or `hidden.coreui.offcanvas` event occurs).|
319
+
|`getInstance`|*Static* method that allows you to obtain the offcanvas instance associated with a DOM element |
320
+
|`getOrCreateInstance`|*Static* method that enables you to retrieve the offcanvas instance linked to a DOM element, or create a new one if it hasn't been initialized |
321
+
|`hide`| Hides an offcanvas element. **Returns to the caller before the offcanvas element is actually hidden** (i.e. before the `hidden.coreui.offcanvas` event occurs).|
322
+
|`show`|Displays an offcanvas element. **Returns to the caller before the offcanvas element is actually shown** (i.e. before the `shown.coreui.offcanvas` event occurs).|
323
+
| `toggle` | Switches an offcanvas element between shown and hidden. **Returns to the caller before the offcanvas element is actually shown or hidden** (i.e. before the `shown.coreui.offcanvas` or `hidden.coreui.offcanvas` event occurs).
324
324
{{< /bs-table >}}
325
325
326
326
### Events
327
327
328
328
CoreUI for Bootstrap's offcanvas class exposes a few events for hooking into offcanvas functionality.
329
329
330
330
{{< bs-table "table" >}}
331
-
| Event type| Description |
331
+
| Event Type| Description |
332
332
| --- | --- |
333
-
|`hide.coreui.offcanvas`| This event is fired immediately when the `hide` method has been called. |
334
-
|`hidden.coreui.offcanvas`| This event is fired when an offcanvas element has been hidden from the user (will wait for CSS transitions to complete). |
335
-
|`hidePrevented.coreui.offcanvas`| This event is fired when the offcanvas is shown, its backdrop is `static` and a click outside of the offcanvas is performed. The event is also fired when the escape key is pressed and the `keyboard` option is set to `false`. |
336
-
|`show.coreui.offcanvas`| This event fires immediately when the `show` instance method is called. |
337
-
|`shown.coreui.offcanvas`| This event is fired when an offcanvas element has been made visible to the user (will wait for CSS transitions to complete).|
333
+
|`hide.coreui.offcanvas`| This event is fired immediately after the `hide` method has been called. |
334
+
|`hidden.coreui.offcanvas`| This event is fired when an offcanvas element is hidden from the user (it will wait for CSS transitions to complete). |
335
+
|`hidePrevented.coreui.offcanvas`| This event is triggered when the offcanvas is shown, its backdrop is `static`, and a click outside of the offcanvas occurs. The event is also triggered when the escape key is pressed and the `keyboard` option is set to `false`. |
336
+
|`show.coreui.offcanvas`| This event fires immediately when the `show` instance method is invoked. |
337
+
| `shown.coreui.offcanvas` | This event is fired when an offcanvas element becomes visible to the user (it will wait for CSS transitions to complete).
Offcanvas uses local CSS variables on `.offcanvas` for enhanced real-time customization. Values for the CSS variables are set via Sass, so Sass customization is still supported, too.
351
+
Offcanvas utilizes local CSS variables on `.offcanvas` for improved real-time customization. The values for the CSS variables are defined through Sass, ensuring that Sass customization remains supported as well.
0 commit comments