packages/components/eui-input-radio/eui-input-radio.component.ts
Radio input component for selecting a single value from a set of mutually exclusive options. Integrates with Angular forms (both reactive and template-driven) and provides custom EUI styling. Implements ControlValueAccessor for seamless form integration with validation states and error handling. Automatically manages checked state, value binding, and form control synchronization. Must be applied as an attribute directive to native HTML radio input elements.
<!-- Template-driven forms -->
<div>
<input euiInputRadio type="radio" name="size" value="small" [(ngModel)]="selectedSize" id="size-small" />
<label for="size-small">Small</label>
</div>
<div>
<input euiInputRadio type="radio" name="size" value="medium" [(ngModel)]="selectedSize" id="size-medium" />
<label for="size-medium">Medium</label>
</div>
<div>
<input euiInputRadio type="radio" name="size" value="large" [(ngModel)]="selectedSize" id="size-large" />
<label for="size-large">Large</label>
</div><form [formGroup]="myForm">
<div>
<input euiInputRadio type="radio" formControlName="plan" value="basic" id="plan-basic" />
<label for="plan-basic">Basic Plan</label>
</div>
<div>
<input euiInputRadio type="radio" formControlName="plan" value="premium" id="plan-premium" />
<label for="plan-premium">Premium Plan</label>
</div>
</form>myForm = this.fb.group({
plan: ['basic', Validators.required]
});<form [formGroup]="form">
<div>
<input euiInputRadio type="radio" formControlName="option" value="yes" id="opt-yes" />
<label for="opt-yes">Yes</label>
</div>
<div>
<input euiInputRadio type="radio" formControlName="option" value="no" id="opt-no" />
<label for="opt-no">No</label>
</div>
<div *ngIf="form.get('option')?.invalid && form.get('option')?.touched" class="error">
Please select an option
</div>
</form><input euiInputRadio type="radio" name="status" value="active" [disabled]="true" id="status-active" />
<label for="status-active">Active (disabled)</label><input euiInputRadio type="radio" name="option" value="1" [(ngModel)]="selected" id="opt-1" />
<label for="opt-1">Option 1</label>
OnInit
DoCheck
OnChanges
ControlValueAccessor
| selector | input[euiInputRadio] |
| styleUrls | ./eui-input-radio.scss |
Methods |
Inputs |
HostBindings |
HostListeners |
Accessors |
constructor()
|
| checked |
Type : any
|
|
Gets or sets the default checked state of the radio input. This is different from the current checked state and represents the initial value. |
| isInvalid |
Type : boolean
|
|
Gets or sets whether the radio input is in an invalid state. This can be set manually or will be automatically set when used with form validation. |
| value |
Type : any
|
|
Gets or sets the value of the radio input. The value can be of any type and will be used when the radio is selected in a form group. |
| disabled |
Type : boolean
|
| euiDanger |
Type : boolean
|
Default value : false
|
| euiDisabled |
Type : boolean
|
Default value : false
|
| placeholder |
Type : string | null
|
| readonly |
Type : any
|
| attr.type |
Type : string
|
Default value : 'radio'
|
| class |
Type : string
|
|
Gets the CSS classes for the radio input component. Combines base classes with invalid state modifier if applicable. |
| change | ||||||
Arguments : '$any($event)'
|
||||||
change(event: Event)
|
||||||
|
Handles change events on the radio input. Updates the model value when the radio selection changes.
Parameters :
|
| registerOnChange | ||||||||
registerOnChange(fn: any)
|
||||||||
|
Registers a callback function that is called when the control's value changes.
Parameters :
Returns :
void
|
| registerOnTouched | ||||||||
registerOnTouched(fn: any)
|
||||||||
|
Registers a callback function that is called when the control is touched.
Parameters :
Returns :
void
|
| Optional setDisabledState | ||||||||
setDisabledState(isDisabled: boolean)
|
||||||||
|
Sets the disabled state of the radio input.
Parameters :
Returns :
void
|
| writeValue | ||||||||
writeValue(obj: string)
|
||||||||
|
Implements ControlValueAccessor.writeValue. Updates the checked state based on the form control value.
Parameters :
Returns :
void
|
| getCssClasses | ||||||
getCssClasses(rootClass: string)
|
||||||
|
Parameters :
Returns :
string
|
| isInvalid | ||||||
getisInvalid()
|
||||||
|
Gets or sets whether the radio input is in an invalid state. This can be set manually or will be automatically set when used with form validation.
Returns :
boolean
|
||||||
setisInvalid(state: BooleanInput)
|
||||||
|
Parameters :
Returns :
void
|
| class |
getclass()
|
|
Gets the CSS classes for the radio input component. Combines base classes with invalid state modifier if applicable.
Returns :
string
|
| defaultChecked | ||||||
getdefaultChecked()
|
||||||
|
Gets or sets the default checked state of the radio input. This is different from the current checked state and represents the initial value.
Returns :
any
|
||||||
setdefaultChecked(value: BooleanInput)
|
||||||
|
Parameters :
Returns :
void
|
| selected |
getselected()
|
|
Gets whether the radio input is currently selected.
Returns :
boolean
|
| value | ||||||
getvalue()
|
||||||
|
Gets or sets the value of the radio input. The value can be of any type and will be used when the radio is selected in a form group.
Returns :
any
|
||||||
setvalue(value: unknown)
|
||||||
|
Parameters :
Returns :
void
|