|
|
@ -25,6 +25,9 @@ interface State { |
|
|
// The selected suggested index.
|
|
|
// The selected suggested index.
|
|
|
selectedIndex: number; |
|
|
selectedIndex: number; |
|
|
|
|
|
|
|
|
|
|
|
// The selected item.
|
|
|
|
|
|
selectedItem?: number; |
|
|
|
|
|
|
|
|
// The current search query.
|
|
|
// The current search query.
|
|
|
query?: RegExp; |
|
|
query?: RegExp; |
|
|
} |
|
|
} |
|
|
@ -66,14 +69,11 @@ export class DropdownComponent extends StatefulControlComponent<State, ReadonlyA |
|
|
|
|
|
|
|
|
public queryInput = new FormControl(); |
|
|
public queryInput = new FormControl(); |
|
|
|
|
|
|
|
|
public get selectedItem() { |
|
|
|
|
|
return this.items[this.snapshot.selectedIndex]; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
constructor(changeDetector: ChangeDetectorRef) { |
|
|
constructor(changeDetector: ChangeDetectorRef) { |
|
|
super(changeDetector, { |
|
|
super(changeDetector, { |
|
|
selectedIndex: -1, |
|
|
selectedIndex: -1, |
|
|
suggestedItems: [] |
|
|
selectedItem: undefined, |
|
|
|
|
|
suggestedItems: [], |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -202,7 +202,6 @@ export class DropdownComponent extends StatefulControlComponent<State, ReadonlyA |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public selectIndex(selectedIndex: number, fromUserAction: boolean) { |
|
|
public selectIndex(selectedIndex: number, fromUserAction: boolean) { |
|
|
if (fromUserAction) { |
|
|
|
|
|
const items = this.snapshot.suggestedItems || []; |
|
|
const items = this.snapshot.suggestedItems || []; |
|
|
|
|
|
|
|
|
if (selectedIndex < 0) { |
|
|
if (selectedIndex < 0) { |
|
|
@ -215,6 +214,7 @@ export class DropdownComponent extends StatefulControlComponent<State, ReadonlyA |
|
|
|
|
|
|
|
|
const selectedItem = items[selectedIndex]; |
|
|
const selectedItem = items[selectedIndex]; |
|
|
|
|
|
|
|
|
|
|
|
if (fromUserAction) { |
|
|
let selectedValue = selectedItem; |
|
|
let selectedValue = selectedItem; |
|
|
|
|
|
|
|
|
if (this.valueProperty && this.valueProperty.length > 0 && selectedValue) { |
|
|
if (this.valueProperty && this.valueProperty.length > 0 && selectedValue) { |
|
|
@ -229,7 +229,7 @@ export class DropdownComponent extends StatefulControlComponent<State, ReadonlyA |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
this.next({ selectedIndex }); |
|
|
this.next({ selectedIndex, selectedItem }); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private getSelectedIndex(value: any) { |
|
|
private getSelectedIndex(value: any) { |
|
|
|