I can’t find any information on how to properly ungroup items in fabricjs v6 in a Typescript environment.
Group.toActiveSelection isn’t in v6 that I can tell, and the closest I can get is with this:
const ungroupSelectedObject = () => {
if (!fabricCanvasRef.current) return;
const activeObject = fabricCanvasRef.current.getActiveObject();
if (activeObject && isGroup(activeObject)) {
const items = activeObject.getObjects();
fabricCanvasRef.current.remove(activeObject);
items.forEach((item) => {
fabricCanvasRef.current?.add(item);
});
// Optionally, select the ungrouped items
const selection = new fabric.ActiveSelection(items, {
canvas: fabricCanvasRef.current,
});
fabricCanvasRef.current.setActiveObject(selection);
fabricCanvasRef.current.renderAll();
setIsGroupSelected(false);
setIsMultipleSelected(true);
}
};
But the ungrouped objects are no longer selectable. Other tries have teleported the objects and broken the canvas, so I’m out of ideas.