Skip to content

Commit

Permalink
fix(ripple): Always set even num when initial ripple size is ca… (#5141)
Browse files Browse the repository at this point in the history
  • Loading branch information
abhiomkar authored Oct 2, 2019
1 parent 3eae309 commit b26ad23
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/mdc-ripple/foundation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,13 @@ export class MDCRippleFoundation extends MDCFoundation<MDCRippleAdapter> {
this.maxRadius_ = this.adapter_.isUnbounded() ? maxDim : getBoundedRadius();

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

this.updateLayoutCssVars_();
Expand Down
14 changes: 14 additions & 0 deletions test/unit/mdc-ripple/foundation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,20 @@ testFoundation(`#layout sets ${strings.VAR_FG_SIZE} to the circumscribing circle
td.verify(adapter.updateCssVariable(strings.VAR_FG_SIZE, `${initialSize}px`));
});

testFoundation(`#layout always sets ${strings.VAR_FG_SIZE} to even number`,
({foundation, adapter, clock}) => {
const width = 36;
const height = 36;

td.when(adapter.computeBoundingRect()).thenReturn({width, height});
td.when(adapter.isUnbounded()).thenReturn(true);
foundation.layout();
clock.runToFrame();

const isEvenNumber = (pixel) => (parseInt(pixel, 10) % 2 === 0);
td.verify(adapter.updateCssVariable(strings.VAR_FG_SIZE, td.matchers.argThat(isEvenNumber)));
});

testFoundation(`#layout sets ${strings.VAR_FG_SCALE} based on the difference between the ` +
'proportion of the max radius and the initial size', ({foundation, adapter, clock}) => {
const width = 200;
Expand Down

0 comments on commit b26ad23

Please sign in to comment.