I am making drawing editor using Fabric.js. One of the requirements is to create flexible text box component (like Goole Slides or Power Point) whose bounding box can be adjusted without compromising text size and other text controls like scale, reposition... Currently, what fabric.js provides with fabric.Text is not sufficient for this task. So I am using fabric.Group but I am stack on selection issue. I cannot select sub-objects of group. How can I go about this issue. Any information is welcome
This is I want to achieve:
This is what I have now with raw fabric.Text object
This is what I have achieved with fabric.Group
Here is my class which is intended for Textbox
class Text extends fabric.Group {
constructor(options) {
super([], Object.assign(options));
this.class = 'textbox';
this.init();
}
init() {
const left = this.left;
const top = this.top;
const width = this.width || 100;
const height = this.height || 40;
this.rect = new fabric.Rect({
left,
top,
width,
height,
fill: 'rgba(0,0,0,0)',
stroke: this.stroke,
type: 'rect',
originX: 'left',
originY: 'top',
strokeWidth: this.strokeWidth
});
this.text = new fabric.IText(this.text, {
left: left + 20,
top: top + 12,
fontSize: this.fontSize,
fontFamily: this.fontFamily,
fontColor: this.fontColor,
selectable: true
});
this.text.setCoords();
this.text.setControlsVisibility({
br: false, // middle top disable
bl: false, // midle bottom
tl: false, // middle left
tr: false, // I think you get it,
mb: false,
ml: false,
mt: false,
mr: false,
mtr: false
});
this.addWithUpdate(this.rect);
this.addWithUpdate(this.text);
}
toObject() {
const obj = super.toObject();
return Object.assign(obj, {
class: this.class
});
}
}
export default Text;


