How can I trigger the Bootstrap V5 Offcanvas using Bootstrap switches? I want the Offcanvas to open when the switch is checked and close when the Offcanvas is closed.
Sample Code :
<!-- Using checkbox switches to open the offcanvas -->
<div class="form-check form-switch">
<input type="checkbox" id="offcanvas-toggler" class="form-check-input" />
</div>
<button class="btn btn-primary" type="button" data-bs-toggle="offcanvas" data-bs-target="#offcanvasExample" aria-controls="offcanvasExample">
Button with data-bs-target
</button>
<div class="offcanvas offcanvas-start" tabindex="-1" id="offcanvasExample" aria-labelledby="offcanvasExampleLabel">
<div class="offcanvas-header">
<h5 class="offcanvas-title" id="offcanvasExampleLabel">Offcanvas</h5>
<button type="button" class="btn-close text-reset" data-bs-dismiss="offcanvas" aria-label="Close"></button>
</div>
<div class="offcanvas-body">
<div>
Some text as placeholder. In real life you can have the elements you have chosen. Like, text, images, lists, etc.
</div>
</div>
</div>
References :
https://getbootstrap.com/docs/5.0/forms/checks-radios/ https://getbootstrap.com/docs/5.0/components/offcanvas/