Skip to content

Commit 6575ade

Browse files
chore: use computed radius size for checkbox ripple during 2018 material spec update transition (#13038)
1 parent 948e563 commit 6575ade

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
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: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import {FocusMonitor, FocusOrigin} from '@angular/cdk/a11y';
1010
import {coerceBooleanProperty} from '@angular/cdk/coercion';
1111
import {
12+
AfterViewChecked,
1213
AfterViewInit,
1314
Attribute,
1415
ChangeDetectionStrategy,
@@ -50,6 +51,11 @@ import {MAT_CHECKBOX_CLICK_ACTION, MatCheckboxClickAction} from './checkbox-conf
5051
// Increasing integer for generating unique ids for checkbox components.
5152
let nextUniqueId = 0;
5253

54+
// TODO(josephperrott): Revert to constants for ripple radius once 2018 Checkbox updates have
55+
// landed.
56+
// The radius for the checkbox's ripple, in pixels.
57+
let calculatedRippleRadius = 0;
58+
5359
/**
5460
* Provider Expression that allows mat-checkbox to register as a ControlValueAccessor.
5561
* This allows it to support [(ngModel)].
@@ -127,7 +133,8 @@ export const _MatCheckboxMixinBase:
127133
changeDetection: ChangeDetectionStrategy.OnPush
128134
})
129135
export class MatCheckbox extends _MatCheckboxMixinBase implements ControlValueAccessor,
130-
AfterViewInit, OnDestroy, CanColor, CanDisable, HasTabIndex, CanDisableRipple {
136+
AfterViewChecked, AfterViewInit, OnDestroy, CanColor, CanDisable, HasTabIndex,
137+
CanDisableRipple {
131138

132139
/**
133140
* Attached to the aria-label attribute of the host element. In most cases, arial-labelledby will
@@ -210,6 +217,10 @@ export class MatCheckbox extends _MatCheckboxMixinBase implements ControlValueAc
210217
.subscribe(focusOrigin => this._onInputFocusChange(focusOrigin));
211218
}
212219

220+
ngAfterViewChecked() {
221+
this._calculateRippleRadius();
222+
}
223+
213224
ngOnDestroy() {
214225
this._focusMonitor.stopMonitoring(this._inputElement);
215226
}
@@ -457,4 +468,19 @@ export class MatCheckbox extends _MatCheckboxMixinBase implements ControlValueAc
457468

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

0 commit comments

Comments
 (0)