How to Host Buttons, Textboxes, or Complex Shapes as Content of Nodes in a Javascript Diagram?
Syncfusion® JavaScript Diagram allows you to host interactive HTML elements such as buttons, textboxes, or complex shapes within diagram nodes. This feature enhances user interaction within the diagram by embedding HTML elements inside the nodes. It’s especially useful when you want to create dynamic diagrams where users can input data or trigger actions directly in the diagram, such as clicking buttons or entering text.
To embed a button, textbox, or other HTML elements inside a diagram node, set the shape
property of the node to type: 'HTML'
and define the HTML content in the content
property. This enables seamless integration of interactive HTML content within the node.
let nodes = [
{
id: 'Button',
offsetX: 100, offsetY: 100,
width: 120, height: 100,
shape: {
type: 'HTML',
content: '<div style="background:#6BA5D7;height:100%;width:100%;"><button type="button" style="width:100%">Button</button></div>'
},
},
{
id: 'ColorPicker',
offsetX: 300, offsetY: 100,
width: 120, height: 100,
shape: {
type: 'HTML',
content: '<div style="background:#FBF6A4;height:100%;width:100%;"><input type="color" value="#ff0000" style="width:100%"></div>'
}
}
]
You can find a working example of this implementation on StackBlitz in the provided link: Click here for sample
Conclusion
I hope you enjoyed learning how to host the button, textbox or complex shapes as content of the node in Javascript Diagram. You can refer to our JavaScript Diagram feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our JavaScript Diagram example to understand how to create 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 other controls. If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!