@@ -11,11 +11,14 @@ import { FadeInOutAnimation } from 'src/app/modules/animations'
1111 animations : [ FadeInOutAnimation ]
1212} )
1313export class DropdownComponent implements OnInit {
14- constructor ( public utils : UtilitiesService , public zone : NgZone ) {
14+ constructor (
15+ public utils : UtilitiesService ,
16+ public zone : NgZone ,
17+ public ref : ElementRef
18+ ) {
1519 }
1620
1721 public _items : any [ ] = [ ]
18- hasSelection = false
1922 @Input ( ) editable = false
2023 @Input ( )
2124 get items ( ) {
@@ -24,15 +27,15 @@ export class DropdownComponent implements OnInit {
2427 set items ( newItems ) {
2528 if ( ! newItems || ! Array . isArray ( newItems ) ) return
2629 this . _items = newItems
27- const hasSelection = newItems . length > 1
28- this . zone . run ( ( ) => this . hasSelection = hasSelection )
2930 }
31+ @Output ( ) refChanged = new EventEmitter < DropdownComponent > ( )
3032 @HostBinding ( 'class.disabled' ) @Input ( ) disabled = false
3133 @Input ( ) selectedItem = null
3234 @Input ( ) labelParam = 'text'
3335 @Input ( ) numberOfVisibleItems = 6
3436 @Input ( ) placeholder = 'Select item'
3537 @Input ( ) noItemsPlaceholder = 'No items'
38+ @Input ( ) closeOnSelect = true
3639 @Output ( ) itemSelected = new EventEmitter ( )
3740
3841 @ViewChild ( 'container' , { read : ElementRef , static : true } ) container : ElementRef
@@ -53,6 +56,7 @@ export class DropdownComponent implements OnInit {
5356 await this . utils . delay ( 100 )
5457 this . calculateYCoordinate ( )
5558 }
59+ this . refChanged . emit ( this )
5660 }
5761
5862 setDimensions ( ) {
@@ -115,6 +119,8 @@ export class DropdownComponent implements OnInit {
115119 selectItem ( item ) {
116120 this . selectedItem = item
117121 this . itemSelected . emit ( item )
118- this . close ( )
122+ if ( this . closeOnSelect ) {
123+ this . close ( )
124+ }
119125 }
120126}
0 commit comments