Giter VIP home page Giter VIP logo

Comments (7)

matdru avatar matdru commented on May 26, 2024 3

I think the most sensible solution for time being will be to re-enable onClick propagation and introduce an internal flag system so that craft can handle selection events properly, @prevwong i can try and draft a PR for that

from craft.js.

prevwong avatar prevwong commented on May 26, 2024 2

@dadwic @ymoussaba @hdaggett Fixed in 0.1.0.beta-8! 🥳

from craft.js.

prevwong avatar prevwong commented on May 26, 2024 1

So this is because the connect/select connector adds a onClick event handler to the DOM element and it prevents propagation, so this means any other onClick handler that you add will not be fired 😢

We would definitely like to improve this behaviour. But in the meantime, the temporary workaround is to use a side effect that reacts to the selected event:

const Button = () => {
  const { selected } = useNode(node => ({ selected: node.events.selected });

  useEffect(() => {
    if ( selected ) {
      console.log("Button clicked!")
   } 
  }, [selected]);
} 

from craft.js.

prevwong avatar prevwong commented on May 26, 2024 1

Yeah, previously for the select handler, we were using onMouseDownCapture with debounce, which made it possible for you to add your own event handlers without issues.

But this had some caveats for us internally. For example, the event handler would be fired multiple times (so in the case of the select handler, we will be calling setNodeEvent multiple times, which was not ideal)

from craft.js.

hdaggett avatar hdaggett commented on May 26, 2024 1
const Button = () => {
  const { selected } = useNode(node => ({ selected: node.events.selected });

  useEffect(() => {
    if ( selected ) {
      console.log("Button clicked!")
   } 
  }, [selected]);
} 

This doesn't work for components that have multiple elements that may be clicked inside them :(

from craft.js.

dadwic avatar dadwic commented on May 26, 2024

Thanks,
In the previous version (v0.1.0-beta.6), this bug did not exist!

from craft.js.

ymoussaba avatar ymoussaba commented on May 26, 2024

I was dealing with this issue after an update too. I use a popover to edit the components. But since most react libraries (Antd in my case) are relying on onClick, nothing works.

Wouldn't there be a way to use another event than the onClick?

from craft.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.