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

chore: Fix regression in MDCChipFoundation.getDimensions() #4443

Merged
merged 3 commits into from
Feb 23, 2019
Merged
Changes from 1 commit
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
23 changes: 14 additions & 9 deletions packages/mdc-chips/chip/foundation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,19 +94,24 @@ export class MDCChipFoundation extends MDCFoundation<MDCChipAdapter> {
}

getDimensions(): ClientRect {
const rootRect = this.adapter_.getRootBoundingClientRect();
const checkmarkRect = this.adapter_.getCheckmarkBoundingClientRect();
const getRootRect = () => this.adapter_.getRootBoundingClientRect();
const getCheckmarkRect = () => this.adapter_.getCheckmarkBoundingClientRect();

// When a chip has a checkmark and not a leading icon, the bounding rect changes in size depending on the current
// size of the checkmark.
if (!this.adapter_.hasLeadingIcon() && checkmarkRect !== null) {
// The checkmark's width is initially set to 0, so use the checkmark's height as a proxy since the checkmark
// should always be square.
const width = rootRect.width + checkmarkRect.height;
return {...rootRect, width};
} else {
return rootRect;
if (!this.adapter_.hasLeadingIcon()) {
const checkmarkRect = getCheckmarkRect();
if (checkmarkRect) {
const rootRect = getRootRect();
const height = rootRect.height;
// The checkmark's width is initially set to 0, so use the checkmark's height as a proxy since the checkmark
// should always be square.
const width = rootRect.width + checkmarkRect.height;
return {...rootRect, width, height};
}
}

return getRootRect();
}

/**
Expand Down