Skip to content

Commit

Permalink
Handle label reactively for dropdown item
Browse files Browse the repository at this point in the history
  • Loading branch information
AronssonFredrik committed Dec 10, 2020
1 parent b85bdde commit 8e67588
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Component, Input, EventEmitter, Output, ViewChild, ElementRef, AfterViewInit } from '@angular/core';
import { Component, Input, EventEmitter, Output, ViewChild, ElementRef } from '@angular/core';

@Component({
selector: 'vgr-dropdown-item',
templateUrl: './dropdown-item.component.html'
})
export class DropdownItemComponent implements AfterViewInit {
export class DropdownItemComponent {

@Input() selectedLabel: string;
@Input() value: any;
Expand All @@ -14,19 +14,16 @@ export class DropdownItemComponent implements AfterViewInit {
@Output() next = new EventEmitter();
@Output() nextMatch = new EventEmitter<string>();
@ViewChild('item') item: ElementRef;
label: string;

get label(): string {
return this.value;
};

multi = false;
selected = false;
visible = true;
hasFocus = false;

ngAfterViewInit() {
this.label = (this.item.nativeElement as Node).textContent.trim();
if (this.value === undefined) {
this.value = this.label;
}
}

toggleSelect() {
if (this.multi) {
this.selected = !this.selected;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import {
Component, AfterViewChecked, QueryList, forwardRef, ElementRef, ContentChildren, Renderer2, OnDestroy, Output, EventEmitter
} from '@angular/core';
Expand Down

0 comments on commit 8e67588

Please sign in to comment.