Item configuration in Vue Toolbar component
11 Jun 20249 minutes to read
The Vue Toolbar can be rendered by defining an array of items. Items can be constructed with the following built-in command types or item template.
Button
Button
is the default command type
, and it can be rendered by using the text
property. Properties of the button command type:
Property | Description |
---|---|
text | The text to be displayed for button. |
id | The ID of the button to be rendered. If the ID is not given, auto ID is generated. |
prefixIcon | Defines the class used to specify an icon for the button. The icon is positioned before the text if text is available or the icon alone button is rendered. |
suffixIcon | Defines the class used to specify an icon for the button. The icon is positioned after the text if text is available. If both prefixIcon and suffixIcon are specified, only prefixIcon is considered. |
width | Used to set the width of the button. |
Separator
The Separator
type adds a vertical separation between the Toolbar’s single/multiple commands.
<template>
<div id="app">
<div id='container' style="margin:50px auto 0; width:100%;">
<br>
<ejs-toolbar>
<e-items>
<e-item text='Cut'></e-item>
<e-item text='Copy'></e-item>
<e-item text='Paste'></e-item>
<e-item type='Separator'></e-item>
<e-item text='Bold'></e-item>
<e-item text='Italic'></e-item>
<e-item text='Underline'></e-item>
</e-items>
</ejs-toolbar>
</div>
</div>
</template>
<script setup>
import { ToolbarComponent as EjsToolbar, ItemsDirective as EItems, ItemDirective as EItem } from "@syncfusion/ej2-vue-navigations";
</script>
<style>
@import "../node_modules/@syncfusion/ej2-base/styles/material.css";
@import "../node_modules/@syncfusion/ej2-vue-buttons/styles/material.css";
@import "../node_modules/@syncfusion/ej2-vue-popups/styles/material.css";
@import "../node_modules/@syncfusion/ej2-vue-navigations/styles/material.css";
</style>
<template>
<div id="app">
<div id='container' style="margin:50px auto 0; width:100%;">
<br>
<ejs-toolbar>
<e-items>
<e-item text='Cut'></e-item>
<e-item text='Copy'></e-item>
<e-item text='Paste'></e-item>
<e-item type='Separator'></e-item>
<e-item text='Bold'></e-item>
<e-item text='Italic'></e-item>
<e-item text='Underline'></e-item>
</e-items>
</ejs-toolbar>
</div>
</div>
</template>
<script>
import { ToolbarComponent, ItemDirective, ItemsDirective } from "@syncfusion/ej2-vue-navigations";
export default {
name: "App",
components: {
"ejs-toolbar": ToolbarComponent,
"e-items": ItemsDirective,
"e-item": ItemDirective
}
}
</script>
<style>
@import "../node_modules/@syncfusion/ej2-base/styles/material.css";
@import "../node_modules/@syncfusion/ej2-vue-buttons/styles/material.css";
@import "../node_modules/@syncfusion/ej2-vue-popups/styles/material.css";
@import "../node_modules/@syncfusion/ej2-vue-navigations/styles/material.css";
</style>
If
Separator
is added as the first or the last item, it will not be visible.
Enabling tab key navigation in Toolbar
The tabIndex
property of a Toolbar item is used to enable tab key navigation for the item. By default, the user can switch between items using the arrow keys, but the tabIndex
property allows you to switch between items using the Tab and Shift+Tab keys as well.
To use the tabIndex
property, you need to set it for each Toolbar item that you want to enable tab key navigation. The tabIndex
property should be set to a positive integer value. A value of 0 or a negative value will disable tab key navigation for the item.
For example, to enable tab key navigation for two Toolbar items, you can use the following code:
<template>
<div id="app">
<ejs-toolbar>
<e-items>
<e-item text='Item 1' tabIndex="1"></e-item>
<e-item text='Item 2' tabIndex="2"></e-item>
<e-item text='Item 3' tabIndex="3"></e-item>
</e-items>
</ejs-toolbar>
</div>
</template>
<script setup>
import { ToolbarComponent } from '@syncfusion/ej2-vue-navigations';
export default {
name: 'app',
}
</script>
With the above code, the user can switch between the two Toolbar items using the Tab and Shift+Tab keys, in addition to using the arrow keys. The items will be navigated in the order specified by the tabIndex
values.
If you set the tabIndex
value to 0 for all Toolbar items, tab key navigation will be based on the element order rather than the tabIndex
values. For example:
<template>
<div id="app">
<ejs-toolbar>
<e-items>
<e-item text='Item 1' tabIndex="0"></e-item>
<e-item text='Item 2' tabIndex="0"></e-item>
<e-item text='Item 3' tabIndex="0"></e-item>
</e-items>
</ejs-toolbar>
</div>
</template>
<script setup>
import { ToolbarComponent } from '@syncfusion/ej2-vue-navigations';
export default {
name: 'app',
}
</script>
In this case, the user can switch between the two Toolbar items using the Tab and Shift+Tab keys, and the items will be navigated in the order in which they appear in the DOM.
Example:
Here is an example of how you can use the tabIndex
property to enable tab key navigation for a Toolbar component:
<template>
<div id="app">
<ejs-toolbar>
<e-items>
<e-item text='Cut' tabIndex="0"></e-item>
<e-item text='Copy' tabIndex="0"></e-item>
<e-item text='Paste' tabIndex="0"></e-item>
<e-item type='Separator'></e-item>
<e-item text='Bold'></e-item>
<e-item text='Italic'></e-item>
<e-item text='Underline'></e-item>
</e-items>
</ejs-toolbar>
</div>
</template>
<script setup>
import { ToolbarComponent as EjsToolbar, ItemsDirective as EItems, ItemDirective as EItem } from "@syncfusion/ej2-vue-navigations";
</script>
<style>
@import "../node_modules/@syncfusion/ej2-base/styles/material.css";
@import "../node_modules/@syncfusion/ej2-vue-buttons/styles/material.css";
@import "../node_modules/@syncfusion/ej2-vue-popups/styles/material.css";
@import "../node_modules/@syncfusion/ej2-vue-navigations/styles/material.css";
</style>
<template>
<div id="app">
<ejs-toolbar>
<e-items>
<e-item text='Cut' tabIndex="0"></e-item>
<e-item text='Copy' tabIndex="0"></e-item>
<e-item text='Paste' tabIndex="0"></e-item>
<e-item type='Separator'></e-item>
<e-item text='Bold'></e-item>
<e-item text='Italic'></e-item>
<e-item text='Underline'></e-item>
</e-items>
</ejs-toolbar>
</div>
</template>
<script>
import { ToolbarComponent, ItemDirective, ItemsDirective } from '@syncfusion/ej2-vue-navigations';
export default {
name: "App",
components: {
"ejs-toolbar": ToolbarComponent,
"e-items": ItemsDirective,
"e-item": ItemDirective
}
}
</script>
<style>
@import "../node_modules/@syncfusion/ej2-base/styles/material.css";
@import "../node_modules/@syncfusion/ej2-vue-buttons/styles/material.css";
@import "../node_modules/@syncfusion/ej2-vue-popups/styles/material.css";
@import "../node_modules/@syncfusion/ej2-vue-navigations/styles/material.css";
</style>
With the above code, the user can switch between the Toolbar items using the Tab and Shift+Tab keys, and the items will be navigated based on the element order.