question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Click event and react component

See original GitHub issue

I’m trying to make a react component that uses Mermaid just like this but that will allow the click event to be used. I tried the solution found here without success.

Here is what i got:

import React, { Component } from "react";
import $ from 'jquery';
import mermaid from "mermaid";

class Mimi extends Component {
  constructor(props) {
    super(props);

    mermaid.mermaidAPI.initialize({
      startOnLoad: true,
        cloneCssStyles: false,
        flowchart: {
            useMaxWidth: true,
            htmlLabels: true
        }
    });

  }

  componentDidMount() {
     function myAction(id) {
        alert("click firedee");
    }
    $(function () {
        var graphDefinition = 'graph TB\nProposal-->Contract\nContract-->Planning\nPlanning-->Design\nDesign-->Build\nBuild-->Verification\nVerification-->Delivery\nDelivery-->Support\nclick Design myAction\n';
        var callback = function (code,bindEvents){
            console.log(bindEvents);
            $("#div-id1").html(code)
            bindEvents();
        }
        mermaid.mermaidAPI.render('some_id', graphDefinition, callback);
    });
  }

  render() {
    return (<div id={"div-id1"}></div>)
  }
}

export default Mimi;

Which is called from a parent react component just like that:

<Mimi />

The FlowChart displays fine but the “Design” node that is clickable will not trigger the myAction function once clicked.

Help would be appreciated.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
digitalillusioncommented, Oct 24, 2018

This is the working react component I come up with just to test the integration with version ^8.0.0-rc.8:

import React, { Component } from "react";
import mermaid from "mermaid";


class TplDiagram extends Component {
    constructor(props) {
        super(props);

        mermaid.initialize({
            mermaid : {
                startOnLoad: true,
            }
        })
    }

    componentDidMount() {
        window.callback = e => console.log(e)
        mermaid.contentLoaded()
    }

    render() {
        return <div className="mermaid">
            graph LR;
                A-->B;
                    click A callback "Tooltip";
                    click B "http://www.github.com" "This is a link"
        </div>
    }
}

export default TplDiagram;
0reactions
IOrlandonicommented, Dec 8, 2019

@mrkchang Hey! You’re commenting in an old closed issue. Feel free to create a new issue if you found a bug, need help, want to request a feature or anything!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Handling Events - React
With JSX you pass a function as the event handler, rather than a string. For example, the HTML: <button onclick="activateLasers()"> Activate Lasers </button>....
Read more >
React onClick event handlers: A complete guide
The React onClick event handler enables you to call a function and trigger an action when a user clicks an element, such as...
Read more >
React onClick event on component - Stack Overflow
I have a React component called <SensorList /> that has many child <SensorItem /> s (another React component). I want to be able...
Read more >
How to Use React onClick Events in Class and Functional ...
Click events are triggered when an element is clicked, and are defined in React with the event type onClick . This is passed...
Read more >
React onClick Event Handling (With Examples) - Upmostly
In React, the onClick handler allows you to call a function and perform an action when an element is clicked. onClick is the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found