Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot fire events with g6-react-node #3455

Closed
monolithed opened this issue Jan 16, 2022 · 5 comments
Closed

Cannot fire events with g6-react-node #3455

monolithed opened this issue Jan 16, 2022 · 5 comments
Assignees
Labels
Outdate This issue is too old to be resolved

Comments

@monolithed
Copy link

Describe the bug

  1. Cannot subscribe to onMouseEnter and onMouseLeave events
  2. The onMouseOut event triggered after click on the element

Your Example Website or App

https://codesandbox.io/s/frosty-euclid-3zbt9?file=/index.js

Steps to Reproduce the Bug or Issue

Hover over element

Expected behavior

The onMouseOut event should be triggered

Screenshots or Videos

No response

Platform

  • OS: macOS
  • Browser: Safari
  • Version: latest versions

Additional context

No response

@mxz96102
Copy link
Member

mxz96102 commented Feb 7, 2022

because of event triggers' least unit is the item, unless your mouse in or mouse out event are triggered with item(node), the shape in item won't trigger these event

@monolithed
Copy link
Author

@mxz96102, thanks for your reply, could you provide an example how to subscribe on onMouseEnter correctly?

@defghy
Copy link

defghy commented Nov 17, 2023

same problem
because when mouseEnter cannot get shape
image
event.target has value;
because when event trigger,mouse has come out

image

@defghy
Copy link

defghy commented Nov 18, 2023

quick fix;hijack createNodeFromReact

import { createNodeFromReact as originCreateNodeFromReact } from '@antv/g6-react-node'

const cfg2EventMap = {
  onClick: 'click',
  onDBClick: 'dblclick',
  onMouseEnter: 'mouseenter',
  onMouseMove: 'mousemove',
  onMouseOut: 'mouseout',
  onMouseOver: 'mouseover',
  onMouseLeave: 'mouseleave',
  onMouseDown: 'mousedown',
  onMouseUp: 'mouseup',
  onDragStart: 'dragstart',
  onDrag: 'drag',
  onDragEnd: 'dragend',
  onDragEnter: 'dragenter',
  onDragLeave: 'dragleave',
  onDragOver: 'dragover',
  onDrop: 'drop',
  onContextMenu: 'contextmenu',
}

export const createNodeFromReact = function (arg) {
  const shapeOption = originCreateNodeFromReact(arg)
  const originDraw = shapeOption.draw
  shapeOption.draw = function (cfg: any, group: IGroup) {
    const target = originDraw(cfg, group)

    // 遍历
    group.find((shape: any) => {
      const cfgKeys = Object.keys(shape.cfg)
      // 绑定相关事件
      cfgKeys
        .filter(key => cfg2EventMap[key])
        .forEach(eventKey => {
          shape.on(cfg2EventMap[eventKey], shape.cfg[eventKey])
        })

      return false
    })

    return target
  }

  return shapeOption
}

@Aarebecca Aarebecca added the Outdate This issue is too old to be resolved label Dec 8, 2023
Copy link

github-actions bot commented Dec 8, 2023

This issue has been closed because it has been outdate for a long time.
Please open a new issue if you still need help.
这个 issue 已经被关闭,因为 它已经过期很久了
如果你仍然需要帮助,请创建一个新的 issue。

@github-actions github-actions bot closed this as completed Dec 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Outdate This issue is too old to be resolved
Projects
None yet
Development

No branches or pull requests

4 participants