Menu - Documentation | www.HtmlElements.com

Overview

Smart.Menu represents a custom element which can be used to choose an option from a nested list of items.

Getting Started with Menu Web Component

Smart UI for Web Components is distributed as smart-webcomponents NPM package. You can also get the full download from our website with all demos from the Download page.

Setup the Menu

Smart UI for Web Components is distributed as smart-webcomponents NPM package

  1. Download and install the package.

    npm install smart-webcomponents

  2. Once installed, import the Menu module in your application.

    <script type="module" src="node_modules/smart-webcomponents/source/modules/smart.menu.js"></script>

  3. Adding CSS reference

    The smart.default.css CSS file should be referenced using following code.

    <link rel="stylesheet" type="text/css" href="node_modules/smart-webcomponents/source/styles/smart.default.css" />

  4. Add the Menu tag to your Web Page

    <smart-menu id="menu">    
    				<smart-menu-item>ISO 8859-5</smart-menu-item>
                    <smart-menu-item>KOI8-R</smart-menu-item>
                    <smart-menu-item>KOI8-U</smart-menu-item>
                    <smart-menu-item>Windows-1251</smart-menu-item>
    	  </smart-menu>

  5. Create the Menu Component

    	<script type="module">
    		Smart('#menu', class {
    			get properties() {
    				return { checkboxes: true }
    			}
    		});
    	</script>	   
    		

    Another option is to create the Menu is by using the traditional Javascript way:
    	const menu = document.createElement('smart-menu');
    
    	menu.disabled = true;
    	document.body.appendChild(menu);
    		

    Smart framework provides a way to dynamically create a web component on demand from a DIV tag which is used as a host. The following imports the web component's module and creates it on demand, when the document is ready. The #menu is the ID of a DIV tag.

    	import "../../source/modules/smart.menu.js";
    
    	document.readyState === 'complete' ? init() : window.onload = init;
    
    	function init() { 
    		const menu = new Smart.Menu('#menu', { checkboxes: true });
    	}
    	

  6. Open the page in your web server.

Appearance

The menu structure contains smart-menu-item and smart-menu-items-group elements.

The following attributes are available for these custom elements.

  • label - the label to be displayed in the Menu
  • separator - if present, a visual separator (horizontal line) is added after the item
  • disabled - disables the selection of an item

The following attributes are only available for smart-menu-item.

  • value - a custom value that is not displayed, but is passed as an argument to the itemClick event (called when an item is chosen).
  • shortcut - a helper text/icon that can represent a keyboard shortcut that activates the item. The shortcut is not displayed for top-level items in horizontal and vertical modes.

Animated menu could be achieved when animation class is added .

 <smart-menu class="animation"></smart-menu>

Demo

The Menu and its items can have checkbox or radio button selection. To allow this the user has to set element's checkboxes property to true and checkable for the particular items or group.

 <smart-menu checkboxes checkable></smart-menu>

Demo

Data Binding

To initialize a populated Smart.Menu custom element, insert the required inner structure consisting of the auxiliary custom elements smart-menu-item and smart-menu-items-group, e.g.:

<!DOCTYPE html>
<html lang="en">
<head>
 <link rel="stylesheet" href="../../source/styles/smart.default.css" type="text/css" />
 <script type="text/javascript" src="../../source/smart.element.js"></script>
 <script type="text/javascript" src="../../source/smart.button.js"></script>
 <script type="text/javascript" src="../../source/smart.menu.js"></script>
</head>
<body>
 <smart-menu>
    <smart-menu-items-group>
        File
        <smart-menu-item shortcut="Ctrl+N">New</smart-menu-item>
        <smart-menu-item shortcut="Ctrl+0">Open</smart-menu-item>
        <smart-menu-items-group>
            Open Containing Folder
            <smart-menu-item>Explorer</smart-menu-item>
            <smart-menu-item>cmd</smart-menu-item>
        </smart-menu-items-group>
        <smart-menu-item shortcut="Ctrl+S" disabled>Save</smart-menu-item>
        <smart-menu-item shortcut="Ctrl+Alt+S" separator>Save As...</smart-menu-item>
        <smart-menu-item shortcut="Alt+F4">Exit</smart-menu-item>
    </smart-menu-items-group>
    <smart-menu-items-group>
        Help
        <smart-menu-item>About</smart-menu-item>
        <smart-menu-item>Help center</smart-menu-item>
        <smart-menu-item>Feedback</smart-menu-item>
    </smart-menu-items-group>
 </smart-menu>
</body>
</html>

Demo

Populating from UL :

<!DOCTYPE html>
<html lang="en">
<head>
 <link rel="stylesheet" href="../../source/styles/smart.default.css" type="text/css" />
 <script type="text/javascript" src="../../source/smart.element.js"></script>
 <script type="text/javascript" src="../../source/smart.button.js"></script>
 <script type="text/javascript" src="../../source/smart.menu.js"></script>
</head>
<body>
 <smart-menu id="menu">
    <ul>
        <li><a href="#Home">Home</a></li>
        <li>
                Solutions
                    <li><a href="#Education">Education</a></li>
                    <li><a href="#Financial">Financial services</a></li>
                    <li>
                        Software Solutions
                        <ul>
                            <li><a href="#ConsumerPhoto">Consumer photo and video</a></li>
                            <li><a href="#Mobile">Mobile</a></li>
                            <li><a href="#RIA">Rich Internet applications</a></li>
                        </ul>
                    </li>
                <li><a href="#">All industries and solutions</a></li>
                </ul>
        </li>
        <li>
                Products
                <ul>
                    <li><a href="#PCProducts">PC products</a></li>
                    <li><a href="#MobileProducts">Mobile products</a></li>
                    <li><a href="#AllProducts">All products</a></li>
                </ul>
        </li>
        <li>
                Support
                <ul>
                    <li><a href="#SupportHome">Support home</a></li>
                    <li><a href="#CustomerService">Customer Service</a></li>
                    <li><a href="#KB">Knowledge base</a></li>
                    <li><a href="#Books">Books</a></li>
                </ul>
        </li>
    </ul>
 </smart-menu>
</body>
</html>

Demo

Populating from dataSource.

<!DOCTYPE html>
<html lang="en">
<head>
 <link rel="stylesheet" href="../../source/styles/smart.default.css" type="text/css" />
 <script type="text/javascript" src="../../source/smart.element.js"></script>
 <script type="text/javascript" src="../../source/smart.button.js"></script>
 <script type="text/javascript" src="../../source/smart.menu.js"></script>
 <script>
 window.onload = function () {
     document.querySelector('smart-menu').dataSource = [
                {
                    label: 'File',
                    items: [
                        {
                            label: 'New',
                            shortcut: 'Ctrl+N'
                        },
                        {
                            label: 'Open',
                            shortcut: 'Ctrl+0'
                        },
                        {
                            label: 'Open Containing Folder',
                            items: [
                                {
                                    label: 'Explorer'
                                },
                                {
                                    label: 'cmd'
                                }
                            ]
                        },
                        {
                            label: 'Save',
                            shortcut: 'Ctrl+S',
                            disabled: true,
                            separator: true
                        },
                        {
                            label: 'Exit',
                            shortcut: 'Alt+F4'
                        }
                    ]
                }
            ];
     }
 </script>
</head>
<body>
    <smart-menu></smart-menu>
</body>
</html>

Demo

Behavior

Smart.Menu has the following choices for display mode:

  • horizontal - firs level items are displayed in a row
  • vertical - firs level items are displayed in a column
  • popup - the menu acts as a popup menu. This mode supports open and close methods
  • tree - the menu goes in tree mode. The item groups are toggled and their items or sub groups are displayed in the same container.

selectionMode property determines the item selection. Allowed values are click and mouseenter

<!DOCTYPE html>
<html lang="en">
<head>
 <link rel="stylesheet" href="../../source/styles/smart.default.css" type="text/css" />
 <script type="text/javascript" src="../../source/smart.element.js"></script>
 <script type="text/javascript" src="../../source/smart.button.js"></script>
 <script type="text/javascript" src="../../source/smart.menu.js"></script>
</head>
<body>
 <smart-menu selection-mode="mouseenter">
    <smart-menu-items-group>
        File
        <smart-menu-item shortcut="Ctrl+N">New</smart-menu-item>
        <smart-menu-item shortcut="Ctrl+0">Open</smart-menu-item>
        <smart-menu-items-group>
            Open Containing Folder
            <smart-menu-item>Explorer</smart-menu-item>
            <smart-menu-item>cmd</smart-menu-item>
        </smart-menu-items-group>
        <smart-menu-item shortcut="Ctrl+S" disabled>Save</smart-menu-item>
        <smart-menu-item shortcut="Ctrl+Alt+S" separator>Save As...</smart-menu-item>
        <smart-menu-item shortcut="Alt+F4">Exit</smart-menu-item>
    </smart-menu-items-group>
    <smart-menu-items-group>
        Help
        <smart-menu-item>About</smart-menu-item>
        <smart-menu-item>Help center</smart-menu-item>
        <smart-menu-item>Feedback</smart-menu-item>
    </smart-menu-items-group>
 </smart-menu>
</body>
</html>

Demo

The position of the menu popups is determines by dropDownPosition property. The allowed values are:

  • top-left
  • top-right
  • bottom-left
  • bottom-right
  • overlay-left
  • overlay-right
  • auto

Manipulating the content

The element offers the following methods:

  • maximize - sets the menu to maximized mode.
     <script>
         window.onload = function () {
             var menu = document.querySelector('smart-menu');
             menu.maximize();
         }
     </script>
    
  • addItem - adds new item to the menu.
     <script>
         window.onload = function () {
             var menu = document.querySelector('smart-menu');
             menu.addItem(document.createElement('smart-menu-item'), '0');
         }
     </script>
    
  • close - closes the menu when mode is set to 'popup'.
     <script>
         window.onload = function () {
             var menu = document.querySelector('smart-menu');
             menu.close();
         }
     </script>
    
  • collapseItem - collapses a particular item. The id or the path to the item is passed in as the method argument.
     <script>
         window.onload = function () {
             var menu = document.querySelector('smart-menu');
             menu.collapseItem('0.0');
         }
     </script>
    
  • expandItem - expands particular item. The id or the path to the item is passed in as the method argument.
     <script>
         window.onload = function () {
             var menu = document.querySelector('smart-menu');
             menu.expandItem('1.2');
         }
     </script>
    
  • getItem - returns an item accroding to the desired id or numeric path.
     <script>
         window.onload = function () {
             var menu = document.querySelector('smart-menu');
             menu.getItem('0.0');
         }
     </script>
    
  • checkItem - checks an item. The id or the path to the item is passed in as the method argument.
     <script>
         window.onload = function () {
             var menu = document.querySelector('smart-menu');
             menu.checkItem('0.0');
         }
     </script>
    
  • minimize - minimizes the menu.
     <script>
         window.onload = function () {
             var menu = document.querySelector('smart-menu');
             menu.minimize();
         }
     </script>
    
  • open - opens the menu when mode is set to 'popup'.
     <script>
         window.onload = function () {
             var menu = document.querySelector('smart-menu');
             menu.open();
         }
     </script>
    
  • removeItem - removes an item. The id or the path to the item is passed in as the method argument.
     <script>
         window.onload = function () {
             var menu = document.querySelector('smart-menu');
             menu.removeItem('0.0');
         }
     </script>
    
  • setFocusable - sets whether the element can be focused or not.
     <script>
         window.onload = function () {
             var menu = document.querySelector('smart-menu');
             menu.setFocusable(false);
         }
     </script>
    
  • uncheckItem - unchecks an item. The id or the path to the item is passed in as the method argument.
     <script>
         window.onload = function () {
             var menu = document.querySelector('smart-menu');
             menu.uncheckItem('0.0');
         }
     </script>
    

Keyboard Support

Key Action
Tab The Menu receives focus by tabbing into it.
Arrow Up / Arrow Left / Arrow Down / Arrow Right Navigation between the items. Depends on selected mode and dropDownPosition.
Home Selects first enabled item in the last opennded container.
End Selects last enabled item in the last opennded container.
Enter Selects an item/opens a pop-up.
Escape Closes the selected popup and focuses its parent popup.
Space Toggles an item's checked state.

Keyboard Support in Tree/Minimized Mode

Key Action
Tab The Menu receives focus by tabbing into it.
Arrow Up / Arrow Down Navigation between visible items.
Left Arrow On an expanded item, collapses the item. On a collapsed or a "leaf" item moves focus to the item's parent item.
Right Arrow On a collapsed item expands the item. On an expanded item, moves to the first child item, or does nothing on a "leaf" item.
Home Moves to the top enabled item.
End Moves to the last enabled item.
Enter Expands/collapses an item or selects a "leaf" item. If the menu is minimized and the minimized pop-up is closed, opens the pop-up.
Escape If the menu is minimized, closes the minimized pop-up.
Space Toggles an item's checked state.

Create, Append, Remove, Get/Set Property, Invoke Method, Bind to Event


Create a new element:
	const menu = document.createElement('smart-menu');
	

Append it to the DOM:
	document.body.appendChild(menu);
	

Remove it from the DOM:
	menu.parentNode.removeChild(menu);
	

Set a property:
	menu.propertyName = propertyValue;
	

Get a property value:
	const propertyValue = menu.propertyName;
	

Invoke a method:
	menu.methodName(argument1, argument2);
	

Add Event Listener:
	const eventHandler = (event) => {
	   // your code here.
	};

	menu.addEventListener(eventName, eventHandler);
	

Remove Event Listener:
	menu.removeEventListener(eventName, eventHandler, true);
	

Using with Typescript

Smart Web Components package includes TypeScript definitions which enables strongly-typed access to the Smart UI Components and their configuration.

Inside the download package, the typescript directory contains .d.ts file for each web component and a smart.elements.d.ts typescript definitions file for all web components. Copy the typescript definitions file to your project and in your TypeScript file add a reference to smart.elements.d.ts

Read more about using Smart UI with Typescript.

Getting Started with Angular Menu Component

Setup Angular Environment

Angular provides the easiest way to set angular CLI projects using Angular CLI tool.

Install the CLI application globally to your machine.

npm install -g @angular/cli

Create a new Application

ng new smart-angular-menu

Navigate to the created project folder

cd smart-angular-menu

Setup the Menu

Smart UI for Angular is distributed as smart-webcomponents-angular NPM package

  1. Download and install the package.
    npm install smart-webcomponents-angular
  2. Once installed, import the MenuModule in your application root or feature module.

    app.module.ts

    import { NgModule } from '@angular/core';
    import { BrowserModule } from '@angular/platform-browser';
    
    import { MenuModule } from 'smart-webcomponents-angular/menu';
    
    import { AppComponent } from './app.component';
    
    @NgModule({
        declarations: [ AppComponent ],
        imports: [ BrowserModule, MenuModule ],
        bootstrap: [ AppComponent ],
    	entryComponents: [ AppComponent ]
    })
    
    export class AppModule { }
    	

  3. Adding CSS reference

    The following CSS file is available in ../node_modules/smart-webcomponents-angular/ package folder. This can be referenced in [src/styles.css] using following code.

    	@import 'smart-webcomponents-angular/source/styles/smart.default.css';

    Another way to achieve the same is to edit the angular.json file and in the styles add the style.

    	"styles": [
    		"node_modules/smart-webcomponents-angular/source/styles/smart.default.css"
    	]
    	
  4. Example


    app.component.html

     
    <smart-menu #menu id="menu">
        <smart-menu-items-group>
            File
            <smart-menu-item [shortcut]="'Ctrl+N'">New</smart-menu-item>
            <smart-menu-item [shortcut]="'Ctrl+0'">Open</smart-menu-item>
            <smart-menu-items-group>
                Open Containing Folder
                <smart-menu-item>Explorer</smart-menu-item>
                <smart-menu-item>cmd</smart-menu-item>
            </smart-menu-items-group>
            <smart-menu-item [shortcut]="'Ctrl+S'" [disabled]="true">Save</smart-menu-item>
            <smart-menu-item [shortcut]="'Ctrl+Alt+S'" [separator]="true">Save As...</smart-menu-item>
            <smart-menu-item [shortcut]="'Alt+F4'">Exit</smart-menu-item>
        </smart-menu-items-group>
        <smart-menu-items-group>
            Edit
            <smart-menu-item [shortcut]="'Ctrl+Z'">Undo</smart-menu-item>
            <smart-menu-item [shortcut]="'Ctrl+Y'" [separator]="true">Redo</smart-menu-item>
            <smart-menu-item [shortcut]="'Ctrl+X'">Cut</smart-menu-item>
            <smart-menu-item [shortcut]="'Ctrl+C'">Copy</smart-menu-item>
            <smart-menu-item [shortcut]="'Ctrl+V'" [disabled]="true">Paste</smart-menu-item>
        </smart-menu-items-group>
        <smart-menu-items-group [dropDownHeight]="300">
            Encoding
            <smart-menu-item>Encode in ANSI</smart-menu-item>
            <smart-menu-item>Encode in UTF-8</smart-menu-item>
            <smart-menu-item>Encode in UTF-8-BOM</smart-menu-item>
            <smart-menu-item>Encode in UTCS-2 BE BOM</smart-menu-item>
            <smart-menu-item>Encode in UTCS-2 LE BOM</smart-menu-item>
            <smart-menu-items-group [separator]="true">
                Character sets
                <smart-menu-items-group>
                    Cyrillic
                    <smart-menu-item>ISO 8859-5</smart-menu-item>
                    <smart-menu-item>KOI8-R</smart-menu-item>
                    <smart-menu-item>KOI8-U</smart-menu-item>
                    <smart-menu-item>Windows-1251</smart-menu-item>
                </smart-menu-items-group>
                <smart-menu-items-group>
                    Chinese
                    <smart-menu-item>Big5 (Traditional)</smart-menu-item>
                    <smart-menu-item>GB2312 (Simplified)</smart-menu-item>
                </smart-menu-items-group>
                <smart-menu-items-group>
                    Western European
                    <smart-menu-item>ISO 8859-1</smart-menu-item>
                    <smart-menu-item>ISO 8859-15</smart-menu-item>
                    <smart-menu-item>OEM 850</smart-menu-item>
                    <smart-menu-item>Windows-1252</smart-menu-item>
                </smart-menu-items-group>
            </smart-menu-items-group>
            <smart-menu-item>Convert to ANSI</smart-menu-item>
            <smart-menu-item>Convert to UTF-8</smart-menu-item>
            <smart-menu-item>Convert to UTF-8-BOM</smart-menu-item>
            <smart-menu-item>Convert to UTCS-2 BE BOM</smart-menu-item>
            <smart-menu-item>Convert to UTCS-2 LE BOM</smart-menu-item>
        </smart-menu-items-group>
    </smart-menu>
    		

    app.component.ts

     
    import { Component, ViewChild, OnInit, AfterViewInit } from '@angular/core';
    import { MenuComponent } from 'smart-webcomponents-angular/menu';
    
    
    @Component({
        selector: 'app-root',
        templateUrl: './app.component.html',
    	styleUrls: ['./app.component.css']
    })
    
    export class AppComponent implements AfterViewInit, OnInit {	
    	@ViewChild('menu', { read: MenuComponent, static: false }) menu: MenuComponent;
    	
     
    	ngOnInit(): void {
    		// onInit code.
    	}
    
    	ngAfterViewInit(): void {
    		// afterViewInit code.
    		this.init();
        }
    		
    	init(): void {
    		// init code.
    	    
    
    	}	
    }
    		

    app.module.ts

     
    import { NgModule } from '@angular/core';
    import { BrowserModule } from '@angular/platform-browser';
    
    import { MenuModule } from 'smart-webcomponents-angular/menu';
    
    import { AppComponent } from './app.component';
    
    @NgModule({
        declarations: [ AppComponent ],
        imports: [ BrowserModule, MenuModule ],
        bootstrap: [ AppComponent ],
    	entryComponents: [ AppComponent ]
    })
    
    export class AppModule { }
    		


Running the Angular application

After completing the steps required to render a Menu, run the following command to display the output in your web browser

ng serve
and open localhost:4200 in your favorite web browser.

Read more about using Smart UI for Angular: https://www.htmlelements.com/docs/angular-cli/.

Getting Started with React Menu Component

Setup React Environment

The easiest way to start with React is to use create-react-app. To scaffold your project structure, follow the installation instructions.

	npm install -g create-react-app
	create-react-app my-app
	cd my-app
	npm start
	

Preparation

Open src/App.js andsrc/App.css

  1. Remove everything inside the App div tag in src/App.js:
    <div className="App"> </div>
  2. Remove the logo.svg import
  3. Remove the contents of src/App.css
  4. Remove src/logo.svg

Setup the Menu

Smart UI for React is distributed as smart-webcomponents-react NPM package

  1. Download and install the package.
    npm install smart-webcomponents-react
  2. Once installed, import the React Menu Component and CSS files in your application and render it app.js

    import 'smart-webcomponents-react/source/styles/smart.default.css';
    import React from "react";
    import ReactDOM from "react-dom";
    import { Menu, MenuItem, MenuItemsGroup } from 'smart-webcomponents-react/menu';
    
    class App extends React.Component {
    
    	init() {
    
    	}
    
    
    	componentDidMount() {
    
    	}
    
    	render() {
    		return (
    			<div>
    				<Menu id="menu">
    					<MenuItemsGroup>File
    			            <MenuItem shortcut="Ctrl+N">New</MenuItem>
    						<MenuItem shortcut="Ctrl+0">Open</MenuItem>
    						<MenuItemsGroup>Open Containing Folder
    			                <MenuItem>Explorer</MenuItem>
    							<MenuItem>cmd</MenuItem>
    						</MenuItemsGroup>
    						<MenuItem shortcut="Ctrl+S" disabled>Save</MenuItem>
    						<MenuItem shortcut="Ctrl+Alt+S" separator>Save As...</MenuItem>
    						<MenuItem shortcut="Alt+F4">Exit</MenuItem>
    					</MenuItemsGroup>
    					<MenuItemsGroup>Edit
    			            <MenuItem shortcut="Ctrl+Z">Undo</MenuItem>
    						<MenuItem shortcut="Ctrl+Y" separator>Redo</MenuItem>
    						<MenuItem shortcut="Ctrl+X">Cut</MenuItem>
    						<MenuItem shortcut="Ctrl+C">Copy</MenuItem>
    						<MenuItem shortcut="Ctrl+V" disabled>Paste</MenuItem>
    					</MenuItemsGroup>
    					<MenuItemsGroup dropDownHeight={300}>Encoding
    			            <MenuItem>Encode in ANSI</MenuItem>
    						<MenuItem>Encode in UTF-8</MenuItem>
    						<MenuItem>Encode in UTF-8-BOM</MenuItem>
    						<MenuItem>Encode in UTCS-2 BE BOM</MenuItem>
    						<MenuItem>Encode in UTCS-2 LE BOM</MenuItem>
    						<MenuItemsGroup separator>Character sets
    			                <MenuItemsGroup>Cyrillic
    			                    <MenuItem>ISO 8859-5</MenuItem>
    								<MenuItem>KOI8-R</MenuItem>
    								<MenuItem>KOI8-U</MenuItem>
    								<MenuItem>Windows-1251</MenuItem>
    							</MenuItemsGroup>
    							<MenuItemsGroup>Chinese
    			                    <MenuItem>Big5 (Traditional)</MenuItem>
    								<MenuItem>GB2312 (Simplified)</MenuItem>
    							</MenuItemsGroup>
    							<MenuItemsGroup>Western European
    			                    <MenuItem>ISO 8859-1</MenuItem>
    								<MenuItem>ISO 8859-15</MenuItem>
    								<MenuItem>OEM 850</MenuItem>
    								<MenuItem>Windows-1252</MenuItem>
    							</MenuItemsGroup>
    						</MenuItemsGroup>
    						<MenuItem>Convert to ANSI</MenuItem>
    						<MenuItem>Convert to UTF-8</MenuItem>
    						<MenuItem>Convert to UTF-8-BOM</MenuItem>
    						<MenuItem>Convert to UTCS-2 BE BOM</MenuItem>
    						<MenuItem>Convert to UTCS-2 LE BOM</MenuItem>
    					</MenuItemsGroup>
    				</Menu>
    			</div>
    		);
    	}
    }
    
    ReactDOM.render(<App />, document.querySelector("#root"));
    
    export default App;
    	

Running the React application

Start the app with
npm start
and open localhost:3000 in your favorite web browser to see the output.

Read more about using Smart UI for React: https://www.htmlelements.com/docs/react/.

Getting Started with Vue Menu Component


Setup Vue Environment

We will use vue-cli to get started. Let's install vue-cli

npm install -g @vue/cli

Then we can start creating our Vue.js projects with:

vue create my-project

Setup the Menu

Open the "my-project" folder and run:

npm install smart-webcomponents

Setup with Vue 3.x

  • Make Vue ignore custom elements defined outside of Vue (e.g., using the Web Components APIs). Otherwise, it will throw a warning about an Unknown custom element, assuming that you forgot to register a global component or misspelled a component name.

    Open src/main.js in your favorite text editor and change its contents to the following:

    main.js

    import { createApp } from 'vue'
    import App from './App.vue'
    
    const app = createApp(App)
    
    app.config.isCustomElement = tag => tag.startsWith('smart-');
    app.mount('#app')
    		
  • Open src/App.vue in your favorite text editor and change its contents to the following:

    App.vue

    <template>
      <div class="vue-root">
        <smart-menu id="menu">
          <smart-menu-items-group>
            File
            <smart-menu-item shortcut="Ctrl+N">New</smart-menu-item>
            <smart-menu-item shortcut="Ctrl+0">Open</smart-menu-item>
            <smart-menu-items-group>
              Open Containing Folder
              <smart-menu-item>Explorer</smart-menu-item>
              <smart-menu-item>cmd</smart-menu-item>
            </smart-menu-items-group>
            <smart-menu-item shortcut="Ctrl+S" disabled>Save</smart-menu-item>
            <smart-menu-item shortcut="Ctrl+Alt+S" separator>Save As...</smart-menu-item>
            <smart-menu-item shortcut="Alt+F4">Exit</smart-menu-item>
          </smart-menu-items-group>
          <smart-menu-items-group>
            Edit
            <smart-menu-item shortcut="Ctrl+Z">Undo</smart-menu-item>
            <smart-menu-item shortcut="Ctrl+Y" separator>Redo</smart-menu-item>
            <smart-menu-item shortcut="Ctrl+X">Cut</smart-menu-item>
            <smart-menu-item shortcut="Ctrl+C">Copy</smart-menu-item>
            <smart-menu-item shortcut="Ctrl+V" disabled>Paste</smart-menu-item>
          </smart-menu-items-group>
          <smart-menu-items-group drop-down-height="300">
            Encoding
            <smart-menu-item>Encode in ANSI</smart-menu-item>
            <smart-menu-item>Encode in UTF-8</smart-menu-item>
            <smart-menu-item>Encode in UTF-8-BOM</smart-menu-item>
            <smart-menu-item>Encode in UTCS-2 BE BOM</smart-menu-item>
            <smart-menu-item>Encode in UTCS-2 LE BOM</smart-menu-item>
            <smart-menu-items-group separator>
              Character sets
              <smart-menu-items-group>
                Cyrillic
                <smart-menu-item>ISO 8859-5</smart-menu-item>
                <smart-menu-item>KOI8-R</smart-menu-item>
                <smart-menu-item>KOI8-U</smart-menu-item>
                <smart-menu-item>Windows-1251</smart-menu-item>
              </smart-menu-items-group>
              <smart-menu-items-group>
                Chinese
                <smart-menu-item>Big5 (Traditional)</smart-menu-item>
                <smart-menu-item>GB2312 (Simplified)</smart-menu-item>
              </smart-menu-items-group>
              <smart-menu-items-group>
                Western European
                <smart-menu-item>ISO 8859-1</smart-menu-item>
                <smart-menu-item>ISO 8859-15</smart-menu-item>
                <smart-menu-item>OEM 850</smart-menu-item>
                <smart-menu-item>Windows-1252</smart-menu-item>
              </smart-menu-items-group>
            </smart-menu-items-group>
            <smart-menu-item>Convert to ANSI</smart-menu-item>
            <smart-menu-item>Convert to UTF-8</smart-menu-item>
            <smart-menu-item>Convert to UTF-8-BOM</smart-menu-item>
            <smart-menu-item>Convert to UTCS-2 BE BOM</smart-menu-item>
            <smart-menu-item>Convert to UTCS-2 LE BOM</smart-menu-item>
          </smart-menu-items-group>
        </smart-menu>
      </div>
    </template>
    
    <script>
    import { onMounted } from "vue";
    import "smart-webcomponents/source/styles/smart.default.css";
    import "smart-webcomponents/source/modules/smart.menu.js";
    
    export default {
      name: "app",
      setup() {
        onMounted(() => {});
      }
    };
    </script>
    
    <style>
    smart-menu {
      margin-left: 5%;
    }
    </style>
    		
    We can now use the smart-menu with Vue 3. Data binding and event handlers will just work right out of the box.

Setup with Vue 2.x

  • Make Vue ignore custom elements defined outside of Vue (e.g., using the Web Components APIs). Otherwise, it will throw a warning about an Unknown custom element, assuming that you forgot to register a global component or misspelled a component name.

    Open src/main.js in your favorite text editor and change its contents to the following:

    main.js

    import Vue from 'vue'
    import App from './App.vue'
    
    Vue.config.productionTip = false
    Vue.config.ignoredElements = [
    'smart-menu', 
    'smart-menu-item', 
    'smart-menu-items-group'
    ]
    
    new Vue({
      render: h => h(App),
    }).$mount('#app')
  • Open src/App.vue in your favorite text editor and change its contents to the following:

    App.vue

    <template>
      <smart-menu id="menu">
        <smart-menu-items-group>
          File
          <smart-menu-item shortcut="Ctrl+N">New</smart-menu-item>
          <smart-menu-item shortcut="Ctrl+0">Open</smart-menu-item>
          <smart-menu-items-group>
            Open Containing Folder
            <smart-menu-item>Explorer</smart-menu-item>
            <smart-menu-item>cmd</smart-menu-item>
          </smart-menu-items-group>
          <smart-menu-item shortcut="Ctrl+S" disabled>Save</smart-menu-item>
          <smart-menu-item shortcut="Ctrl+Alt+S" separator>Save As...</smart-menu-item>
          <smart-menu-item shortcut="Alt+F4">Exit</smart-menu-item>
        </smart-menu-items-group>
        <smart-menu-items-group>
          Edit
          <smart-menu-item shortcut="Ctrl+Z">Undo</smart-menu-item>
          <smart-menu-item shortcut="Ctrl+Y" separator>Redo</smart-menu-item>
          <smart-menu-item shortcut="Ctrl+X">Cut</smart-menu-item>
          <smart-menu-item shortcut="Ctrl+C">Copy</smart-menu-item>
          <smart-menu-item shortcut="Ctrl+V" disabled>Paste</smart-menu-item>
        </smart-menu-items-group>
        <smart-menu-items-group drop-down-height="300">
          Encoding
          <smart-menu-item>Encode in ANSI</smart-menu-item>
          <smart-menu-item>Encode in UTF-8</smart-menu-item>
          <smart-menu-item>Encode in UTF-8-BOM</smart-menu-item>
          <smart-menu-item>Encode in UTCS-2 BE BOM</smart-menu-item>
          <smart-menu-item>Encode in UTCS-2 LE BOM</smart-menu-item>
          <smart-menu-items-group separator>
            Character sets
            <smart-menu-items-group>
              Cyrillic
              <smart-menu-item>ISO 8859-5</smart-menu-item>
              <smart-menu-item>KOI8-R</smart-menu-item>
              <smart-menu-item>KOI8-U</smart-menu-item>
              <smart-menu-item>Windows-1251</smart-menu-item>
            </smart-menu-items-group>
            <smart-menu-items-group>
              Chinese
              <smart-menu-item>Big5 (Traditional)</smart-menu-item>
              <smart-menu-item>GB2312 (Simplified)</smart-menu-item>
            </smart-menu-items-group>
            <smart-menu-items-group>
              Western European
              <smart-menu-item>ISO 8859-1</smart-menu-item>
              <smart-menu-item>ISO 8859-15</smart-menu-item>
              <smart-menu-item>OEM 850</smart-menu-item>
              <smart-menu-item>Windows-1252</smart-menu-item>
            </smart-menu-items-group>
          </smart-menu-items-group>
          <smart-menu-item>Convert to ANSI</smart-menu-item>
          <smart-menu-item>Convert to UTF-8</smart-menu-item>
          <smart-menu-item>Convert to UTF-8-BOM</smart-menu-item>
          <smart-menu-item>Convert to UTCS-2 BE BOM</smart-menu-item>
          <smart-menu-item>Convert to UTCS-2 LE BOM</smart-menu-item>
        </smart-menu-items-group>
      </smart-menu>
    </template> 
    
    <script>
    import 'smart-webcomponents/source/modules/smart.listmenu.js';
    import "smart-webcomponents/source/styles/smart.default.css";
    
    export default {
      name: "app"
    };
    </script>
    
    <style>
      smart-menu {
        margin-left: 5%;
      }
    </style>
    		
    We can now use the smart-menu with Vue. Data binding and event handlers will just work right out of the box.
    We have bound the properties of the smart-menu to values in our Vue component.

Running the Vue application

Start the app with
npm run serve
and open localhost:8080 in your favorite web browser to see the output below:

Read more about using Smart UI for Vue: https://www.htmlelements.com/docs/vue/.