Aakansha Doshi 2 years ago
parent
commit
b3068a5248
1 changed files with 10 additions and 1 deletions
  1. 10 1
      src/element/resizeElements.ts

+ 10 - 1
src/element/resizeElements.ts

@@ -23,6 +23,7 @@ import {
 } from "./bounds";
 import {
   isArrowElement,
+  isBoundToContainer,
   isFreeDrawElement,
   isLinearElement,
   isTextElement,
@@ -44,6 +45,7 @@ import {
   getBoundTextElementId,
   handleBindTextResize,
   getMaxContainerWidth,
+  getContainerElement,
 } from "./textElement";
 
 export const normalizeAngle = (angle: number): number => {
@@ -193,8 +195,15 @@ const measureFontSizeFromWidth = (
   nextWidth: number,
 ): number | null => {
   // We only use width to scale font on resize
-  const width = element.width;
+  let width = element.width;
 
+  const hasContainer = isBoundToContainer(element);
+  if (hasContainer) {
+    const container = getContainerElement(element);
+    if (container) {
+      width = getMaxContainerWidth(container);
+    }
+  }
   const nextFontSize = element.fontSize * (nextWidth / width);
   if (nextFontSize < MIN_FONT_SIZE) {
     return null;