@@ -317,13 +317,16 @@ const COMPOSER_CONTEXT_MOTION_EASING = "cubic-bezier(0.32, 0.72, 0, 1)";
317317const COMPOSER_CONTEXT_LABEL_SELECTOR = "[data-composer-label]" ;
318318
319319/**
320- * The width a label's text needs on one line , clipped parts included.
320+ * The width a label takes when shown , clipped parts included.
321321 *
322322 * Text keeps its full width when its box clips it, so each text run measures
323323 * whole. A label can hold more than one run (MiddleTruncate splits a branch
324324 * into a head and a tail), so the runs are added. Reading one element's
325325 * scrollWidth drops the tail when the label is hidden or squeezed, and the
326326 * strip then flips between labels and icons on every measure.
327+ *
328+ * A shown label never grows past its motion span's max width, so longer text
329+ * reserves only that much.
327330 */
328331function labelTextWidth ( label : HTMLElement , range : Range ) : number {
329332 const walker = document . createTreeWalker ( label , NodeFilter . SHOW_TEXT ) ;
@@ -332,7 +335,9 @@ function labelTextWidth(label: HTMLElement, range: Range): number {
332335 range . selectNodeContents ( node ) ;
333336 width += range . getBoundingClientRect ( ) . width ;
334337 }
335- return width ;
338+ const motion = label . querySelector < HTMLElement > ( "[data-composer-label-motion]" ) ;
339+ const maxWidth = motion ? Number . parseFloat ( getComputedStyle ( motion ) . maxWidth ) : Number . NaN ;
340+ return Number . isFinite ( maxWidth ) ? Math . min ( width , maxWidth ) : width ;
336341}
337342
338343/**
0 commit comments