GitHub

DaffSwitchComponent

import { DaffSwitchComponent } from '@daffodil/design/switch'

The switch component provides a way to toggle between two settings.

<daff-switch>
 Label
</daff-switch>
@Component()
class DaffSwitchComponent {
  @Input() @HostBinding() disabled: any
  @Input() @HostBinding() loading: boolean = false
  @Input() checked: boolean = false
  @Input() labelPosition: DaffLabelPosition = DaffLabelPositionEnum.LEFT
  @Input() error: boolean = false
  @Input() ariaLabel: string = ''
  @Input() id: string = 'daff-switch-' + switchUniqueId++

  @Output() toggled: EventEmitter<boolean> = new EventEmitter<boolean>()

  @HostListener() handleKeydown(event: KeyboardEvent): void
}

() Methods

handleKeydown
void
Parameters
Parameterevent: KeyboardEvent
Description

Inputs

disabled
any
Default
Description

Whether the switch is disabled and/or loading.

loading
boolean
Defaultfalse
Description

Whether the switch is loading.

checked
boolean
Defaultfalse
Description

Current state of switch (on/off).

labelPosition
DaffLabelPosition
DefaultDaffLabelPositionEnum.LEFT
Description

The position of the label relative to the switch.

error
boolean
Defaultfalse
Description

Whether the switch shows an error.

ariaLabel
string
Default''
Description

aria-label for the switch.

id
string
Default'daff-switch-' + switchUniqueId++
Description

A unique id for the switch.

The id is automatically generated by linking the prefix 'daff-switch-' with an incrementing number. This value can be customized by passing a different id value via the component's id input.

Outputs

toggled
EventEmitter<boolean>
Default
Description

Output event triggered when the switch has been toggled.