Shay Shmeltzer's Oracle Development Tools Tips

Adding Off Canvas Layout to a Visual Builder Application

Shay Shmeltzer
Director of Product Management - Oracle

Off Canvas layout is a common UI pattern for modern applications, especially on mobile devices. The concept is aimed at saving space on your page, allowing you to pop out a "drawer" of additional information. This helps reduce clatter on the main page but still provide access to important data when needed without leaving the page context. You can see an example of the runtime behavior at the top of this post. 

Oracle JET provides this type of "off-canvas" behavior as a built in component, and they have a demo of it working as part of the cookbook here.

In the video below I show you how to add this to a Visual Builder application. As always - you can mostly just copy and paste code from the JET cookbook, but you need to handle some of the importing of resources a little different, and use the Visual Builder approach for adding your JavaScript function.

The code used in the video is:

Page source:

<div class="oj-offcanvas-outer-wrapper">
  <div class="oj-offcanvas-start oj-panel oj-panel-alt5 oj-offcanvas-overlay-shadow"
    id="startDrawer" style="width: 200px">
    <div class="oj-flex">
      <h2 class="oj-flex-item oj-sm-12 oj-md-12" id="h1-1660298733-2">Menu</h2>

    <div class="oj-flex">
      <oj-label class="oj-flex-item oj-sm-12 oj-md-3" id="oj-label-1660298733-1">List</oj-label>

    <div class="oj-flex">
      <oj-label class="oj-flex-item oj-sm-12 oj-md-3" id="oj-label-1660298733-2">chart</oj-label>

  <div class="demo-main-content" id="mainContent">
    <div class="oj-flex">
      <h2 class="oj-flex-item oj-sm-12 oj-md-10" id="h1-1660298733-1">Gifts</h2>

    <div class="oj-flex">
      <hr class="oj-flex-item oj-sm-12 oj-md-12" id="hr-1660298733-1" />

    <div class="oj-flex">
      <oj-list-view class="oj-flex-item oj-sm-12 oj-md-12" data="[[$page.variables.giftsListSDP]]"
        id="oj-list-view-1660298733-1"> <template slot="itemTemplate"> <oj-vb-list-item> <img :src="[[$current.data.picture]]" height="32" slot="image" width="32" />
<p slot="title1"><oj-bind-text value="[[$current.data.product]]"></oj-bind-text></p>

<p slot="value1"><oj-bind-text value="[[$current.data.cost]]"></oj-bind-text></p>

<p slot="title2"><oj-bind-text value="[[$current.data.sKU]]"></oj-bind-text></p>
</oj-vb-list-item> </template> </oj-list-view>

JavaScript Function in the page:

define(['ojs/ojcore'], function(oj) {
  'use strict';

  var PageModule = function PageModule() {};

  PageModule.prototype.showSide = function() {
    var offcanvas = {
      "selector": "#startDrawer",
      "content": "#mainContent",
      "edge": "start",
      "displayMode": "push",
      "size": "200px"



  return PageModule;

and in your page Json file add this import:

"oj-offCanvas": {
  "path": "ojs/ojoffcanvas"

Join the discussion

Comments ( 6 )
  • Samuel Lima Wednesday, October 30, 2019
    Hi Shay,

    I copied exactly the same code and got an "Unexpected string in JSON at position 412" while loading page "shell/main/main-start".

    Do you know how I can fix it?
  • shay Thursday, October 31, 2019
    Samuel, Seems like there was some junk code added to the json file in the blog. It is fixed now should be:
    "oj-offCanvas": {
    "path": "ojs/ojoffcanvas"
  • Pallavi Thursday, June 4, 2020
    Hello Shay,
    I am using offCanvas in my project & its working as you have explained here.
    But I am looking for automatic resizing of main-content. As a default behavior, my main-content is not complete visible when offCanvas is open.
    Is there any way to handle this ?

    I also referred JET doc (https://www.oracle.com/webfolder/technetwork/jet/jetCookbook.html?component=offcanvas) but couldn't find anything helpful on my query.
  • Shay Shmeltzer Friday, June 5, 2020
    Pallavi, if your aim is to still be able to see the content when you expand the side part - I don't think you are looking for off canvas.
    Rather you probably should use a section in your page that can be shown or hidden and the rest of the page has responsive design for it.
  • Vamsi Monday, November 30, 2020
    Hi Shay,
    The height of the off-canvas div (the one which opens on the click of the icon) seems to be taking the height of the main division. So when the main content is not occupying the full page height, the hidden part when clicked open is also short in size.
    Is there any way to fix the size of the hidden portion to full-page height?
    I added style="height:100vh" to main content but it is inducing an unnecessary scroll bar even if the content is short.
  • Shay Shmeltzer Tuesday, December 1, 2020
    Vamsi - this is a question probably better addressed by the Oracle JET team - try their forum - https://community.oracle.com/tech/developers/categories/16409-oracle-jet
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.