### File

`src/radio/radio.component.ts`

### Description

class: Radio (extends Checkbox)

selector: `n-radio`

source: `src/forms/radio.component.ts`

     * <ibm-radio [(ngModel)]="radioState">Radio</ibm-radio>
     *

Also see: `RadioGroup`

### Metadata

providers | `{ provide: NG_VALUE_ACCESSOR, useExisting: Radio, multi: true }`
selector | `ibm-radio`
template |
    <input
    	*ngIf="!skeleton"
    	class="bx--radio-button"
    	type="radio"
    	[checked]="checked"
    	[disabled]="disabled"
    	[name]="name"
    	[id]="id"
    	[required]="required"
    	[value]="value"
    	[attr.aria-labelledby]="ariaLabelledby"
    	(change)="onChange($event)">
    <div *ngIf="skeleton" class="bx--radio-button bx--skeleton"></div>
    <label
    	class="bx--radio-button__label"
    	[ngClass]="{
    		'bx--skeleton': skeleton
    	}"
    	[for]="id"
    	id="label-{{id}}">
    	<span class="bx--radio-button__appearance"></span>
    	<ng-content></ng-content>
    </label>

### Index

###### Properties
Protected _labelledby radioChangeHandler Static radioCount
###### Methods
onChange registerRadioChangeHandler
###### Inputs
ariaLabelledby checked disabled id labelPlacement name required skeleton value
###### Outputs
change
###### HostBindings
attr.role class.bx--radio-button-wrapper class.bx--radio-button-wrapper--label-left
###### Accessors
ariaLabelledby

### Inputs

`ariaLabelledby` | Type : `string`
Defined in src/radio/radio.component.ts:73

`checked` | Default value : `false`
Defined in src/radio/radio.component.ts:65

`disabled` | Default value : `false`
Defined in src/radio/radio.component.ts:69

`id` | The id for the `Radio`. Default value : ``radio-${Radio.radioCount++}``
Defined in src/radio/radio.component.ts:98

`labelPlacement` | Type : `"right" | "left"` Default value : `"right"`
Defined in src/radio/radio.component.ts:71

`name` | Default value : `""`
Defined in src/radio/radio.component.ts:67

`required` | Sets the HTML required attribute Default value : `false`
Defined in src/radio/radio.component.ts:86

`skeleton` | Set to `true` for a loading table. Default value : `false`
Defined in src/radio/radio.component.ts:94

`value` | The value of the `Radio`. Default value : `""`
Defined in src/radio/radio.component.ts:90

### Outputs

`change` | emits when the state of the radio changes `$event` Type: `EventEmitter`
Defined in src/radio/radio.component.ts:102

### HostBindings

attr.role
`attr.role: ```
Default value : `"radio"`
Defined in src/radio/radio.component.ts:106
Binds 'radio' value to the role attribute for `Radio`.

class.bx--radio-button-wrapper
`class.bx--radio-button-wrapper: ```
Default value : `true`
Defined in src/radio/radio.component.ts:108

class.bx--radio-button-wrapper--label-left
`class.bx--radio-button-wrapper--label-left: ```
Defined in src/radio/radio.component.ts:110

### Methods

onChange
`onChange(event: Event)`
Defined in src/radio/radio.component.ts:125
Synchronizes with the `RadioGroup` in the event of a changed `Radio`. Emits the changes of both the `RadioGroup` and `Radio`. Parameters :
Name | Type | Optional
event | `Event` | No
Returns : `void`

registerRadioChangeHandler
`registerRadioChangeHandler(fn: (event: RadioChange) => void)`
Defined in src/radio/radio.component.ts:137
Method called by `RadioGroup` with a callback function to bubble `RadioChange` events Parameters :
Name | Type | Optional | Description
fn | `function` | No | `callback that expects a `RadioChange` as an argument`
Returns : `void`

### Properties

Protected _labelledby
`_labelledby: `string``
Type : `string`
Default value : `""`
Defined in src/radio/radio.component.ts:114

radioChangeHandler
`radioChangeHandler: ```
Default value : `(event: RadioChange) => {}`
Defined in src/radio/radio.component.ts:119
Handler provided by the `RadioGroup` to bubble events up

Static radioCount
`radioCount: `number``
Type : `number`
Default value : `0`
Defined in src/radio/radio.component.ts:63
Used to dynamically create unique ids for the `Radio`.

### Accessors

ariaLabelledby
get `ariaLabelledby()`
Defined in src/radio/radio.component.ts:77
set `ariaLabelledby(value: string)`
Defined in src/radio/radio.component.ts:73
Parameters :
Name | Type | Optional
value | `string` | No
Returns : `void`

    import {
    	Component,
    	Input,
    	HostBinding,
    	Output,
    	EventEmitter
    } from "@angular/core";
    import { NG_VALUE_ACCESSOR } from "@angular/forms";
    import { RadioChange } from "./radio-change.class";

    /**
     * class: Radio (extends Checkbox)
     *
     * selector: `n-radio`
     *
     * source: `src/forms/radio.component.ts`
     *
     * ```html
     * <ibm-radio [(ngModel)]="radioState">Radio</ibm-radio>
     * ```
     *
     * Also see: [`RadioGroup`](#ibm-radio-group)
     */
    @Component({
    	selector: "ibm-radio",
    	template: `
    		<input
    			*ngIf="!skeleton"
    			class="bx--radio-button"
    			type="radio"
    			[checked]="checked"
    			[disabled]="disabled"
    			[name]="name"
    			[id]="id"
    			[required]="required"
    			[value]="value"
    			[attr.aria-labelledby]="ariaLabelledby"
    			(change)="onChange($event)">
    		<div *ngIf="skeleton" class="bx--radio-button bx--skeleton"></div>
    		<label
    			class="bx--radio-button__label"
    			[ngClass]="{
    				'bx--skeleton': skeleton
    			}"
    			[for]="id"
    			id="label-{{id}}">
    			<span class="bx--radio-button__appearance"></span>
    			<ng-content></ng-content>
    		</label>
    	`,
    	providers: [
    		{
    			provide: NG_VALUE_ACCESSOR,
    			useExisting: Radio,
    			multi: true
    		}
    	]
    })
    export class Radio {
    	/**
    	 * Used to dynamically create unique ids for the `Radio`.
    	 */
    	static radioCount = 0;

    	@Input() checked = false;

    	@Input() name = "";

    	@Input() disabled = false;

    	@Input() labelPlacement: "right" | "left" =  "right";

    	@Input() set ariaLabelledby(value: string) {
    		this._labelledby = value;
    	}

    	get ariaLabelledby() {
    		if (this._labelledby) {
    			return this._labelledby;
    		}
    		return `label-${this.id}`;
    	}
    	/**
    	 * Sets the HTML required attribute
    	 */
    	@Input() required = false;
    	/**
    	 * The value of the `Radio`.
    	 */
    	@Input() value = "";
    	/**
    	 * Set to `true` for a loading table.
    	 */
    	@Input() skeleton = false;
    	/**
    	 * The id for the `Radio`.
    	 */
    	@Input() id = `radio-${Radio.radioCount++}`;
    	/**
    	 * emits when the state of the radio changes
    	 */
    	@Output() change = new EventEmitter<RadioChange>();
    	/**
    	 * Binds 'radio' value to the role attribute for `Radio`.
    	 */
    	@HostBinding("attr.role") role = "radio";

    	@HostBinding("class.bx--radio-button-wrapper") hostClass = true;

    	@HostBinding("class.bx--radio-button-wrapper--label-left") get labelLeft() {
    		return this.labelPlacement === "left";
    	}

    	protected _labelledby = "";

    	/**
    	 * Handler provided by the `RadioGroup` to bubble events up
    	 */
    	radioChangeHandler = (event: RadioChange) => {};

    	/**
    	 * Synchronizes with the `RadioGroup` in the event of a changed `Radio`.
    	 * Emits the changes of both the `RadioGroup` and `Radio`.
    	 */
    	onChange(event: Event) {
    		event.stopPropagation();
    		this.checked = (event.target as HTMLInputElement).checked;
    		const radioEvent = new RadioChange(this, this.value);
    		this.change.emit(radioEvent);
    		this.radioChangeHandler(radioEvent);
    	}

    	/**
    	 * Method called by `RadioGroup` with a callback function to bubble `RadioChange` events
    	 * @param fn callback that expects a `RadioChange` as an argument
    	 */
    	registerRadioChangeHandler(fn: (event: RadioChange) => void) {
    		this.radioChangeHandler = fn;
    	}
    }

Legend
Html element
Component
Html element with directive

# result-matching ""

# No results matching ""