-import { Component, forwardRef, Input } from '@angular/core'
+import { Component, forwardRef, HostListener, Input } from '@angular/core'
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'
-
-export type SelectOptionsItem = {
- id: string | number
- label: string
- description?: string
- group?: string
- groupLabel?: string
-}
+import { SelectOptionsItem } from '../../../../types/select-options-item.model'
@Component({
selector: 'my-select-options',
@Input() searchable = false
@Input() groupBy: string
@Input() labelForId: string
+ @Input() searchFn: any
selectedId: number | string
+ disabled = false
propagateChange = (_: any) => { /* empty */ }
+ // Allow plugins to update our value
+ @HostListener('change', [ '$event.target' ])
+ handleChange (event: any) {
+ this.writeValue(event.value)
+ this.onModelChange()
+ }
+
writeValue (id: number | string) {
this.selectedId = id
}
onModelChange () {
this.propagateChange(this.selectedId)
}
+
+ setDisabledState (isDisabled: boolean) {
+ this.disabled = isDisabled
+ }
}