FabricJS Catch click on object inside group

Gonchar Denys picture Gonchar Denys · Dec 2, 2015 · Viewed 11.7k times · Source

I have tried many thing like calculating location, handling with the event we do have in original fabricjs. Does any have done this before?

Answer

Kevin Farrugia picture Kevin Farrugia · Apr 13, 2017

It is possible to listen for events on the inner object by adding the option: subTargetCheck: true to the fabric.Group object.

    // create a group
    let group = new fabric.Group([circle, rect], {
        subTargetCheck: true
    });

    circle.on('mousedown', function(e) { 
        // e.target should be the circle
        console.log(e.target);
    });