@@ -236,6 +236,98 @@ return (
236236)
237237```
238238
239+ export const BackdropExample = () => {
240+ const [visibleScrolling, setVisibleScrolling] = useState (false )
241+ const [visibleWithBackdrop, setVisibleWithBackdrop] = useState (false )
242+ const [visibleWithBothOptions, setVisibleWithBothOptions] = useState (false )
243+ return (
244+ <>
245+ <CButton color = " primary" onClick = { () => setVisibleScrolling (true )} >Enable body scrolling</CButton >
246+ <CButton color = " primary" onClick = { () => setVisibleWithBackdrop (true )} >Enable backdrop (default)</CButton >
247+ <CButton color = " primary" onClick = { () => setVisibleWithBothOptions (true )} >Enable both scrolling & backdrop</CButton >
248+ <COffcanvas backdrop = { false } placement = " start" scroll visible = { visibleScrolling } onDismiss = { () => setVisibleScrolling (false )} >
249+ <COffcanvasHeader >
250+ <COffcanvasTitle >Offcanvas</COffcanvasTitle >
251+ <CCloseButton className = " text-reset" onClick = { () => setVisibleScrolling (false )} />
252+ </COffcanvasHeader >
253+ <COffcanvasBody >
254+ <p >Try scrolling the rest of the page to see this option in action.</p >
255+ </COffcanvasBody >
256+ </COffcanvas >
257+ <COffcanvas placement = " start" visible = { visibleWithBackdrop } onDismiss = { () => setVisibleWithBackdrop (false )} >
258+ <COffcanvasHeader >
259+ <COffcanvasTitle >Offcanvas</COffcanvasTitle >
260+ <CCloseButton className = " text-reset" onClick = { () => setVisibleWithBackdrop (false )} />
261+ </COffcanvasHeader >
262+ <COffcanvasBody >
263+ <p >.....</p >
264+ </COffcanvasBody >
265+ </COffcanvas >
266+ <COffcanvas placement = " start" scroll visible = { visibleWithBothOptions } onDismiss = { () => setVisibleWithBothOptions (false )} >
267+ <COffcanvasHeader >
268+ <COffcanvasTitle >Offcanvas</COffcanvasTitle >
269+ <CCloseButton className = " text-reset" onClick = { () => setVisibleWithBothOptions (false )} />
270+ </COffcanvasHeader >
271+ <COffcanvasBody >
272+ <p >Try scrolling the rest of the page to see this option in action.</p >
273+ </COffcanvasBody >
274+ </COffcanvas >
275+ </>
276+ )
277+ }
278+
279+ ## Backdrop
280+
281+ Scrolling the ` <body> ` element is disabled when an offcanvas and its backdrop are visible. Use the ` scroll ` property to toggle ` <body> ` scrolling and ` backdrop ` to toggle the backdrop.
282+
283+ <Example >
284+ <BackdropExample />
285+ </Example >
286+
287+ ``` jsx
288+ const [visibleScrolling , setVisibleScrolling ] = useState (false )
289+ const [visibleWithBackdrop , setVisibleWithBackdrop ] = useState (false )
290+ const [visibleWithBothOptions , setVisibleWithBothOptions ] = useState (false )
291+ return (
292+ <>
293+ < CButton color= " primary" onClick= {() => setVisibleScrolling (true )}> Enable body scrolling< / CButton>
294+ < CButton color= " primary" onClick= {() => setVisibleWithBackdrop (true )}> Enable backdrop (default)< / CButton>
295+ < CButton color= " primary" onClick= {() => setVisibleWithBothOptions (true )}> Enable both scrolling & amp; backdrop< / CButton>
296+ < COffcanvas backdrop= {false } placement= " start" scroll visible= {visibleScrolling} onDismiss= {() => setVisibleScrolling (false )}>
297+ < COffcanvasHeader>
298+ < COffcanvasTitle> Offcanvas< / COffcanvasTitle>
299+ < CCloseButton className= " text-reset" onClick= {() => setVisibleScrolling (false )}/ >
300+ < / COffcanvasHeader>
301+ < COffcanvasBody>
302+ < p> Try scrolling the rest of the page to see this option in action.< / p>
303+ < / COffcanvasBody>
304+ < / COffcanvas>
305+ < COffcanvas placement= " start" visible= {visibleWithBackdrop} onDismiss= {() => setVisibleWithBackdrop (false )}>
306+ < COffcanvasHeader>
307+ < COffcanvasTitle> Offcanvas< / COffcanvasTitle>
308+ < CCloseButton className= " text-reset" onClick= {() => setVisibleWithBackdrop (false )}/ >
309+ < / COffcanvasHeader>
310+ < COffcanvasBody>
311+ < p> ... ..< / p>
312+ < / COffcanvasBody>
313+ < / COffcanvas>
314+ < COffcanvas placement= " start" scroll visible= {visibleWithBothOptions} onDismiss= {() => setVisibleWithBothOptions (false )}>
315+ < COffcanvasHeader>
316+ < COffcanvasTitle> Offcanvas< / COffcanvasTitle>
317+ < CCloseButton className= " text-reset" onClick= {() => setVisibleWithBothOptions (false )}/ >
318+ < / COffcanvasHeader>
319+ < COffcanvasBody>
320+ < p> Try scrolling the rest of the page to see this option in action.< / p>
321+ < / COffcanvasBody>
322+ < / COffcanvas>
323+ < / >
324+ )
325+ ```
326+
327+ ## Accessibility
328+
329+ Since the offcanvas panel is conceptually a modal dialog, be sure to add ` aria-labelledby="..." ` —referencing the offcanvas title—to ` <COffcanvas> ` . Note that you don’t need to add ` role="dialog" ` since we already add it automatically.
330+
239331## API
240332
241333### COffcanvas
0 commit comments