import { KbqRadioModule } from '@koobiq/components/radio';

KbqRadioButton

componentCopy link to KbqRadioButton
@Component({ selector: 'kbq-radio-button', exportAs: 'kbqRadioButton' })
class KbqRadioButton extends KbqColorDirective {
checked = input<boolean | undefined>();
value = input<NonNullable<unknown> | null | undefined>();
disabled = input<boolean | undefined>();
required = input<boolean | undefined>();
labelPosition = input<'before' | 'after' | undefined>();
name = input<string | undefined>();
readonly id = input<string>(this.uniqueId);
readonly color = input<T | null | undefined>();
readonly change = output<KbqRadioChange>();
readonly inputElement: Signal<ElementRef<HTMLInputElement>>;
radioGroup: KbqRadioGroup | null;
readonly inputId: Signal<string>;
get colorClassName(): string;
focus(origin?: FocusOrigin): void;
markForCheck(): void;
onInputClick(event: Event): void;
onInputChange(event: Event): void;
setDefaultColor(color: T): void;
}
checkedinputCopy link to checkedboolean | undefined

Whether this radio button is checked.

valueinputCopy link to valueNonNullable<unknown> | null | undefined

The value of this radio button.

disabledinputCopy link to disabledboolean | undefined

Whether the radio button is disabled. A button inside a disabled group is disabled as well.

requiredinputCopy link to requiredboolean | undefined

Whether the radio button is required. A button inside a required group is required as well.

labelPositioninputCopy link to labelPosition'before' | 'after' | undefined

Whether the label should appear after or before the radio button. Defaults to 'after'

nameinputCopy link to namestring | undefined

Analog to HTML 'name' attribute used to group radios for unique selection. Defaults to the parent group's name, or — outside a group — to an id unique to this button.

idinputCopy link to idstring

A unique id for the radio button. If none is supplied — or null is bound explicitly — it is auto-generated, so a read always yields the id the element actually carries.

colorinputCopy link to colorT | null | undefined

Color of the component. A value set in code holds until the input changes, and the default color is used while both are unset or falsy.

changeoutputCopy link to changeKbqRadioChange

Event emitted when the checked state of this radio button changes. Change events are only emitted when the value changes due to user interaction with the radio button (the same behavior as <input type-"radio">).

inputElementCopy link to inputElementSignal<ElementRef<HTMLInputElement>>

The native <input type=radio> element

radioGroupCopy link to radioGroupKbqRadioGroup | null

The parent radio group. null when the button is used outside one.

inputIdCopy link to inputIdSignal<string>

ID of the native input element inside <kbq-radio-button>

colorClassNameCopy link to colorClassNamestring

current class name of color

focus()Copy link to focus()void

Focuses the radio button.

Routed through the FocusMonitor so the origin is recorded: the focus ring is keyed off .cdk-keyboard-focused, which a bare element.focus() never produces.

markForCheck()Copy link to markForCheck()void

Marks the radio button as needing checking for change detection.

Kept for back-compatibility. A button derives its state from signals, its own and its group's, so it re-renders on its own and nothing in the library calls this any more.

setDefaultColor()Copy link to setDefaultColor()void

this color will be used as a default value. For example [color]="'' | false | undefined | null".

KbqRadioGroup

componentCopy link to KbqRadioGroup

Selection group for KbqRadioButton.

The host is a radiogroup, which is not a name-from-content role, so it reaches assistive technology unnamed unless the consumer names it. Name it with a plain aria-label / aria-labelledby attribute pointing at the visible group label: the host is the very element the consumer writes, so an input aliased to the same name would only write back what is already there — and would wipe an [attr.aria-label] binding, which never reaches the input.

To show a validation error, bind the group to a form control and put the error text in a kbq-error inside the group. A kbq-hint put inside the group is shown under the options, below the error.

@Component({ selector: 'kbq-radio-group', exportAs: 'kbqRadioGroup' })
class KbqRadioGroup extends KbqColorDirective implements ControlValueAccessor, CanUpdateErrorState {
readonly errorStateMatcher = input<ErrorStateMatcher>();
readonly big = input<boolean>(false);
readonly name = input<string>(
inject(_IdGenerator).getId('kbq-radio-group-')
);
readonly labelPosition = input<'before' | 'after'>('after');
value = input<NonNullable<unknown> | null | undefined>();
selected = input<KbqRadioButton | null | undefined>();
disabled = input<boolean | undefined>();
readonly required = input<boolean>(false);
readonly color = input<T | null | undefined>();
readonly change = output<KbqRadioChange>();
readonly errorState: Signal<boolean>;
get radios(): QueryList<KbqRadioButton>;
get colorClassName(): string;
checkSelectedRadioButton(): void;
updateErrorState(): void;
focus(origin?: FocusOrigin): void;
touch(): void;
emitChangeEvent(): void;
markRadiosForCheck(): void;
setDefaultColor(color: T): void;
}
errorStateMatcherinputCopy link to errorStateMatcherErrorStateMatcher

An object used to control when the error state is shown.

nameinputCopy link to namestring

Name of the radio button group. All radio buttons inside this group will use this name, unless they were given one of their own.

labelPositioninputCopy link to labelPosition'before' | 'after'

Whether the labels should appear after or before the radio-buttons. Defaults to 'after'

valueinputCopy link to valueNonNullable<unknown> | null | undefined

Value of the radio button.

selectedinputCopy link to selectedKbqRadioButton | null | undefined

Whether the radio button is selected.

disabledinputCopy link to disabledboolean | undefined

Whether the radio group is disabled

requiredinputCopy link to requiredboolean

Whether the radio group is required

colorinputCopy link to colorT | null | undefined

Color of the component. A value set in code holds until the input changes, and the default color is used while both are unset or falsy.

changeoutputCopy link to changeKbqRadioChange

Event emitted when the group value changes. Change events are only emitted when the value changes due to user interaction with a radio button (the same behavior as <input type-"radio">).

errorStateCopy link to errorStateSignal<boolean>

Whether the radio group is in an error state.

radiosCopy link to radiosQueryList<KbqRadioButton>

Child radio buttons.

colorClassNameCopy link to colorClassNamestring

current class name of color

updateErrorState()Copy link to updateErrorState()void

Updates the error state based on the error state matcher.

focus()Copy link to focus()void

Moves focus to the checked radio button, or to the first enabled one when nothing is checked — the same rule the browser follows when the group is reached with Tab.

touch()Copy link to touch()void

Mark this group as being "touched" (for ngModel). Meant to be called by the contained radio buttons upon their blur.

emitChangeEvent()Copy link to emitChangeEvent()void

Dispatch change event with current selection and group value.

markRadiosForCheck()Copy link to markRadiosForCheck()void

Marks every radio button of the group for a change-detection check.

Kept for back-compatibility. A button derives checked and disabled from signals, its own and its group's, so it re-renders on its own and nothing in the library calls this any more.

setDefaultColor()Copy link to setDefaultColor()void

this color will be used as a default value. For example [color]="'' | false | undefined | null".

KbqRadioChange

classCopy link to KbqRadioChange

Change event object emitted by KbqRadio.

class KbqRadioChange {
source: KbqRadioButton;
value: any;
constructor(source: KbqRadioButton, value: any);
}
sourceCopy link to sourceKbqRadioButton

The KbqRadioButton that emits the change event.

valueCopy link to valueany

The value of the KbqRadioButton.

constructor()Copy link to constructor()
Parameters
sourceKbqRadioButton

The KbqRadioButton that emits the change event.

valueany

The value of the KbqRadioButton.

Suggestions for improvement
If you found a mistake or want to improve the article, create an issue on GitHub.