@progress/kendo-angular-treeview
Version:
Kendo UI TreeView for Angular
84 lines (83 loc) • 3.33 kB
JavaScript
/**-----------------------------------------------------------------------------------------
* Copyright © 2025 Progress Software Corporation. All rights reserved.
* Licensed under commercial license. See LICENSE.md in the project root for more information
*-------------------------------------------------------------------------------------------*/
import { ChangeDetectorRef, Directive, Input } from '@angular/core';
import { TreeViewComponent } from './treeview.component';
import * as i0 from "@angular/core";
import * as i1 from "./treeview.component";
/**
* Represents a directive which manages the disabled in-memory state of the TreeView node
* ([see example]({% slug disabledstate_treeview %})).
*
* @example
* ```html
* <kendo-treeview
* [nodes]="data"
* textField="text"
* [hasChildren]="hasChildren"
* [children]="fetchChildren"
* kendoTreeViewDisable
* [disabledKeys]="disabledKeys">
* </kendo-treeview>
* ```
*
* @remarks
* Applied to: {@link TreeViewComponent}
*/
export class DisableDirective {
treeView;
cdr;
/**
* @hidden
*/
set isDisabled(value) {
this.treeView.isDisabled = value;
}
/**
* Defines the item key that will be stored in the `disabledKeys` collection.
*/
disableKey;
/**
* Defines the collection that will store the disabled keys.
*/
disabledKeys = [];
constructor(treeView, cdr) {
this.treeView = treeView;
this.cdr = cdr;
this.treeView.isDisabled = (dataItem, index) => (this.disabledKeys.indexOf(this.itemKey({ dataItem, index })) > -1);
}
ngOnChanges(changes = {}) {
const { disabledKeys } = changes;
if (disabledKeys && !disabledKeys.firstChange) {
this.cdr.markForCheck();
}
}
itemKey(e) {
if (!this.disableKey) {
return e.index;
}
if (typeof this.disableKey === "string") {
return e.dataItem[this.disableKey];
}
if (typeof this.disableKey === "function") {
return this.disableKey(e);
}
}
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: DisableDirective, deps: [{ token: i1.TreeViewComponent }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Directive });
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "18.2.14", type: DisableDirective, isStandalone: true, selector: "[kendoTreeViewDisable]", inputs: { isDisabled: "isDisabled", disableKey: ["kendoTreeViewDisable", "disableKey"], disabledKeys: "disabledKeys" }, usesOnChanges: true, ngImport: i0 });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: DisableDirective, decorators: [{
type: Directive,
args: [{
selector: '[kendoTreeViewDisable]',
standalone: true
}]
}], ctorParameters: () => [{ type: i1.TreeViewComponent }, { type: i0.ChangeDetectorRef }], propDecorators: { isDisabled: [{
type: Input
}], disableKey: [{
type: Input,
args: ["kendoTreeViewDisable"]
}], disabledKeys: [{
type: Input
}] } });