@progress/kendo-angular-conversational-ui
Version:
Kendo UI for Angular Conversational UI components
57 lines (56 loc) • 2.57 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 { Injectable } from '@angular/core';
import { LocalizationService } from '@progress/kendo-angular-l10n';
import * as i0 from "@angular/core";
import * as i1 from "@progress/kendo-angular-l10n";
/**
* @hidden
*/
export class ToolbarNavigationService {
localizationService;
focusableElements = [];
currentFocusedIndex = 0;
constructor(localizationService) {
this.localizationService = localizationService;
}
register(tool) {
if (!this.focusableElements.some(el => el === tool)) {
this.focusableElements.push(tool);
}
}
unregister(tool) {
this.currentFocusedIndex = 0;
this.focusableElements = this.focusableElements.filter(el => el !== tool);
}
isActive(focusable) {
return this.focusableElements[this.currentFocusedIndex] === focusable;
}
setActiveIndex(tool) {
this.currentFocusedIndex = Math.max(this.focusableElements.indexOf(tool), 0);
}
move(direction) {
let delta = direction === 'right' ? 1 : -1;
if (this.localizationService.rtl) {
delta = -delta;
}
this.currentFocusedIndex += delta;
if (this.currentFocusedIndex < 0) {
this.currentFocusedIndex = this.focusableElements.length - 1;
}
else if (this.currentFocusedIndex >= this.focusableElements.length) {
this.currentFocusedIndex = 0;
}
this.focusableElements[this.currentFocusedIndex].activate();
}
focusFirst() {
this.focusableElements[this.currentFocusedIndex].activate();
}
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: ToolbarNavigationService, deps: [{ token: i1.LocalizationService }], target: i0.ɵɵFactoryTarget.Injectable });
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: ToolbarNavigationService });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: ToolbarNavigationService, decorators: [{
type: Injectable
}], ctorParameters: function () { return [{ type: i1.LocalizationService }]; } });