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
Original file line number
Diff line number
Diff line change
@@ -13,14 +13,14 @@ other_frameworks: offcanvas
13
13
14
14
## How it works
15
15
16
-
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.
16
+
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.
17
17
18
-
- Offcanvas shares some of the same JavaScript code as modals. Conceptually, they are quite similar, but they are separate plugins.
19
-
-Similarly, some [source Sass](#sass) variables for offcanvas's styles and dimensions are inherited from the modal's variables.
20
-
- When shown, offcanvas includes a default backdrop that can be clicked to hide the offcanvas.
21
-
-Similar to modals, only one offcanvas can be shown at a time.
18
+
- Offcanvas shares some JavaScript code with modals. Conceptually, they are quite similar, but they remain separate plugins.
19
+
-Likewise, some [source Sass](#sass) variables for offcanvas styles and dimensions are derived from the modal variables.
20
+
- When displayed, offcanvas features a default backdrop that can be clicked to hide it.
21
+
-As with modals, only one offcanvas can be displayed at a time.
22
22
23
-
**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.
23
+
**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.
@@ -30,7 +30,7 @@ Offcanvas is a sidebar component that can be toggled via JavaScript to appear fr
30
30
31
31
### Offcanvas components
32
32
33
-
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.
33
+
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.
34
34
35
35
{{< 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.
42
+
The content for the Bootstrap offcanvas goes here. You can place nearly any Bootstrap component or custom element here.
43
43
</div>
44
44
</div>
45
45
{{< /example >}}
46
46
47
47
### Live demo
48
48
49
-
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.
49
+
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.
50
50
51
-
-`.offcanvas` hides content (default)
52
-
-`.offcanvas.show` shows content
51
+
-`.offcanvas` hides content.
52
+
-`.offcanvas.show` shows content.
53
53
54
-
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.
54
+
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.
@@ -86,7 +86,7 @@ You can use a link with the `href` attribute, or a button with the `data-coreui-
86
86
87
87
### Body scrolling
88
88
89
-
Scrolling the `<body>` elementis disabled when an offcanvas and its backdrop are visible. Use the `data-coreui-scroll` attribute to enable `<body>` scrolling.
89
+
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>`.
90
90
91
91
{{< example >}}
92
92
<buttonclass="btn btn-primary"type="button"data-coreui-toggle="offcanvas"data-coreui-target="#offcanvasScrolling"aria-controls="offcanvasScrolling">Enable body scrolling</button>
@@ -97,7 +97,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`.
149
+
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`.
150
150
151
151
{{< callout warning >}}
152
-
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.
152
+
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.
153
153
{{< /callout >}}
154
154
155
155
{{< example class="docs-example-offcanvas p-0 bg-body-secondary overflow-hidden" >}}
@@ -168,7 +168,7 @@ Heads up! Dark variants for components were deprecated in v5.3.0 with the introd
168
168
169
169
{{< added-in "4.2.6" >}}
170
170
171
-
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.
171
+
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.
@@ -186,7 +186,7 @@ Responsive offcanvas classes hide content outside the viewport from a specified
186
186
</div>
187
187
{{< /example >}}
188
188
189
-
Responsive offcanvas classes are available across for each breakpoint.
189
+
Responsive offcanvas classes are available for each breakpoint.
190
190
191
191
-`.offcanvas`
192
192
-`.offcanvas-sm`
@@ -197,14 +197,14 @@ Responsive offcanvas classes are available across for each breakpoint.
197
197
198
198
## Placement
199
199
200
-
There's no default placement for offcanvas components, so you must add one of the modifier classes below.
200
+
Offcanvas components do not have a default position; therefore, you need to apply one of the modifier classes listed below.
201
201
202
-
-`.offcanvas-start` places offcanvas on the left of the viewport (shown above)
203
-
-`.offcanvas-end` places offcanvas on the right of the viewport
204
-
-`.offcanvas-top` places offcanvas on the top of the viewport
205
-
-`.offcanvas-bottom` places offcanvas on the bottom of the viewport
202
+
-`.offcanvas-start` places the offcanvas on the left side of the viewport (as shown above)
203
+
-`.offcanvas-end` places the offcanvas on the right side of the viewport
204
+
-`.offcanvas-top` places offcanvas at the top of the viewport
205
+
-`.offcanvas-bottom` places offcanvas at the bottom of the viewport
206
206
207
-
Try the top, right, and bottom examples out below.
207
+
Feel free to experiment with the top, right, and bottom examples below.
208
208
209
209
{{< example >}}
210
210
<buttonclass="btn btn-primary"type="button"data-coreui-toggle="offcanvas"data-coreui-target="#offcanvasTop"aria-controls="offcanvasTop">Toggle top offcanvas</button>
@@ -256,27 +256,27 @@ Since the offcanvas panel is conceptually a modal dialog, be sure to add `aria-l
256
256
257
257
{{< bootstrap-compatibility >}}
258
258
259
-
The offcanvas plugin utilizes a few classes and attributes to handle the heavy lifting:
259
+
The offcanvas plugin leverages several classes and attributes to perform its functions:
260
260
261
261
-`.offcanvas` hides the content
262
262
-`.offcanvas.show` shows the content
263
263
-`.offcanvas-start` hides the offcanvas on the left
264
264
-`.offcanvas-end` hides the offcanvas on the right
265
-
-`.offcanvas-top` hides the offcanvas on the top
266
-
-`.offcanvas-bottom` hides the offcanvas on the bottom
265
+
-`.offcanvas-top` hides the offcanvas at the top
266
+
-`.offcanvas-bottom` hides the offcanvas at the bottom
267
267
268
-
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.
268
+
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.
269
269
270
270
### Via data attributes
271
271
272
-
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`.
272
+
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.
273
273
274
274
#### Dismiss
275
275
276
276
{{% js-dismiss "offcanvas" %}}
277
277
278
278
{{< callout warning >}}
279
-
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.
279
+
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. |
301
-
|`keyboard`| boolean |`true`| Closes the offcanvas when escape key is pressed |
302
-
|`scroll`| boolean |`false`|Allow body scrolling while offcanvas is open|
300
+
|`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. |
301
+
|`keyboard`| boolean |`true`| Closes the offcanvas when the escape key is pressed.|
302
+
| `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 |
323
-
|`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 |
324
-
|`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).|
325
-
|`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).|
326
-
|`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).|
322
+
|`getInstance`|*Static* method that allows you to obtain the offcanvas instance associated with a DOM element |
323
+
|`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 |
324
+
|`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).|
325
+
|`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).|
326
+
| `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).
327
327
{{< /bs-table >}}
328
328
329
329
### Events
330
330
331
331
CoreUI for Bootstrap's offcanvas class exposes a few events for hooking into offcanvas functionality.
332
332
333
333
{{< bs-table "table" >}}
334
-
| Event type| Description |
334
+
| Event Type| Description |
335
335
| --- | --- |
336
-
|`hide.coreui.offcanvas`| This event is fired immediately when the `hide` method has been called. |
337
-
|`hidden.coreui.offcanvas`| This event is fired when an offcanvas element has been hidden from the user (will wait for CSS transitions to complete). |
338
-
|`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`. |
339
-
|`show.coreui.offcanvas`| This event fires immediately when the `show` instance method is called. |
340
-
|`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).|
336
+
|`hide.coreui.offcanvas`| This event is fired immediately after the `hide` method has been called. |
337
+
|`hidden.coreui.offcanvas`| This event is fired when an offcanvas element is hidden from the user (it will wait for CSS transitions to complete). |
338
+
|`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`. |
339
+
|`show.coreui.offcanvas`| This event fires immediately when the `show` instance method is invoked. |
340
+
| `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.
354
+
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