Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions packages/block-editor/src/utils/fit-text-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ function findOptimalFontSize( textElement, applyFontSize ) {
const range = document.createRange();
range.selectNodeContents( textElement );

let referenceElement = textElement;
const parentElement = textElement.parentElement;
if (
parentElement &&
window?.getComputedStyle( parentElement )?.display === 'flex'
) {
referenceElement = parentElement;
}

while ( minSize <= maxSize ) {
const midSize = Math.floor( ( minSize + maxSize ) / 2 );
applyFontSize( midSize );
Expand All @@ -36,12 +45,14 @@ function findOptimalFontSize( textElement, applyFontSize ) {
// Check if text fits within the element's width and is not
// overflowing into the padding area.
const fitsWidth =
textElement.scrollWidth <= textElement.clientWidth &&
textWidth <= textElement.clientWidth - paddingLeft - paddingRight;
textElement.scrollWidth <= referenceElement.clientWidth &&
// textWidth <= textElement.parentElement.clientWidth &&
textWidth <=
referenceElement.clientWidth - paddingLeft - paddingRight;
// Check if text fits within the element's height.
const fitsHeight =
alreadyHasScrollableHeight ||
textElement.scrollHeight <= textElement.clientHeight;
textElement.scrollHeight <= referenceElement.clientHeight;

if ( fitsWidth && fitsHeight ) {
bestSize = midSize;
Expand Down
Loading