Skip to content

Commit fe315ef

Browse files
authored
clean up radio docs (#3524)
1 parent 22668af commit fe315ef

File tree

1 file changed

+65
-63
lines changed

1 file changed

+65
-63
lines changed

src/lib/radio/radio.ts

Lines changed: 65 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ var _uniqueIdCounter = 0;
4343

4444
/** Change event object emitted by MdRadio and MdRadioGroup. */
4545
export class MdRadioChange {
46+
/** The MdRadioButton that emits the change event. */
4647
source: MdRadioButton;
48+
/** The value of the MdRadioButton. */
4749
value: any;
4850
}
4951

@@ -270,9 +272,6 @@ export class MdRadioGroup implements AfterContentInit, ControlValueAccessor {
270272
})
271273
export class MdRadioButton implements OnInit, AfterViewInit, OnDestroy {
272274

273-
/** Whether this radio is checked. */
274-
private _checked: boolean = false;
275-
276275
/** The unique ID for the radio button. */
277276
@Input() id: string = `md-radio-${_uniqueIdCounter++}`;
278277

@@ -285,65 +284,11 @@ export class MdRadioButton implements OnInit, AfterViewInit, OnDestroy {
285284
/** The 'aria-labelledby' attribute takes precedence as the element's text alternative. */
286285
@Input('aria-labelledby') ariaLabelledby: string;
287286

288-
/** Whether this radio is disabled. */
289-
private _disabled: boolean;
290-
291-
/** Value assigned to this radio.*/
292-
private _value: any = null;
293-
294-
/** Whether the ripple effect on click should be disabled. */
295-
private _disableRipple: boolean;
296-
297-
/** The child ripple instance. */
298-
@ViewChild(MdRipple) _ripple: MdRipple;
299-
300-
/** Stream of focus event from the focus origin monitor. */
301-
private _focusOriginMonitorSubscription: Subscription;
302-
303-
/** Reference to the current focus ripple. */
304-
private _focusedRippleRef: RippleRef;
305-
306-
/** The parent radio group. May or may not be present. */
307-
radioGroup: MdRadioGroup;
308-
309287
/** Whether the ripple effect for this radio button is disabled. */
310288
@Input()
311289
get disableRipple(): boolean { return this._disableRipple; }
312290
set disableRipple(value) { this._disableRipple = coerceBooleanProperty(value); }
313291

314-
/**
315-
* Event emitted when the checked state of this radio button changes.
316-
* Change events are only emitted when the value changes due to user interaction with
317-
* the radio button (the same behavior as `<input type-"radio">`).
318-
*/
319-
@Output()
320-
change: EventEmitter<MdRadioChange> = new EventEmitter<MdRadioChange>();
321-
322-
/** The native `<input type=radio>` element */
323-
@ViewChild('input') _inputElement: ElementRef;
324-
325-
constructor(@Optional() radioGroup: MdRadioGroup,
326-
private _elementRef: ElementRef,
327-
private _renderer: Renderer,
328-
private _focusOriginMonitor: FocusOriginMonitor,
329-
public radioDispatcher: UniqueSelectionDispatcher) {
330-
// Assertions. Ideally these should be stripped out by the compiler.
331-
// TODO(jelbourn): Assert that there's no name binding AND a parent radio group.
332-
333-
this.radioGroup = radioGroup;
334-
335-
radioDispatcher.listen((id: string, name: string) => {
336-
if (id != this.id && name == this.name) {
337-
this.checked = false;
338-
}
339-
});
340-
}
341-
342-
/** ID of the native input element inside `<md-radio-button>` */
343-
get inputId(): string {
344-
return `${this.id}-input`;
345-
}
346-
347292
/** Whether this radio button is checked. */
348293
@Input()
349294
get checked(): boolean {
@@ -364,7 +309,7 @@ export class MdRadioButton implements OnInit, AfterViewInit, OnDestroy {
364309

365310
if (newCheckedState) {
366311
// Notify all radio buttons with the same name to un-check.
367-
this.radioDispatcher.notify(this.id, this.name);
312+
this._radioDispatcher.notify(this.id, this.name);
368313
}
369314
}
370315
}
@@ -429,6 +374,68 @@ export class MdRadioButton implements OnInit, AfterViewInit, OnDestroy {
429374
this._disabled = (value != null && value !== false) ? true : null;
430375
}
431376

377+
/**
378+
* Event emitted when the checked state of this radio button changes.
379+
* Change events are only emitted when the value changes due to user interaction with
380+
* the radio button (the same behavior as `<input type-"radio">`).
381+
*/
382+
@Output()
383+
change: EventEmitter<MdRadioChange> = new EventEmitter<MdRadioChange>();
384+
385+
/** The parent radio group. May or may not be present. */
386+
radioGroup: MdRadioGroup;
387+
388+
/** ID of the native input element inside `<md-radio-button>` */
389+
get inputId(): string {
390+
return `${this.id}-input`;
391+
}
392+
393+
/** Whether this radio is checked. */
394+
private _checked: boolean = false;
395+
396+
/** Whether this radio is disabled. */
397+
private _disabled: boolean;
398+
399+
/** Value assigned to this radio.*/
400+
private _value: any = null;
401+
402+
/** Whether the ripple effect on click should be disabled. */
403+
private _disableRipple: boolean;
404+
405+
/** The child ripple instance. */
406+
@ViewChild(MdRipple) _ripple: MdRipple;
407+
408+
/** Stream of focus event from the focus origin monitor. */
409+
private _focusOriginMonitorSubscription: Subscription;
410+
411+
/** Reference to the current focus ripple. */
412+
private _focusedRippleRef: RippleRef;
413+
414+
/** The native `<input type=radio>` element */
415+
@ViewChild('input') _inputElement: ElementRef;
416+
417+
constructor(@Optional() radioGroup: MdRadioGroup,
418+
private _elementRef: ElementRef,
419+
private _renderer: Renderer,
420+
private _focusOriginMonitor: FocusOriginMonitor,
421+
private _radioDispatcher: UniqueSelectionDispatcher) {
422+
// Assertions. Ideally these should be stripped out by the compiler.
423+
// TODO(jelbourn): Assert that there's no name binding AND a parent radio group.
424+
425+
this.radioGroup = radioGroup;
426+
427+
_radioDispatcher.listen((id: string, name: string) => {
428+
if (id != this.id && name == this.name) {
429+
this.checked = false;
430+
}
431+
});
432+
}
433+
434+
/** Focuses the radio button. */
435+
focus(): void {
436+
this._focusOriginMonitor.focusVia(this._inputElement.nativeElement, this._renderer, 'keyboard');
437+
}
438+
432439
ngOnInit() {
433440
if (this.radioGroup) {
434441
// If the radio is inside a radio group, determine if it should be checked
@@ -469,11 +476,6 @@ export class MdRadioButton implements OnInit, AfterViewInit, OnDestroy {
469476
return this.disableRipple || this.disabled;
470477
}
471478

472-
/** Focuses the radio button. */
473-
focus(): void {
474-
this._focusOriginMonitor.focusVia(this._inputElement.nativeElement, this._renderer, 'keyboard');
475-
}
476-
477479
_onInputBlur() {
478480
if (this._focusedRippleRef) {
479481
this._focusedRippleRef.fadeOut();

0 commit comments

Comments
 (0)