Articles in this section
Category / Section

How to bind click event to HTML button node in React Diagram?

2 mins read

First, create an HTML node with a button. In the React Diagram, a button for each HTML node must be provided either as string content or an ng-template to trigger the click event. Below is a code snippet demonstrating how to render the button using an ng-template:

<DiagramComponent
   id="diagram"
   ref={(diagram) => (diagramInstance = diagram)}
   width={'100%'}
   height={'645px'}
   nodes={nodes}
   getNodeDefaults={(node) => {
     node.width = 100;
     node.height = 100;
     return node;
   }}
   nodeTemplate={diagramTemplate.bind(this)}
   >
</DiagramComponent>

To trigger the click event on the button, add the click event inside the button div element. In the below sample, we have bound the click event and changed the shape to basic, and filled the node color.

 function diagramTemplate(props) {
   return (
     <div style={{ width: '100px', height: '100px', background: 'blue' }}>
       <button id="buttonClick" onClick={buttonClick}>
         Click
       </button>
     </div>
   );
 }
 
function buttonClick() {
   diagramInstance.nodes[0].shape = { type: 'Basic' };
   diagramInstance.nodes[0].style = { fill: 'red' };
   diagramInstance.dataBind();
 }

Sample

Conclusion

We hope you enjoyed learning about how to bind a click event to an HTML button node in React Diagram.

You can refer to our React Diagram feature tour page to learn about its other groundbreaking feature representations and documentations. You can also explore our React Diagram example to understand how to present and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our React Diagram and other components.

If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied