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.

Plugin support for onMouseOver, onMouseOut etc.

See original GitHub issue

Do you want to request a feature or report a bug?

Feature

What’s the current behavior?

If a plugin wants to handle onMouseOver or onMouseOut events, it either needs to bind arguments in the render method, or store data in a data-attribute. The specific use case I’m trying to achieve is taking action based on mark data on mouse over.

class Plugin {

  static onMouseOver(event) {
    console.log(event.target.getAttribute('data-foovalue')
  }

  static renderMark() {
    const fooValue = props.mark.data.get("foo");
    return (
      <span data-foovalue={fooValue} onMouseOver={Plugin.onMouseOver}>
        {props.children}
      </span>
    )
  }

}

What’s the expected behavior?

It would be great if onMouseOver and onMouseOut were supported “naturally”, such that we got an event and a change, so we had access to value, document, fragment, or mark data. We wouldn’t need a renderMark function then, and could do something like:

class Plugin {

  static onMouseOver(event, change) {
    // vague-ish pseudo-code. could also handle this by addition
    // of a new `hover` range to the change object, similar to selection.
    const node = findNode(event.target, change.value)
    const marks = node.getMarksAtRange(rangeOfNode), 
    console.log(marks[0].data.get("foo"))
  }
}

I’m happy to put together an initial pass at this, if it’s likely to be accepted in principle, and if I can be pointed in the right direction 😃

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:9 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
mmdonaldsoncommented, Jun 28, 2019

Any updates on this? Do we need someone to dive into it? As this is also a requirement for me too

1reaction
AndreiRaileancommented, Feb 9, 2018

I see, you’re optimising for memory. Perhaps it’s worth writing a proper component and letting react optimise for multiple instances of the same component

const MySpecialMark = ({fooValue, children}) => {
  const onMouseOver() => consoleLog(fooValue)
  return (
      <span onMouseOver={onMouseOver}>
        {children}
      </span>
  )
}

and

  ...
  static renderMark() {
    const fooValue = props.mark.data.get("foo");
    return <MySpecialMark fooValue={fooValue} />
  }

I guess it’s similar to my other suggestion.

Your suggestion seems like a common pattern in Slate.js so it’s quite easy to reason about. Serialisation rules work in the same way: loop over all rules, find one that can generate a node from content. Having convenient access to the value, change is important, but pure components don’t need to know anything about it - just feed them callbacks.

Anyway, sounds like you already know how to implement it. Give it a go!

Read more comments on GitHub >

github_iconTop Results From Across the Web

onmouseover doesn't work when using javascript to add img ...
I need some javascript code that dynamically adds an img tag to a div, and the img tag needs onmouseover and onmouseout handlers....
Read more >
onMouseOut() not being called - DSP and Plug-in Development ...
I have this code, with mouseOver being initialised to FALSE, and draw() only draws lines for the crossfair if the mouseOver is TRUE....
Read more >
IMG mouseover plugin for WordPress - The Woodwork
Download. Please go to IMG Mouseover on WordPress.org. When clicked, the image should be changed to this. To revert, simply mouseout of the...
Read more >
Topic: onmouseout/onmouseover in sidepanel widget
Hi I am trying to figure out how to make a mouseover effect ork in sidebar widget. My problem is that the editor...
Read more >
Moving the mouse over a control with a tooltip reset the scroll ...
There are onmouseover and onmouseout events attached to the div that ... at the mouseover/mouseenter/mouseout etc and modify accordingly.
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