Skip to content

Commit d83b3e0

Browse files
tinayuangaojelbourn
authored andcommitted
feat(radio): add ripple (#1553)
1 parent 0174fa9 commit d83b3e0

File tree

5 files changed

+54
-8
lines changed

5 files changed

+54
-8
lines changed

src/lib/radio/_radio-theme.scss

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@
2929
}
3030
}
3131

32-
// TODO(jelbourn): remove style for temporary ripple once the real ripple is applied.
33-
.md-radio-focused .md-ink-ripple {
32+
.md-radio-focused .md-radio-ripple .md-ripple-foreground {
3433
background-color: md-color($accent, 0.26);
3534
}
3635
}

src/lib/radio/radio.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
<div class="md-radio-container">
66
<div class="md-radio-outer-circle"></div>
77
<div class="md-radio-inner-circle"></div>
8-
<div class="md-ink-ripple"></div>
8+
<div md-ripple *ngIf="!disableRipple" class="md-radio-ripple"
9+
[md-ripple-trigger]="getHostElement()"
10+
[md-ripple-centered]="true"
11+
[md-ripple-speed-factor]="0.3"
12+
md-ripple-background-color="rgba(0, 0, 0, 0)"></div>
913
</div>
1014

1115
<input #input class="md-radio-input md-visually-hidden" type="radio"

src/lib/radio/radio.scss

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44

55
$md-radio-size: $md-toggle-size !default;
6+
$md-radio-ripple-size: $md-radio-size * 0.75;
67

78
// Top-level host container.
89
md-radio-button {
@@ -89,4 +90,12 @@ md-radio-button {
8990
cursor: default;
9091
}
9192

92-
@include md-temporary-ink-ripple(radio);
93+
.md-radio-ripple {
94+
position: absolute;
95+
left: -$md-radio-ripple-size;
96+
top: -$md-radio-ripple-size;
97+
right: -$md-radio-ripple-size;
98+
bottom: -$md-radio-ripple-size;
99+
border-radius: 50%;
100+
z-index: 1;
101+
}

src/lib/radio/radio.spec.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,23 @@ describe('MdRadio', () => {
216216

217217
expect(radioInstances.every(radio => !radio.checked)).toBe(true);
218218
});
219+
220+
it('should remove ripple if md-ripple-disabled input is set', async(() => {
221+
fixture.detectChanges();
222+
for (let radioNativeElement of radioNativeElements)
223+
{
224+
expect(radioNativeElement.querySelectorAll('[md-ripple]').length)
225+
.toBe(1, 'Expect [md-ripple] in radio buttons');
226+
}
227+
228+
testComponent.disableRipple = true;
229+
fixture.detectChanges();
230+
for (let radioNativeElement of radioNativeElements)
231+
{
232+
expect(radioNativeElement.querySelectorAll('[md-ripple]').length)
233+
.toBe(0, 'Expect no [md-ripple] in radio buttons');
234+
}
235+
}));
219236
});
220237

221238
describe('group with ngModel', () => {
@@ -437,16 +454,17 @@ describe('MdRadio', () => {
437454
[align]="alignment"
438455
[value]="groupValue"
439456
name="test-name">
440-
<md-radio-button value="fire">Charmander</md-radio-button>
441-
<md-radio-button value="water">Squirtle</md-radio-button>
442-
<md-radio-button value="leaf">Bulbasaur</md-radio-button>
457+
<md-radio-button value="fire" [disableRipple]="disableRipple">Charmander</md-radio-button>
458+
<md-radio-button value="water" [disableRipple]="disableRipple">Squirtle</md-radio-button>
459+
<md-radio-button value="leaf" [disableRipple]="disableRipple">Bulbasaur</md-radio-button>
443460
</md-radio-group>
444461
`
445462
})
446463
class RadiosInsideRadioGroup {
447464
alignment: string;
448465
isGroupDisabled: boolean = false;
449466
groupValue: string = null;
467+
disableRipple: boolean = false;
450468
}
451469

452470

src/lib/radio/radio.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
Component,
44
ContentChildren,
55
Directive,
6+
ElementRef,
67
EventEmitter,
78
HostBinding,
89
Input,
@@ -15,11 +16,13 @@ import {
1516
NgModule,
1617
ModuleWithProviders,
1718
} from '@angular/core';
19+
import {CommonModule} from '@angular/common';
1820
import {
1921
NG_VALUE_ACCESSOR,
2022
ControlValueAccessor
2123
} from '@angular/forms';
22-
import {MdUniqueSelectionDispatcher} from '../core';
24+
import {MdRippleModule, MdUniqueSelectionDispatcher} from '../core';
25+
import {coerceBooleanProperty} from '../core/coersion/boolean-property';
2326

2427

2528

@@ -263,14 +266,22 @@ export class MdRadioButton implements OnInit {
263266
/** Value assigned to this radio.*/
264267
private _value: any = null;
265268

269+
/** Whether the ripple effect on click should be disabled. */
270+
private _disableRipple: boolean;
271+
266272
/** The parent radio group. May or may not be present. */
267273
radioGroup: MdRadioGroup;
268274

275+
@Input()
276+
get disableRipple(): boolean { return this._disableRipple; }
277+
set disableRipple(value) { this._disableRipple = coerceBooleanProperty(value); }
278+
269279
/** Event emitted when the group value changes. */
270280
@Output()
271281
change: EventEmitter<MdRadioChange> = new EventEmitter<MdRadioChange>();
272282

273283
constructor(@Optional() radioGroup: MdRadioGroup,
284+
private _elementRef: ElementRef,
274285
public radioDispatcher: MdUniqueSelectionDispatcher) {
275286
// Assertions. Ideally these should be stripped out by the compiler.
276287
// TODO(jelbourn): Assert that there's no name binding AND a parent radio group.
@@ -411,10 +422,15 @@ export class MdRadioButton implements OnInit {
411422
this.radioGroup._touch();
412423
}
413424
}
425+
426+
getHostElement() {
427+
return this._elementRef.nativeElement;
428+
}
414429
}
415430

416431

417432
@NgModule({
433+
imports: [CommonModule, MdRippleModule],
418434
exports: [MdRadioGroup, MdRadioButton],
419435
declarations: [MdRadioGroup, MdRadioButton],
420436
})

0 commit comments

Comments
 (0)