Skip to content
This repository has been archived by the owner on Feb 2, 2019. It is now read-only.

Commit

Permalink
feat(radioGroup): allow two way binding to value
Browse files Browse the repository at this point in the history
 `<md-radio-group [(value)]="yourModel"></md-radio-group>`
  • Loading branch information
justindujardin committed Dec 12, 2015
1 parent 6af23c9 commit 9e8ae62
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
8 changes: 8 additions & 0 deletions ng2-material/all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {MdProgressCircular} from './components/progress_circular/progress_circul
export * from './components/progress_circular/progress_circular';

import {MdRadioButton, MdRadioGroup} from './components/radio/radio_button';
import {MdRadioDispatcher} from './components/radio/radio_dispatcher';
export * from './components/radio/radio_button';
export * from './components/radio/radio_dispatcher';

Expand Down Expand Up @@ -60,3 +61,10 @@ export const MATERIAL_DIRECTIVES: Type[] = CONST_EXPR([
MdSwitch,
MdToolbar
]);

/**
* Collection of Material Design component providers.
*/
export const MATERIAL_PROVIDERS: Type[] = CONST_EXPR([
MdRadioDispatcher
]);
3 changes: 0 additions & 3 deletions ng2-material/components/radio/radio_button.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
@import "../../core/style/variables";
@import "../../core/style/shadows";

// TODO(jelbourn): This goes away.
@import "../../core/style/default-theme";

Expand Down Expand Up @@ -76,7 +75,6 @@ md-radio-group {
cursor: pointer;
}


// THEME

.md-radio-off {
Expand All @@ -94,7 +92,6 @@ md-radio-group {
// TODO
.md-radio-checked .md-ink-ripple { }
.md-radio-container .md-ripple { }
p

md-radio-group:not([disabled]) md-radio:not([disabled]) {

Expand Down
14 changes: 8 additions & 6 deletions ng2-material/components/radio/radio_button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import {Event, KeyboardEvent} from 'angular2/src/facade/browser';

import {MdRadioDispatcher} from './radio_dispatcher';
import {KeyCodes} from '../../core/key_codes';
import {Output} from 'angular2/core';

// TODO(jdd): [disabled] style

// TODO(jelbourn): Behaviors to test
// Disabled radio don't select
Expand All @@ -33,7 +36,6 @@ var _uniqueIdCounter: number = 0;

@Component({
selector: 'md-radio-group',
outputs: ['change'],
inputs: ['disabled', 'value'],
host: {
'role': 'radiogroup',
Expand Down Expand Up @@ -68,7 +70,7 @@ export class MdRadioGroup implements OnChanges {
/** The ID of the selected radio button. */
selectedRadioId: string;

change: EventEmitter<any>;
@Output('valueChange') change: EventEmitter<any>;

tabindex: number;

Expand Down Expand Up @@ -108,10 +110,10 @@ export class MdRadioGroup implements OnChanges {

// If the value of this radio-group has been set or changed, we have to look through the
// child radio buttons and select the one that has a corresponding value (if any).
if (isPresent(this.value) && this.value != '') {
if (isPresent(this.value) && this.value !== '') {
this.radioDispatcher.notify(this.name_);
this.radios_.forEach(radio => {
if (radio.value == this.value) {
if (radio.value === this.value) {
radio.checked = true;
this.selectedRadioId = radio.id;
this.activedescendant = radio.id;
Expand All @@ -125,7 +127,7 @@ export class MdRadioGroup implements OnChanges {
this.value = value;
this.selectedRadioId = id;
this.activedescendant = id;
ObservableWrapper.callEmit(this.change, null);
ObservableWrapper.callEmit(this.change, value);
}

/** Registers a child radio button with this group. */
Expand Down Expand Up @@ -275,7 +277,7 @@ export class MdRadioButton implements OnInit {
// if the user just adds a `disabled` attribute with no value, or may be absent completely.
// TODO(jelbourn): If someone sets `disabled="disabled"`, will this work in dart?
return this.disabled || (isPresent(this.disabled) && StringWrapper.equals(this.disabled, '')) ||
(isPresent(this.radioGroup) && this.radioGroup.disabled);
(isPresent(this.radioGroup) && this.radioGroup.disabled);
}

get disabled(): any {
Expand Down

0 comments on commit 9e8ae62

Please sign in to comment.