Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.

Commit 69e87e5

Browse files
committed
chore: Fix regression in MDCChipFoundation.getDimensions()
PR #4332 inadvertently broke short-circuit logic and evaluation order. The change caused incorrect ripple size calculations on filter chips without leading icons, which was caught by internal screenshot tests.
1 parent b6b6983 commit 69e87e5

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

packages/mdc-chips/chip/foundation.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,19 +94,24 @@ export class MDCChipFoundation extends MDCFoundation<MDCChipAdapter> {
9494
}
9595

9696
getDimensions(): ClientRect {
97-
const rootRect = this.adapter_.getRootBoundingClientRect();
98-
const checkmarkRect = this.adapter_.getCheckmarkBoundingClientRect();
97+
const getRootRect = () => this.adapter_.getRootBoundingClientRect();
98+
const getCheckmarkRect = () => this.adapter_.getCheckmarkBoundingClientRect();
9999

100100
// When a chip has a checkmark and not a leading icon, the bounding rect changes in size depending on the current
101101
// size of the checkmark.
102-
if (!this.adapter_.hasLeadingIcon() && checkmarkRect !== null) {
103-
// The checkmark's width is initially set to 0, so use the checkmark's height as a proxy since the checkmark
104-
// should always be square.
105-
const width = rootRect.width + checkmarkRect.height;
106-
return {...rootRect, width};
107-
} else {
108-
return rootRect;
102+
if (!this.adapter_.hasLeadingIcon()) {
103+
const checkmarkRect = getCheckmarkRect();
104+
if (checkmarkRect) {
105+
const rootRect = getRootRect();
106+
const height = rootRect.height;
107+
// The checkmark's width is initially set to 0, so use the checkmark's height as a proxy since the checkmark
108+
// should always be square.
109+
const width = rootRect.width + checkmarkRect.height;
110+
return {...rootRect, width, height};
111+
}
109112
}
113+
114+
return getRootRect();
110115
}
111116

112117
/**

0 commit comments

Comments
 (0)