Search results

Add link to Toolbar Item in React Toolbar component

03 Dec 2021 / 1 minute to read

You can add link inside Toolbar using React template. Follow the below guidelines for add link as template in Toolbar.

  • Declare a template within the function which returns jsx element. If the template does not need any arguments, then no need to pass the properties.
  • Assign the function as value for the template option of toolbar item.
Source
Preview
index.jsx
index.tsx
index.html
Copied to clipboard
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { ToolbarComponent, ItemsDirective, ItemDirective } from '@syncfusion/ej2-react-navigations';
export default class App extends React.Component {
    render() {
        function AnchorTemplate() {
            return (<div>
      <a target="_blank" href="https://ej2.syncfusion.com/react/documentation/toolbar/getting-started/">
      Anchor Toolbar Link
      </a>
    </div>);
        }
        return (<div id='container'>
        <ToolbarComponent id="ej2Toolbar">
          <ItemsDirective>
            <ItemDirective text="Cut"/>
            <ItemDirective text="Copy"/>
            <ItemDirective type="Separator"/>
            <ItemDirective text="Paste"/>
            <ItemDirective type="Separator"/>
            <ItemDirective template={AnchorTemplate}/>
          </ItemsDirective>
        </ToolbarComponent>
    </div>);
    }
}
ReactDOM.render(<App />, document.getElementById('element'));
Copied to clipboard
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { ToolbarComponent, ItemsDirective, ItemDirective } from '@syncfusion/ej2-react-navigations';


export default class App extends React.Component<{}, {}> {

  render() {

  function AnchorTemplate(): JSX.Element {
  return (
    <div>
      <a
        target="_blank"
        href="https://ej2.syncfusion.com/react/documentation/toolbar/getting-started/"
      >
      Anchor Toolbar Link
      </a>
    </div>
  );
  }
return (
    <div id='container'>
        <ToolbarComponent id="ej2Toolbar">
          <ItemsDirective>
            <ItemDirective text="Cut" />
            <ItemDirective text="Copy"/>
            <ItemDirective type="Separator"/>
            <ItemDirective text="Paste"/>
            <ItemDirective type="Separator"/>
            <ItemDirective template = { AnchorTemplate } />
          </ItemsDirective>
        </ToolbarComponent>
    </div>
);
  }
}

ReactDOM.render(<App />, document.getElementById('element'));
Copied to clipboard
<!DOCTYPE html>
<html lang="en">

<head>
    <title>Syncfusion React Toolbar Sample</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Essential JS 2 for React Components" />
    <meta name="author" content="Syncfusion" />
    <link href="//cdn.syncfusion.com/ej2/material.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
    <style>
        #container {
            max-width: 700px;
            min-width: 520px;
        }

        #loader {
            color: #008cff;
            height: 40px;
            left: 45%;
            position: absolute;
            top: 45%;
            width: 30%;
        }
    </style>
</head>

<body>
    <div id='container'>
        <div id='element'>
            <div id='loader'>Loading</div>
        </div>
    </div>
</body>

</html>