Skip to content

Commit

Permalink
Fixed #1420
Browse files Browse the repository at this point in the history
  • Loading branch information
Çağatay Çivici committed Nov 24, 2016
1 parent b2810a2 commit e8a93c9
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions components/radiobutton/radiobutton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ export const RADIO_VALUE_ACCESSOR: any = {
template: `
<div class="ui-radiobutton ui-widget">
<div class="ui-helper-hidden-accessible">
<input type="radio" [attr.name]="name" [attr.value]="value" [checked]="checked" (change)="onChange($event)"
<input #rb type="radio" [attr.name]="name" [attr.value]="value" [checked]="checked" (change)="onChange($event)"
(focus)="onFocus($event)" (blur)="onBlur($event)">
</div>
<div (click)="handleClick()" (mouseenter)="hover=true" (mouseleave)="hover=false"
<div (click)="handleClick(rb)" (mouseenter)="hover=true" (mouseleave)="hover=false"
[ngClass]="{'ui-radiobutton-box ui-widget ui-state-default':true,
'ui-state-hover':hover&&!disabled,'ui-state-active':checked,'ui-state-disabled':disabled,'ui-state-focus':focused}">
<span class="ui-radiobutton-icon" [ngClass]="{'fa fa-fw fa-circle':checked}"></span>
'ui-state-hover':hover&&!disabled,'ui-state-active':rb.checked,'ui-state-disabled':disabled,'ui-state-focus':focused}">
<span class="ui-radiobutton-icon" [ngClass]="{'fa fa-fw fa-circle':rb.checked}"></span>
</div>
</div>
<label class="ui-radiobutton-label" (click)="select()" *ngIf="label">{{label}}</label>
<label class="ui-radiobutton-label" (click)="select(rb)" *ngIf="label">{{label}}</label>
`,
providers: [RADIO_VALUE_ACCESSOR]
})
Expand All @@ -37,9 +37,7 @@ export class RadioButton implements ControlValueAccessor {
@Input() label: string;

@Output() onClick: EventEmitter<any> = new EventEmitter();

public model: any;


public onModelChange: Function = () => {};

public onModelTouched: Function = () => {};
Expand All @@ -50,23 +48,22 @@ export class RadioButton implements ControlValueAccessor {

public focused: boolean;

handleClick() {
handleClick(rb: HTMLInputElement) {
if(!this.disabled) {
this.onClick.emit(null);
this.select();
this.select(rb);
}
}

select() {
select(rb: HTMLInputElement) {
if(!this.disabled) {
this.checked = true;
rb.checked = true;
this.onModelChange(this.value);
}
}

writeValue(model: any) : void {
this.model = model;
this.checked = (this.model == this.value);
this.checked = (model == this.value);
}

registerOnChange(fn: Function): void {
Expand All @@ -90,8 +87,8 @@ export class RadioButton implements ControlValueAccessor {
this.onModelTouched();
}

onChange(event) {
this.select();
onChange(event,rb: HTMLInputElement) {
this.select(rb);
}
}

Expand Down

0 comments on commit e8a93c9

Please sign in to comment.