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

Commit b26ad23

Browse files
authored
fix(ripple): Always set even num when initial ripple size is ca… (#5141)
1 parent 3eae309 commit b26ad23

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

packages/mdc-ripple/foundation.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,13 @@ export class MDCRippleFoundation extends MDCFoundation<MDCRippleAdapter> {
502502
this.maxRadius_ = this.adapter_.isUnbounded() ? maxDim : getBoundedRadius();
503503

504504
// Ripple is sized as a fraction of the largest dimension of the surface, then scales up using a CSS scale transform
505-
this.initialSize_ = Math.floor(maxDim * MDCRippleFoundation.numbers.INITIAL_ORIGIN_SCALE);
505+
const initialSize = Math.floor(maxDim * MDCRippleFoundation.numbers.INITIAL_ORIGIN_SCALE);
506+
// Unbounded ripple size should always be even number to equally center align.
507+
if (this.adapter_.isUnbounded() && initialSize % 2 !== 0) {
508+
this.initialSize_ = initialSize - 1;
509+
} else {
510+
this.initialSize_ = initialSize;
511+
}
506512
this.fgScale_ = `${this.maxRadius_ / this.initialSize_}`;
507513

508514
this.updateLayoutCssVars_();

test/unit/mdc-ripple/foundation.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,20 @@ testFoundation(`#layout sets ${strings.VAR_FG_SIZE} to the circumscribing circle
233233
td.verify(adapter.updateCssVariable(strings.VAR_FG_SIZE, `${initialSize}px`));
234234
});
235235

236+
testFoundation(`#layout always sets ${strings.VAR_FG_SIZE} to even number`,
237+
({foundation, adapter, clock}) => {
238+
const width = 36;
239+
const height = 36;
240+
241+
td.when(adapter.computeBoundingRect()).thenReturn({width, height});
242+
td.when(adapter.isUnbounded()).thenReturn(true);
243+
foundation.layout();
244+
clock.runToFrame();
245+
246+
const isEvenNumber = (pixel) => (parseInt(pixel, 10) % 2 === 0);
247+
td.verify(adapter.updateCssVariable(strings.VAR_FG_SIZE, td.matchers.argThat(isEvenNumber)));
248+
});
249+
236250
testFoundation(`#layout sets ${strings.VAR_FG_SCALE} based on the difference between the ` +
237251
'proportion of the max radius and the initial size', ({foundation, adapter, clock}) => {
238252
const width = 200;

0 commit comments

Comments
 (0)