GitHub

Select

Usage

Components

import { DaffSelectComponent } from '@daffodil/design/select'

DaffSelectComponent is a form control component that presents a list of selectable options, similar to the native <select> element we call <daff-native-select>.

@Component()
class DaffSelectComponent<<T = unknown>>  extends DaffFormFieldControl<string> implements DaffFormFieldControl<string>, OnInit, OnDestroy, ControlValueAccessor {
  @Optional() @Self() ngControl: NgControl

  @Input() options: T[] = []
  @Input() optionsId: string = 'daff-select-options' + '-' + ++daffSelectOtionsId

  open(event?: MouseEvent | KeyboardEvent): void
  close(event?: MouseEvent | KeyboardEvent): void
  selectOption(option: T): void
  selectHighlighted(event?: MouseEvent | KeyboardEvent): void
  highlightNext(event?: MouseEvent | KeyboardEvent): void
  highlightPrevious(event?: MouseEvent | KeyboardEvent): void
}

Inputs

options
T[]
Default[]
Description
optionsId
string
Default'daff-select-options' + '-' + ++daffSelectOtionsId
Description

The unique id of the select options. Defaults to an autogenerated value.

() Methods

open
void

Opens the options list.

Parameters
Parameterevent: MouseEvent | KeyboardEvent
Description
close
void

Closes the options list.

Parameters
Parameterevent: MouseEvent | KeyboardEvent
Description
selectOption
void

Selects an option.

Parameters
Parameteroption: T
Description
selectHighlighted
void

Selects the option referenced by the highlighted index.

Parameters
Parameterevent: MouseEvent | KeyboardEvent
Description
highlightNext
void

Highlights the next option in the list.

Parameters
Parameterevent: MouseEvent | KeyboardEvent
Description
highlightPrevious
void

Highlights the previous option in the list.

Parameters
Parameterevent: MouseEvent | KeyboardEvent
Description

Directives

import { DaffSelectOptionDirective } from '@daffodil/design/select'

The directive provides the template for a list of options inside the select dropdown.

@Directive()
class DaffSelectOptionDirective {
  @Optional() templateRef: TemplateRef<unknown>
}

Types

import { DaffSelectOptionDirectiveContext } from '@daffodil/design/select'

The slot context for DaffSelectOptionDirective.

interface DaffSelectOptionDirectiveContext<T = unknown> {
  option: T
  isSelected: boolean
  isHighlighted: boolean
}

Properties

option
T

The option for this element in the list.

isSelected
boolean

Whether this option is the currently selected one.

isHighlighted
boolean

Whether this option is the currently highlighted one in the options list.


Constants

import { DAFF_SELECT_COMPONENTS } from '@daffodil/design/select'