Skip to content

Commit 81e885f

Browse files
committed
Fixed maxWidth being applied incorrectly on unmeasured elements
1 parent b893ac8 commit 81e885f

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

.changeset/common-things-train.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@plexinc/react-lightning-plugin-flexbox": patch
3+
---
4+
5+
Fixed maxWidth being applied incorrectly on unmeasured elements

packages/plugin-flexbox/src/index.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -240,23 +240,25 @@ export function plugin(yogaOptions?: YogaOptions): Plugin<LightningElement> {
240240
// be the computed width
241241
let computedWidth = flexInstance.yogaNode.getComputedWidth();
242242

243-
if (
244-
Number.isNaN(computedWidth) &&
245-
maxWidth.unit === Yoga.instance.UNIT_PERCENT
246-
) {
247-
// Try to get the parent width and calculating manually
248-
const parentWidth = flexInstance.yogaNode
249-
.getParent()
250-
?.getComputedWidth();
251-
252-
if (parentWidth) {
253-
computedWidth = parentWidth * (maxWidth.value / 100);
243+
if (computedWidth > 0) {
244+
if (
245+
Number.isNaN(computedWidth) &&
246+
maxWidth.unit === Yoga.instance.UNIT_PERCENT
247+
) {
248+
// Try to get the parent width and calculating manually
249+
const parentWidth = flexInstance.yogaNode
250+
.getParent()
251+
?.getComputedWidth();
252+
253+
if (parentWidth) {
254+
computedWidth = parentWidth * (maxWidth.value / 100);
255+
}
254256
}
255-
}
256257

257-
if (event.dimensions.width > computedWidth) {
258-
node.contain = 'width';
259-
node.width = computedWidth;
258+
if (event.dimensions.width > computedWidth) {
259+
node.contain = 'width';
260+
node.width = computedWidth;
261+
}
260262
}
261263
}
262264

0 commit comments

Comments
 (0)