How to Prevent Node When Clicking a Button in HTML in React Diagram?
In Syncfusion® React Diagram, nodes can contain HTML templates with interactive elements, such as buttons. When clicking these buttons, you may want to prevent the node from being selected. This can be done by handling the selectionChange
event, which is triggered whenever a selection attempt is made.
This guide demonstrates how to prevent node selection when clicking a button within the node’s HTML template by checking if the active element is the button and canceling the selection process by setting args.cancel to true.
// Function to handle the selectionChange event
selectionChange={(args) => {
// Check if the currently focused element is the button inside the node
if (document.activeElement && document.activeElement.id === 'buttonInsideNode') {
// Cancel the node selection
args.cancel = true;
}
}}
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 prevent node selection while mouse clicking on HTML template button in React Diagram. You can refer to our React 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 React 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!