@progress/kendo-angular-treelist
Version:
Kendo UI TreeList for Angular - Display hierarchical data in an Angular tree grid view that supports sorting, filtering, paging, and much more.
78 lines (77 loc) • 3.69 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 { Directive, ElementRef } from '@angular/core';
import { isDocumentAvailable } from '@progress/kendo-angular-common';
import { ContextService } from '../../common/provider.service';
import * as i0 from "@angular/core";
import * as i1 from "../../common/provider.service";
/**
* A directive for toolbar elements that need to be part of TreeList keyboard navigation.
* Use this directive to make toolbar elements focusable and accessible with the keyboard.
*
* @example
* ```html
* <kendo-treelist>
* <kendo-toolbar>
* <button kendoTreeListToolbarFocusable>Custom Button</button>
* <button kendoTreeListCancelCommand>Cancel</button>
* <button kendoTreeListEditCommand>Edit</button>
* </kendo-toolbar>
* </kendo-treelist>
* ```
*/
export class TreeListToolbarFocusableDirective {
host;
ctx;
/**
* @hidden
*/
get element() {
return this.host.nativeElement;
}
/**
* @hidden
*/
get toolbarPosition() {
return isDocumentAvailable() && this.host.nativeElement.closest('.k-toolbar')?.getAttribute('position');
}
constructor(host, ctx) {
this.host = host;
this.ctx = ctx;
}
ngAfterViewInit() {
if (!isDocumentAvailable() || !this.toolbarPosition) {
return;
}
this.ctx[`${this.toolbarPosition}ToolbarNavigation`]?.navigableElements.push(this.element);
this.ctx[`${this.toolbarPosition}ToolbarNavigation`]?.notify();
}
ngOnDestroy() {
if (!isDocumentAvailable() || !this.toolbarPosition) {
return;
}
const elements = this.ctx[`${this.toolbarPosition}ToolbarNavigation`].navigableElements;
this.ctx[`${this.toolbarPosition}ToolbarNavigation`].navigableElements = elements.filter(el => el !== this.element);
this.ctx[`${this.toolbarPosition}ToolbarNavigation`].notify();
}
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: TreeListToolbarFocusableDirective, deps: [{ token: i0.ElementRef }, { token: i1.ContextService }], target: i0.ɵɵFactoryTarget.Directive });
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "18.2.14", type: TreeListToolbarFocusableDirective, isStandalone: true, selector: "\n [kendoTreeListToolbarFocusable],\n [kendoTreeListAddCommand],\n [kendoTreeListCancelCommand],\n [kendoTreeListEditCommand],\n [kendoTreeListRemoveCommand],\n [kendoTreeListSaveCommand],\n [kendoTreeListExcelCommand],\n [kendoTreeListPDFCommand]\n ", ngImport: i0 });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: TreeListToolbarFocusableDirective, decorators: [{
type: Directive,
args: [{
selector: `
[kendoTreeListToolbarFocusable],
[kendoTreeListAddCommand],
[kendoTreeListCancelCommand],
[kendoTreeListEditCommand],
[kendoTreeListRemoveCommand],
[kendoTreeListSaveCommand],
[kendoTreeListExcelCommand],
[kendoTreeListPDFCommand]
`,
standalone: true
}]
}], ctorParameters: () => [{ type: i0.ElementRef }, { type: i1.ContextService }] });