How to Trigger Event When Diagram is Read-Only Mode in React Diagram?
In Syncfusion® React Diagram, you can make the diagram read-only while still triggering events like click by disabling the select constraints on nodes and connectors, along with the zoom constraint on the diagram. This effectively prevents interactions such as selection and zooming. The getNodeDefaults method uses NodeConstraints to disable the selection functionality on nodes, while the getConnectorDefaults method uses ConnectorConstraints to disable the selection functionality on connectors. Additionally, the DiagramConstraints disable the zoom functionality in diagram.
The following code snippet demonstrates how to configure these settings and trigger the click event.
<DiagramComponent
id="diagram"
ref={(diagram) => (diagramInstance = diagram)}
width={'100%'}
height={'645px'}
nodes={sdlc}
connectors={connections}
//Define the click event
click={() => {
alert('Click Event is triggered');
}}
//Disable the Select constraint for nodes
getNodeDefaults={(obj) => {
//Sets the default values of a node
obj.width = 100;
obj.height = 100;
obj.constraints =
NodeConstraints.Default & ~NodeConstraints.Select;
return obj;
}}
//Disable the Select constraint for connectors
getConnectorDefaults={(obj) => {
obj.constraints =
ConnectorConstraints.Default & ~ConnectorConstraints.Select;
return { style: { strokeColor: '#024249', strokeWidth: 2 } };
}}
//Disable the Zoom constraint for diagram
constraints={DiagramConstraints.Default & ~DiagramConstraints.Zoom}
>
</DiagramComponent>
Sample : Click here for sample
Conclusion
I hope you enjoyed about how to trigger click event when diagram is in read-only mode 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!