File tree 4 files changed +28
-6
lines changed
4 files changed +28
-6
lines changed Original file line number Diff line number Diff line change @@ -114,7 +114,7 @@ class Offcanvas extends BaseComponent {
114
114
this . _element . classList . add ( CLASS_NAME_SHOWING )
115
115
116
116
const completeCallBack = ( ) => {
117
- if ( ! this . _config . scroll ) {
117
+ if ( ! this . _config . scroll || this . _config . backdrop ) {
118
118
this . _focustrap . activate ( )
119
119
}
120
120
Original file line number Diff line number Diff line change @@ -293,7 +293,8 @@ describe('Offcanvas', () => {
293
293
294
294
const offCanvasEl = fixtureEl . querySelector ( '.offcanvas' )
295
295
const offCanvas = new Offcanvas ( offCanvasEl , {
296
- scroll : true
296
+ scroll : true ,
297
+ backdrop : false
297
298
} )
298
299
299
300
const spy = spyOn ( offCanvas . _focustrap , 'activate' ) . and . callThrough ( )
@@ -306,6 +307,27 @@ describe('Offcanvas', () => {
306
307
offCanvas . show ( )
307
308
} )
308
309
} )
310
+
311
+ it ( 'should trap focus if scroll is allowed OR backdrop is enabled' , ( ) => {
312
+ return new Promise ( resolve => {
313
+ fixtureEl . innerHTML = '<div class="offcanvas"></div>'
314
+
315
+ const offCanvasEl = fixtureEl . querySelector ( '.offcanvas' )
316
+ const offCanvas = new Offcanvas ( offCanvasEl , {
317
+ scroll : true ,
318
+ backdrop : true
319
+ } )
320
+
321
+ const spy = spyOn ( offCanvas . _focustrap , 'activate' ) . and . callThrough ( )
322
+
323
+ offCanvasEl . addEventListener ( 'shown.bs.offcanvas' , ( ) => {
324
+ expect ( spy ) . toHaveBeenCalled ( )
325
+ resolve ( )
326
+ } )
327
+
328
+ offCanvas . show ( )
329
+ } )
330
+ } )
309
331
} )
310
332
311
333
describe ( 'toggle' , ( ) => {
Original file line number Diff line number Diff line change 1
1
{{ define "main" }}
2
2
< div class ="container-xxl bd-gutter mt-3 my-md-4 bd-layout ">
3
3
< aside class ="bd-sidebar ">
4
- < div class ="offcanvas-lg offcanvas-start " id ="bdSidebar " aria-labelledby ="bdSidebarOffcanvasLabel ">
4
+ < div class ="offcanvas-lg offcanvas-start " tabindex =" -1 " id ="bdSidebar " aria-labelledby ="bdSidebarOffcanvasLabel ">
5
5
< div class ="offcanvas-header border-bottom ">
6
6
< h5 class ="offcanvas-title " id ="bdSidebarOffcanvasLabel "> Browse docs</ h5 >
7
7
< button type ="button " class ="btn-close " data-bs-dismiss ="offcanvas " aria-label ="Close " data-bs-target ="#bdSidebar "> </ button >
Original file line number Diff line number Diff line change 1
1
< header class ="navbar navbar-expand-lg navbar-dark bd-navbar sticky-top ">
2
2
< nav class ="container-xxl bd-gutter flex-wrap flex-lg-nowrap " aria-label ="Main navigation ">
3
3
{{- if eq .Layout "docs" }}
4
- < button class ="navbar-toggler p-2 " type ="button " data-bs-toggle ="offcanvas " data-bs-target ="#bdSidebar " aria-controls ="bdSidebar " aria-expanded =" false " aria- label ="Toggle docs navigation ">
4
+ < button class ="navbar-toggler p-2 " type ="button " data-bs-toggle ="offcanvas " data-bs-target ="#bdSidebar " aria-controls ="bdSidebar " aria-label ="Toggle docs navigation ">
5
5
{{ partial "icons/hamburger.svg" (dict "class" "bi" "width" "24" "height" "24") }}
6
6
< span class ="d-none fs-6 pe-1 "> Browse</ span >
7
7
</ button >
13
13
{{ partial "icons/bootstrap-white-fill.svg" (dict "class" "d-block my-1" "width" "40" "height" "32") }}
14
14
</ a >
15
15
16
- < button class ="navbar-toggler d-flex d-lg-none order-3 p-2 " type ="button " data-bs-toggle ="offcanvas " data-bs-target ="#bdNavbar " aria-controls ="bdNavbar " aria-expanded =" false " aria- label ="Toggle navigation ">
16
+ < button class ="navbar-toggler d-flex d-lg-none order-3 p-2 " type ="button " data-bs-toggle ="offcanvas " data-bs-target ="#bdNavbar " aria-controls ="bdNavbar " aria-label ="Toggle navigation ">
17
17
< svg class ="bi " aria-hidden ="true "> < use xlink:href ="#three-dots "> </ use > </ svg >
18
18
</ button >
19
19
20
- < div class ="offcanvas-lg offcanvas-end flex-grow-1 " id ="bdNavbar " aria-labelledby ="bdNavbarOffcanvasLabel " data-bs-scroll ="true ">
20
+ < div class ="offcanvas-lg offcanvas-end flex-grow-1 " tabindex =" -1 " id ="bdNavbar " aria-labelledby ="bdNavbarOffcanvasLabel " data-bs-scroll ="true ">
21
21
< div class ="offcanvas-header px-4 pb-0 ">
22
22
< h5 class ="offcanvas-title text-white " id ="bdNavbarOffcanvasLabel "> Bootstrap</ h5 >
23
23
< button type ="button " class ="btn-close btn-close-white " data-bs-dismiss ="offcanvas " aria-label ="Close " data-bs-target ="#bdNavbar "> </ button >
You can’t perform that action at this time.
0 commit comments