The problem here is basically that when multiple objects are selected in the canvas, Fabric dynamically creates a group for them. Because of this, it assumes the rotation of the bounding box for the objects should be 0, because that's a sensible default. Therefore, if we want to get around this, we need to create our own group before we add the items to the canvas so that Fabric knows to treat them as part of the same thing.
In order to do that, we create a fabric.Group
first, add the objects we want to add to the canvas to that, and then add that group to the canvas. For example,
const text = ...;
const rectangle = ...;
const group = new fabric.Group();
group.initialize([text, rectangle]);
canvas.add(group);
Note that this creates a static group - the objects added to the group cannot be separated from each other by user input. Unless there is other code to explicitly break up the group, fabric will continue to treat them as one entity.
JSFiddle: http://jsfiddle.net/35wgmhca/1/
The linked JSFiddle has an orange square grouped with a blue square to demonstrate how that bounding box correctly sticks to the group.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…