Skip to content

Commit a539749

Browse files
committed
added ref changed output to dropdown
1 parent 40937eb commit a539749

4 files changed

Lines changed: 18 additions & 7 deletions

File tree

ui/src/app/components/options/options.component.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@
5959
[noItemsPlaceholder]="option.noItemsPlaceholder"
6060
(itemSelected)="option.itemSelected($event)"
6161
[forceDirection]="option.forceDirection"
62+
[closeOnSelect]="option.closeOnSelect"
63+
(refChanged)="option.refChanged && option.refChanged($event)"
6264
></eqm-dropdown>
6365
</div>
6466

ui/src/app/components/options/options.component.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Component, Input, Output, EventEmitter, ChangeDetectorRef } from '@angular/core'
2+
import { DropdownComponent } from '../../modules/eqmac-components/components/dropdown/dropdown.component'
23
import { ApplicationService } from '../../services/app.service'
34

45
interface BaseOptions {
@@ -39,6 +40,8 @@ export interface DropdownOption extends Omit<BaseOptions, 'label'> {
3940
placeholder?: string
4041
noItemsPlaceholder?: string
4142
forceDirection?: 'up' | 'down'
43+
closeOnSelect?: boolean
44+
refChanged?: (ref: DropdownComponent) => void
4245
itemSelected: (item: any) => void | Promise<void>
4346
}
4447

ui/src/app/modules/eqmac-components/components/dropdown/dropdown.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
</div>
88

99
<div class="arrows" (click)="editable ? toggle($event) : undefined">
10-
<eqm-icon [name]="'triangle'" [height]="8" [width]="8" [color]="hasSelection ? '#4f8d71' : '#555'" rotate="-90">
10+
<eqm-icon [name]="'triangle'" [height]="8" [width]="8" [color]="items.length ? '#4f8d71' : '#555'" rotate="-90">
1111
</eqm-icon>
12-
<eqm-icon [name]="'triangle'" [height]="8" [width]="8" [color]="hasSelection ? '#4f8d71' : '#555'" rotate="90">
12+
<eqm-icon [name]="'triangle'" [height]="8" [width]="8" [color]="items.length ? '#4f8d71' : '#555'" rotate="90">
1313
</eqm-icon>
1414
</div>
1515
</eqm-container>

ui/src/app/modules/eqmac-components/components/dropdown/dropdown.component.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@ import { FadeInOutAnimation } from 'src/app/modules/animations'
1111
animations: [ FadeInOutAnimation ]
1212
})
1313
export 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

Comments
 (0)