|
9 | 9 | import {FocusMonitor, FocusOrigin} from '@angular/cdk/a11y';
|
10 | 10 | import {coerceBooleanProperty} from '@angular/cdk/coercion';
|
11 | 11 | import {
|
| 12 | + AfterViewChecked, |
12 | 13 | AfterViewInit,
|
13 | 14 | Attribute,
|
14 | 15 | ChangeDetectionStrategy,
|
@@ -50,6 +51,11 @@ import {MAT_CHECKBOX_CLICK_ACTION, MatCheckboxClickAction} from './checkbox-conf
|
50 | 51 | // Increasing integer for generating unique ids for checkbox components.
|
51 | 52 | let nextUniqueId = 0;
|
52 | 53 |
|
| 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 | + |
53 | 59 | /**
|
54 | 60 | * Provider Expression that allows mat-checkbox to register as a ControlValueAccessor.
|
55 | 61 | * This allows it to support [(ngModel)].
|
@@ -127,7 +133,8 @@ export const _MatCheckboxMixinBase:
|
127 | 133 | changeDetection: ChangeDetectionStrategy.OnPush
|
128 | 134 | })
|
129 | 135 | export class MatCheckbox extends _MatCheckboxMixinBase implements ControlValueAccessor,
|
130 |
| - AfterViewInit, OnDestroy, CanColor, CanDisable, HasTabIndex, CanDisableRipple { |
| 136 | + AfterViewChecked, AfterViewInit, OnDestroy, CanColor, CanDisable, HasTabIndex, |
| 137 | + CanDisableRipple { |
131 | 138 |
|
132 | 139 | /**
|
133 | 140 | * 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
|
210 | 217 | .subscribe(focusOrigin => this._onInputFocusChange(focusOrigin));
|
211 | 218 | }
|
212 | 219 |
|
| 220 | + ngAfterViewChecked() { |
| 221 | + this._calculateRippleRadius(); |
| 222 | + } |
| 223 | + |
213 | 224 | ngOnDestroy() {
|
214 | 225 | this._focusMonitor.stopMonitoring(this._inputElement);
|
215 | 226 | }
|
@@ -457,4 +468,19 @@ export class MatCheckbox extends _MatCheckboxMixinBase implements ControlValueAc
|
457 | 468 |
|
458 | 469 | return `mat-checkbox-anim-${animSuffix}`;
|
459 | 470 | }
|
| 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 | + } |
460 | 486 | }
|
0 commit comments