File

projects/ui-kit-lib/src/lib/v2/switch/switch.component.ts

Extends

BaseEditableHolder

Implements

OnInit OnDestroy ControlValueAccessor

Metadata

Index

Properties
Methods
Inputs
Outputs
HostListeners

Constructor

constructor()

Inputs

id
Type : string

Host element id. Can be overridden by the consumer.

readonly
Type : boolean | undefined

Read-only mode: prevents user interaction while still allowing focus.

tabindex
Type : number | undefined

Keyboard tab order for the internal input.

disabled
Default value : undefined, { transform: booleanAttribute }

Disabled input as a signal (explicit/external).

invalid
Default value : undefined, { transform: booleanAttribute }

Optional "invalid" flag as a signalized input (used for UI state).

name
Type : string | undefined

Optional control name (useful for forms & a11y attributes).

required
Default value : undefined, { transform: booleanAttribute }

Optional "required" flag as a signalized input.

Outputs

onChange
Type : EventEmitter<ToggleSwitchChangeEvent>

Emits when the user toggles the switch via UI interaction.

Example :
<md-switch (onChange)="handleChange($event)"></md-switch>

HostListeners

click
Arguments : '$event'
click(event: MouseEvent)

Host click handler.

Parameters :
Name Optional Description
event No

Browser MouseEvent.

Methods

_handleClick
_handleClick(event: Event)

Centralized click logic:

  • toggles the model via BaseEditableHolder;
  • calls onModelChange() for the form;
  • emits onChange with details;
  • returns focus to the input for accessible keyboard flow.
Parameters :
Name Type Optional Description
event Event No

Original browser Event.

Returns : void
checked
checked()

Convenience getter for host class binding.

Returns : any

Current checked state.

onBlur
onBlur()

Focus-out handler (called from the template).

Returns : void
onFocus
onFocus()

Focus-in handler (called from the template).

Returns : void
onHostClick
onHostClick(event: MouseEvent)
Decorators :
@HostListener('click', ['$event'])

Host click handler.

Parameters :
Name Type Optional Description
event MouseEvent No

Browser MouseEvent.

Returns : void
validate
validate()

Synchronous validator hook (provided via NG_VALIDATORS).

Returns : void
writeControlValue
writeControlValue(value: any, setModelValue: (value: any) => void)

ControlValueAccessor: write an external value into the component.

Parameters :
Name Type Optional Description
value any No

Value coming from the form model.

setModelValue function No

Callback to update the base class model value.

Returns : void
registerOnChange
registerOnChange(fn: Function)

CVA: registers the callback to propagate value changes to Angular Forms.

Parameters :
Name Type Optional Description
fn Function No

Callback invoked when the control's value changes.

Returns : void
registerOnTouched
registerOnTouched(fn: Function)

CVA: registers the callback to mark the control as touched.

Parameters :
Name Type Optional Description
fn Function No

Callback invoked when the control is touched.

Returns : void
setDisabledState
setDisabledState(val: boolean)

CVA: enables/disables the control from the Forms API.

Parameters :
Name Type Optional Description
val boolean No

true to disable, false to enable.

Returns : void
writeDisabledState
writeDisabledState(value: boolean)

Programmatically set the internal disabled state (used by setDisabledState).

Parameters :
Name Type Optional Description
value boolean No

New disabled state.

Returns : void
writeModelValue
writeModelValue(value: any)

Updates the internal value signal (modelValue) from the component itself (e.g., on user input). This does not notify the Forms API by itself. Invoke onModelChange after this to propagate when appropriate.

Parameters :
Name Type Optional Description
value any No

New internal value to set.

Returns : void
writeValue
writeValue(value: any)

CVA: writes an external value into the control. Delegates to writeControlValue so children can customize behavior.

Parameters :
Name Type Optional Description
value any No

Value coming from the Angular Forms model.

Returns : void

Properties

focused
Type : boolean
Default value : false

Focus ring helper for template/styles.

input
Type : ElementRef
Decorators :
@ViewChild('input')

Template reference to the internal input element (for focus management).

_disabled
Type : unknown
Default value : signal<boolean>(false)

Internal disabled state set via CVA's setDisabledState.

$disabled
Type : unknown
Default value : computed(() => { return this.disabled() || this._disabled(); })

Effective disabled state: true if either the input disabled() is truthy OR setDisabledState(true) was called.

cd
Type : unknown
Default value : inject(ChangeDetectorRef)

Change detector used by children to mark for check after updates.

modelValue
Type : unknown
Default value : signal<string | string[] | any | undefined>(undefined)

Reactive internal value for the control (Signal).

onModelChange
Type : Function
Default value : () => {...}

CVA onChange callback (assigned by Angular Forms).

onModelTouched
Type : Function
Default value : () => {...}

CVA onTouched callback (assigned by Angular Forms).

results matching ""

    No results matching ""