Skip to content

Commit 2ac6e14

Browse files
committed
chore: use computed radius size for checkbox ripple during 2018 material spec update transition
1 parent 7c4fa66 commit 2ac6e14

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/lib/checkbox/checkbox.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ $_mat-checkbox-mark-stroke-size: 2 / 15 * $mat-checkbox-size !default;
438438
left: calc(50% - #{$_mat-checkbox-ripple-radius});
439439
top: calc(50% - #{$_mat-checkbox-ripple-radius});
440440
height: $_mat-checkbox-ripple-radius * 2;
441-
width: $_mat_checkbox-ripple-radius * 2;
441+
width: $_mat-checkbox-ripple-radius * 2;
442442
z-index: 1;
443443
pointer-events: none;
444444
}

src/lib/checkbox/checkbox.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ import {MAT_CHECKBOX_CLICK_ACTION, MatCheckboxClickAction} from './checkbox-conf
5050
// Increasing integer for generating unique ids for checkbox components.
5151
let nextUniqueId = 0;
5252

53+
// TODO(josephperrott): Revert to constants for ripple radius once 2018 Checkbox updates have
54+
// landed.
55+
// The radius for the checkbox's ripple, in pixels.
56+
let calculatedRippleRadius = 0;
57+
5358
/**
5459
* Provider Expression that allows mat-checkbox to register as a ControlValueAccessor.
5560
* This allows it to support [(ngModel)].
@@ -210,6 +215,10 @@ export class MatCheckbox extends _MatCheckboxMixinBase implements ControlValueAc
210215
.subscribe(focusOrigin => this._onInputFocusChange(focusOrigin));
211216
}
212217

218+
ngAfterViewChecked() {
219+
this._calculateRippleRadius();
220+
}
221+
213222
ngOnDestroy() {
214223
this._focusMonitor.stopMonitoring(this._inputElement);
215224
}
@@ -457,4 +466,19 @@ export class MatCheckbox extends _MatCheckboxMixinBase implements ControlValueAc
457466

458467
return `mat-checkbox-anim-${animSuffix}`;
459468
}
469+
470+
// TODO(josephperrott): Revert to constants for ripple radius once 2018 Checkbox updates have
471+
// landed.
472+
/**
473+
* Calculate the radius for the ripple based on the ripple elements width. Only calculated once
474+
* for the application.
475+
*/
476+
private _calculateRippleRadius() {
477+
if (!calculatedRippleRadius) {
478+
const rippleWidth =
479+
this._elementRef.nativeElement.querySelector('.mat-checkbox-ripple').clientWidth || 0;
480+
calculatedRippleRadius = rippleWidth / 2;
481+
}
482+
this.ripple.radius = calculatedRippleRadius;
483+
}
460484
}

0 commit comments

Comments
 (0)