Skip to content

Commit

Permalink
Exposed dropdown directive from dropdown treeview component
Browse files Browse the repository at this point in the history
  • Loading branch information
FrenchFriesFiesta committed Sep 21, 2024
1 parent 7fd36e3 commit 6498f0a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {TreeviewConfig} from '../../models/treeview-config';
import {TreeviewComponent} from '../treeview/treeview.component';
import {TreeviewHeaderTemplateContext} from '../../models/treeview-header-template-context';
import {TreeviewItemTemplateContext} from '../../models/treeview-item-template-context';
import {DropdownDirective} from '../../directives/dropdown.directive';

@Component({
selector: 'ngx-dropdown-treeview',
Expand All @@ -20,6 +21,7 @@ export class DropdownTreeviewComponent {
@Output() selectedChange = new EventEmitter<any[]>(true);
@Output() filterChange = new EventEmitter<string>();
@ViewChild(TreeviewComponent, { static: false }) treeviewComponent: TreeviewComponent;
@ViewChild(DropdownDirective, { static: false }) dropdownDirective: DropdownDirective;
buttonLabel: string;

constructor(
Expand Down
9 changes: 7 additions & 2 deletions src/app/book/book.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,19 @@ <h3>Components (
<input class="form-check-input" type="checkbox" [(ngModel)]="dropdownEnabled"> Enable/disable
</label>
</div>
<div>
<label class="form-check-label">
<input class="form-check-input" type="checkbox" [(ngModel)]="closeOnSelection"> Close dropdown on selection
</label>
</div>
<div class="form-group form-inline">
<label>buttonClass</label>
<select class="form-control mx-sm-3" [(ngModel)]="buttonClass">
<option *ngFor="let c of buttonClasses" [value]="c">{{c}}</option>
</select>
</div>
<ngx-dropdown-treeview [config]="config" [items]="items" [buttonClass]="buttonClass"
(selectedChange)="values = $event" [disabled]="!dropdownEnabled"
<ngx-dropdown-treeview #dropdownTreeview [config]="config" [items]="items" [buttonClass]="buttonClass"
(selectedChange)="onSelectedChange($event)" [disabled]="!dropdownEnabled"
[ngxDisabledOnSelector]="'button.dropdown-toggle'" (filterChange)="onFilterChange($event)">
</ngx-dropdown-treeview>
</div>
Expand Down
14 changes: 12 additions & 2 deletions src/app/book/book.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Component, OnInit} from '@angular/core';
import {TreeviewConfig, TreeviewItem} from 'ngx-treeview2';
import {Component, OnInit, ViewChild} from '@angular/core';
import {DropdownTreeviewComponent, TreeviewConfig, TreeviewItem} from 'ngx-treeview2';
import {BookService} from './book.service';

@Component({
Expand Down Expand Up @@ -33,6 +33,9 @@ export class BookComponent implements OnInit {
];
buttonClass = this.buttonClasses[0];

@ViewChild('dropdownTreeview') dropdownTreeview: DropdownTreeviewComponent;
closeOnSelection = false;

constructor(
private service: BookService
) { }
Expand All @@ -44,4 +47,11 @@ export class BookComponent implements OnInit {
onFilterChange(value: string): void {
console.log('filter:', value);
}

onSelectedChange(event: any[]) {
this.values = event;
if (this.closeOnSelection) {
this.dropdownTreeview.dropdownDirective.close();
}
}
}

0 comments on commit 6498f0a

Please sign in to comment.