@progress/kendo-angular-listview
Version:
Kendo UI Angular listview component
77 lines (76 loc) • 3.5 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, Renderer2, Input } from '@angular/core';
import { NavigationService } from './navigation.service';
import { isPresent } from '../utils';
import * as i0 from "@angular/core";
import * as i1 from "./navigation.service";
/**
* @hidden
*/
export class ListViewNavigableItemDirective {
hostElement;
renderer;
navigationService;
/**
* The current item index. Used to track which navigation changes apply to this item.
*/
index;
navigationSubscription;
constructor(hostElement, renderer, navigationService) {
this.hostElement = hostElement;
this.renderer = renderer;
this.navigationService = navigationService;
}
ngOnChanges() {
this.updateNavigationState();
}
ngOnInit() {
this.navigationSubscription = this.navigationService.changes
.subscribe(this.updateNavigationState.bind(this));
}
ngOnDestroy() {
if (isPresent(this.navigationSubscription)) {
this.navigationSubscription.unsubscribe();
}
}
updateNavigationState() {
this.updateTabIndex();
this.updateFocusedState();
}
updateFocusedState() {
const shouldFocus = this.navigationService.isActive(this.index) && this.navigationService.isFocused;
const focusedCssClass = 'k-focus';
if (shouldFocus) {
this.renderer.addClass(this.hostElement.nativeElement, focusedCssClass);
this.hostElement.nativeElement.focus();
}
else {
this.renderer.removeClass(this.hostElement.nativeElement, focusedCssClass);
}
}
updateTabIndex() {
if (!this.navigationService.isEnabled) {
this.renderer.removeAttribute(this.hostElement.nativeElement, 'tabindex');
}
else if (this.navigationService.isActive(this.index)) {
this.renderer.setAttribute(this.hostElement.nativeElement, 'tabindex', '0');
}
else {
this.renderer.setAttribute(this.hostElement.nativeElement, 'tabindex', '-1');
}
}
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: ListViewNavigableItemDirective, deps: [{ token: i0.ElementRef }, { token: i0.Renderer2 }, { token: i1.NavigationService }], target: i0.ɵɵFactoryTarget.Directive });
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.12", type: ListViewNavigableItemDirective, isStandalone: true, selector: "[kendoListViewNavigableItem]", inputs: { index: "index" }, usesOnChanges: true, ngImport: i0 });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: ListViewNavigableItemDirective, decorators: [{
type: Directive,
args: [{
selector: '[kendoListViewNavigableItem]',
standalone: true
}]
}], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: i0.Renderer2 }, { type: i1.NavigationService }]; }, propDecorators: { index: [{
type: Input
}] } });