Responsive mode in EJ2 JavaScript Toolbar control

16 Jun 202313 minutes to read

This section explains the supported display modes of the Toolbar when the content exceeds the viewing area. Possible modes are:

  • Scrollable
  • Popup

Scrollable

The default overflow mode of the Toolbar is Scrollable. Scrollable display mode supports display of commands in a single line with horizontal scrolling enabled when commands overflow to available space.

  • The right and left navigation arrows are added to the start and end of the Toolbar to navigate to hidden commands.
  • You can also see the hidden commands using touch swipe action.
  • By default, if navigation icon in the left side is disabled, you can see the hidden commands by moving to the right.
  • By clicking the arrow or by holding the arrow continuously, hidden commands will become visible.
  • If device navigation icons are not available, you can touch swipe to see the hidden commands of the Toolbar.

Scrollable

  • Once the Toolbar reaches the last or first command, the corresponding navigation icon will be disabled and you can move to the opposite direction.

Touch scroll

Swipe scroll

  • You can continuously scroll the Toolbar content by holding the navigation icon.

Long press scroll

ej.base.enableRipple(true);

//Initialize Toolbar component

var toolbar = new ej.navigations.Toolbar({
width:600,
items: [
        { type: 'Button', prefixIcon: 'e-cut-icon', text:'Cut' },
        { type: 'Button', prefixIcon: 'e-copy-icon', text:'Copy' },
        { type: 'Button', prefixIcon: 'e-paste-icon', text:'Paste' },
        { type: 'Separator'},
        { type: 'Button', prefixIcon: 'e-bold-icon', text:'Bold' },
        { type: 'Button', prefixIcon: 'e-underline-icon', text:'Underline' },
        { type: 'Button', prefixIcon: 'e-italic-icon', text:'Italic' },
        { type: 'Button', prefixIcon: 'e-color-icon', text:'Color-Picker' },
        { type: 'Separator'},
        { type: 'Button', prefixIcon: 'e-ascending-icon', text:'A-Z Sort' },
        { type: 'Button', prefixIcon: 'e-descending-icon', text:'Z-A Sort' },
        { type: 'Button', prefixIcon: 'e-clear-icon', text:'Clear' }
        ]
});

//Render initialized Toolbar component
toolbar.appendTo('#element');
<!DOCTYPE html><html lang="en"><head>
    <title>Essential JS 2 Toolbar</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Typescript Toolbar Controls">
    <meta name="author" content="Syncfusion">
    <link href="index.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/27.2.2/material.css" rel="stylesheet">
    <link href="https://ej2.syncfusion.com/angular/demos/src/toolbar/toolbar.component.css" rel="stylesheet">
    
    
<script src="https://cdn.syncfusion.com/ej2/27.2.2/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>

<body>
    
    <div id="container">
        <div id="element"></div>
        <br><br>
        <div id="result"></div>
    </div>


<script>
var ele = document.getElementById('container');
if(ele) {
  ele.style.visibility = "visible";
}   
      </script>
<script src="index.js" type="text/javascript"></script>
</body></html>

Popup is another type of overflowMode in which the Toolbar container holds the commands that can be placed in the available space. The rest of the overflowing commands that do not fit within the viewing area moves to the overflow popup container.

The commands placed in the popup can be viewed by opening the popup using the drop down icon given at the end of the Toolbar.

Toolbar popup

If the popup content overflows the height of the page, then the rest of the commands will be hidden.

Priority of commands

Default popup priority is set as none, and when the commands of the Toolbar overflow, the ones listed last will be moved to the popup.

You can customize the priority of commands to be displayed on the Toolbar and popup by using the overflow property.

Property Description
show Always shows items on the Toolbar with primary priority.
hide Always shows items in the popup with secondary priority.
none No priority display, and as per the normal order commands are moved to popup when content exceeds viewing area.

If primary priority commands also exceed available space, they are moved to the popup container at top order position and placed before the secondary priority commands.

You can maintain toolbar item on popup always by using the showAlwaysInPopup property, and this behavior is not applicable for toolbar items with overflow property as ‘show’.

ej.base.enableRipple(true);

//Initialize Toolbar component

var toolbar = new ej.navigations.Toolbar({
width: 380,
overflowMode: 'Popup',
items: [
  { type: 'Button', prefixIcon: 'e-cut-icon', text:'Cut', overflow: 'Show' },
  { type: 'Button', prefixIcon: 'e-copy-icon', text:'Copy', overflow: 'Show' },
  { type: 'Button', prefixIcon: 'e-paste-icon',text:'Paste', overflow: 'Show' },
  { type: 'Separator' },
  { type: 'Button', prefixIcon: 'e-bold-icon', text:'Bold'},
  { type: 'Button', prefixIcon: 'e-italic-icon', text:'Italic'},
  { type: 'Button', prefixIcon: 'e-underline-icon', text:'Underline' },
  { type: 'Separator'},
  { type: 'Button', prefixIcon: 'e-ascending-icon', text:'A-Z Sort', overflow: 'Show'},
  { type: 'Button', prefixIcon: 'e-descending-icon', text:'Z-A Sort', overflow: 'Show'},
  ]
});

//Render initialized Toolbar component
toolbar.appendTo('#element');
<!DOCTYPE html><html lang="en"><head>
    <title>Essential JS 2 Toolbar</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Typescript Toolbar Controls">
    <meta name="author" content="Syncfusion">
    <link href="index.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/27.2.2/material.css" rel="stylesheet">
    <link href="https://ej2.syncfusion.com/angular/demos/src/toolbar/toolbar.component.css" rel="stylesheet">
    
    
<script src="https://cdn.syncfusion.com/ej2/27.2.2/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>

<body>
    
    <div id="container">
        <div id="element"></div>
        <br><br>
        <div id="result"></div>
    </div>


<script>
var ele = document.getElementById('container');
if(ele) {
  ele.style.visibility = "visible";
}   
      </script>
<script src="index.js" type="text/javascript"></script>
</body></html>

Text mode for buttons

The showTextOn property is used to decide button text display area on the Toolbar, popup, or both. This is useful for customization of both text and image representation of commands.

For example, you can show icon only button on the Toolbar, and in the popup container display more information about the commands with icon and text.

Possible values are,

Property Description
Both Button text is visible in both Toolbar and Popup.
Overflow Button text is only visible in Popup.
Toolbar Button text is only visible on the Toolbar.

In the following code sample, text is only visible in the popup container and not in the Toolbar container.

ej.base.enableRipple(true);

//Initialize Toolbar component

var toolbar = new ej.navigations.Toolbar({
width: 330,
overflowMode: 'Popup',
items: [
  { type: 'Button', prefixIcon: 'e-cut-icon', text:'Cut', showTextOn:'Overflow', overflow: 'Show'},
  { type: 'Button', prefixIcon: 'e-copy-icon', text:'Copy', showTextOn:'Overflow', overflow: 'Show'},
  { type: 'Button', prefixIcon: 'e-paste-icon', text:'Paste', showTextOn:'Overflow', overflow: 'Show'},
  { type: 'Separator'},
  { type: 'Button', prefixIcon: 'e-bold-icon', text:'Bold', showTextOn:'Overflow', overflow: 'Show'},
  { type: 'Button', prefixIcon: 'e-underline-icon', text:'Underline', showTextOn:'Overflow', overflow: 'Show'},
  { type: 'Button', prefixIcon: 'e-italic-icon', text:'Italic', overflow: 'Show', showTextOn:'Overflow',},
  { type: 'Button', prefixIcon: 'e-color-icon', text:'Color-Picker', overflow: 'Hide', showTextOn:'Overflow',},
  { type: 'Separator'},
  { type: 'Button', prefixIcon: 'e-ascending-icon', text:'A-Z Sort', overflow: 'Show', showTextOn:'Overflow',},
  { type: 'Button', prefixIcon: 'e-descending-icon', text:'Z-A Sort', overflow: 'Show', showTextOn:'Overflow',},
  { type: 'Button', prefixIcon: 'e-clear-icon', text:'Clear', overflow: 'Show', showTextOn:'Overflow',}]
});

//Render initialized Toolbar component
toolbar.appendTo('#element');
<!DOCTYPE html><html lang="en"><head>
    <title>Essential JS 2 Toolbar</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Typescript Toolbar Controls">
    <meta name="author" content="Syncfusion">
    <link href="index.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/27.2.2/material.css" rel="stylesheet">
    <link href="https://ej2.syncfusion.com/angular/demos/src/toolbar/toolbar.component.css" rel="stylesheet">
    
    
<script src="https://cdn.syncfusion.com/ej2/27.2.2/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>

<body>
    
    <div id="container">
        <div id="element"></div>
        <br><br>
        <div id="result"></div>
    </div>


<script>
var ele = document.getElementById('container');
if(ele) {
  ele.style.visibility = "visible";
}   
      </script>
<script src="index.js" type="text/javascript"></script>
</body></html>