Facilitate Off Canvas Responsive

This is what I have created, a sidebar that turns into an off canvas navigation on small screens.

I have had to enter the code by hand because Wappler does not recognise class="offcanvas-lg" It is now a working example except for the fact that the close button does not work using data-bs-dismiss="offcanvas"

This is the code:

<!doctype html>
<html>

<head>
  <base href="/">
  <script src="/dmxAppConnect/dmxAppConnect.js"></script>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <title>Off Canvas Responsive</title>

  <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.14.0/css/all.css" integrity="sha384-HzLeBuhoNPvSl5KYnjx0BT+WB0QEEqLprO+NBkkk5gbc67FTaL7XIGa2w1L0Xbgc" crossorigin="anonymous" />
  <link rel="stylesheet" href="/bootstrap/5/css/bootstrap.min.css" />
  <link rel="stylesheet" href="/css/style.css" />

  <script src="/dmxAppConnect/dmxRouting/dmxRouting.js" defer></script>
  <script src="/dmxAppConnect/dmxBootstrap5Offcanvas/dmxBootstrap5Offcanvas.js" defer></script>
  <script src="/dmxAppConnect/dmxBootstrap5Navigation/dmxBootstrap5Navigation.js" defer></script>
</head>

<body is="dmx-app" id="main">
  <header class="bg-body-secondary">
    <div class="container">
      <div class="row align-items-center">
        <div class="col">
          <h1>Off Canvas Responsive</h1>
        </div>
        <div class="col-2 text-end">
          <button id="btn1" class="btn d-lg-none" data-bs-toggle="offcanvas" data-bs-target="#offcanvas"><i class="fas fa-bars fa-lg"></i></button>
        </div>
      </div>
    </div>
  </header>
  <div class="container">
    <div class="row pt-lg-4">
      <div class="col">
        <div class="offcanvas-lg offcanvas-start" id="offcanvas" is="dmx-bs5-offcanvas" tabindex="-1">
          <div class="offcanvas-header">
            <h5 class="offcanvas-title">Offcanvas title</h5>
            <button type="button" class="btn-close text-reset" data-bs-dismiss="offcanvas" aria-label="Close"></button>
          </div>
          <div class="offcanvas-body">
            <nav class="navbar">
              <div class="navbar-nav flex-xl-column">
                <a class="nav-item nav-link active" href="/">Home</a>
                <a class="nav-item nav-link" href="#">About</a>
                <a class="nav-item nav-link" href="#">Contact</a>
              </div>
            </nav>
          </div>
        </div>
      </div>
      <div class="col-12 col-lg-9">
        <main>
          <div is="dmx-view" id="content">
            <%- await include(content, locals); %>
          </div>
        </main>
      </div>
    </div>
  </div>

  <script src="/bootstrap/5/js/bootstrap.bundle.min.js"></script>
</body>

</html>

The code is very simple, no extra CSS needed as was the case in previous Bootstrap versions. Facilitating the responsive version of Off Canvas will make creating a sidebar a lot easier.

Please vote:

I see that’s a new option since BS 5.2.0, so we just need to add it in the UI:
https://getbootstrap.com/docs/5.3/components/offcanvas/#responsive

1 Like

We integrated the responsive options for the Offcanvas component in Wappler 6.1.3

1 Like