How to disable group selection in Fabric.js and leave single objects selectable one at a time? With group selection I mean selecting multiple objects using eg. SHIFT+Click.
you can easily achieve this with
canvas.selection = false; // disable group selection
if you want it on individual object
rect.set('selectable', false); // make object unselectable
Disable group selection via selection listener canvas method (in my opinion the best way)
canvas.on('selection:created', (e) => {
if(e.target.type === 'activeSelection') {
canvas.discardActiveObject();
} else {
//do nothing
}
})
@CQ Smooth's answer was close to my requirements, thanks. But I needed the event to be fired when you select one object first, then add another via shift+click:
canvas.on({
'selection:updated': e => {
const activeSelection = e.target
if (activeSelection) {
canvas.discardActiveObject();
}
}
})
You can see the solution working at: https://app.collagemaker.uk/create
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With