Skip to content

Commit 916806a

Browse files
committed
MC-3474: Apply Resizing Functionality to Preview
- Change largest button calculation to use padding and borders
1 parent 1dc44ff commit 916806a

File tree

2 files changed

+36
-4
lines changed
  • app/code/Magento/PageBuilder/view/adminhtml/web

2 files changed

+36
-4
lines changed

app/code/Magento/PageBuilder/view/adminhtml/web/js/content-type/buttons/preview.js

Lines changed: 19 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/code/Magento/PageBuilder/view/adminhtml/web/ts/js/content-type/buttons/preview.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ export default class Preview extends PreviewCollection {
129129
}
130130

131131
/**
132-
* Find the largest button text value which will determine the button width we use for re-sizing.
132+
* Find the largest button which will determine the button width we use for re-sizing.
133133
*
134134
* @param {JQuery} buttonItems
135135
* @returns {JQuery}
@@ -139,11 +139,26 @@ export default class Preview extends PreviewCollection {
139139
buttonItems.each((index, element) => {
140140
const buttonElement = $(element);
141141
if (largestButton === null
142-
|| buttonElement.find("span").width() > largestButton.find("span").width()) {
142+
|| this.calculateButtonWidth(buttonElement) > this.calculateButtonWidth(largestButton)) {
143143
largestButton = buttonElement;
144144
}
145145
});
146146

147147
return largestButton;
148148
}
149+
150+
/**
151+
* Manually calculate button width using content plus box widths (padding, border)
152+
*
153+
* @param {JQuery} buttonItem
154+
* @returns {number}
155+
*/
156+
private calculateButtonWidth(buttonItem: JQuery): number {
157+
const widthProperties = ["paddingLeft", "paddingRight", "borderLeftWidth", "borderRightWidth"];
158+
const calculatedButtonWidth: number = widthProperties.reduce((accumulatedWidth, widthProperty): number => {
159+
return accumulatedWidth + (parseInt(buttonItem.css(widthProperty), 10) || 0);
160+
}, buttonItem.find("span").width());
161+
162+
return calculatedButtonWidth;
163+
}
149164
}

0 commit comments

Comments
 (0)