UNPKG

@progress/kendo-angular-pivotgrid

Version:
99 lines (98 loc) 4.29 kB
/**----------------------------------------------------------------------------------------- * 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, Input, NgZone, Renderer2 } from '@angular/core'; import { Subscription } from 'rxjs'; import { Keys } from '@progress/kendo-angular-common'; import * as i0 from "@angular/core"; /** * @hidden */ export class ChipMenuItemDirective { hostElement; renderer; ngZone; menuItemComponent; firstFocusableElement; lastFocusableElement; set isFirst(value) { if (value) { const focusableElement = this.chipMenuItems[0]; this.menuItemComponent.service.menuTabbingService.firstFocusable = focusableElement; this.ngZone.runOutsideAngular(() => { const firstItemKeydownSub = this.renderer.listen(focusableElement, 'keydown', this.onTab); this.subs.add(firstItemKeydownSub); }); } this._isFirst = value; } get isFirst() { return this._isFirst; } set isLast(value) { if (!this.chipMenuItems) { return; } if (value) { const lastFocusableElement = this.getLastColumnMenuItem(); this.menuItemComponent.service.menuTabbingService.lastFocusable = lastFocusableElement; this.ngZone.runOutsideAngular(() => { const lastItemKeydownSub = this.renderer.listen(lastFocusableElement, 'keydown', this.onTab); this.subs.add(lastItemKeydownSub); }); } this._isLast = value; } get isLast() { return this._isLast; } _isFirst = false; _isLast = false; chipMenuItems; subs = new Subscription(); constructor(hostElement, renderer, ngZone) { this.hostElement = hostElement; this.renderer = renderer; this.ngZone = ngZone; } ngAfterViewInit() { this.chipMenuItems = this.hostElement.nativeElement.querySelectorAll('.k-columnmenu-item'); this.chipMenuItems.forEach(el => this.renderer.setAttribute(el, 'tabindex', '0')); } ngOnDestroy() { this.subs.unsubscribe(); } onTab = (e) => { if (e.keyCode !== Keys.Tab) { return; } if (this.isFirst && e.shiftKey && e.target === this.chipMenuItems[0]) { e.preventDefault(); this.menuItemComponent.service.menuTabbingService.lastFocusable.focus(); } if (this.isLast && !e.shiftKey) { const lastColumnMenuItem = this.getLastColumnMenuItem(); const isExpanded = this.menuItemComponent.expanded; if (lastColumnMenuItem === e.target && !isExpanded) { e.preventDefault(); this.menuItemComponent.service.menuTabbingService.firstFocusable.focus(); } } }; getLastColumnMenuItem() { return this.chipMenuItems[this.chipMenuItems.length - 1]; } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: ChipMenuItemDirective, deps: [{ token: i0.ElementRef }, { token: i0.Renderer2 }, { token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Directive }); static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.12", type: ChipMenuItemDirective, isStandalone: true, selector: "[kendoPivotChipMenuItem]", inputs: { menuItemComponent: ["kendoPivotChipMenuItem", "menuItemComponent"] }, ngImport: i0 }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: ChipMenuItemDirective, decorators: [{ type: Directive, args: [{ selector: '[kendoPivotChipMenuItem]', standalone: true }] }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: i0.Renderer2 }, { type: i0.NgZone }]; }, propDecorators: { menuItemComponent: [{ type: Input, args: ['kendoPivotChipMenuItem'] }] } });