@progress/kendo-angular-buttons
Version:
Buttons Package for Angular
68 lines (67 loc) • 2.91 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, Input, ElementRef, Renderer2 } from '@angular/core';
import { FocusService } from './focus.service';
import { Subscription } from 'rxjs';
import { isDocumentAvailable } from '@progress/kendo-angular-common';
import * as i0 from "@angular/core";
import * as i1 from "./focus.service";
/**
* @hidden
*/
export class FocusableDirective {
focusService;
renderer;
index;
element;
subs = new Subscription();
constructor(focusService, elementRef, renderer) {
this.focusService = focusService;
this.renderer = renderer;
this.element = elementRef.nativeElement;
this.subscribeEvents();
}
ngOnInit() {
if (this.index === this.focusService.focused) {
this.renderer.addClass(this.element, 'k-focus');
}
else {
this.renderer.removeClass(this.element, 'k-focus');
}
}
/**
* @hidden
*/
ngOnDestroy() {
this.subs.unsubscribe();
}
subscribeEvents() {
if (!isDocumentAvailable()) {
return;
}
this.subs.add(this.focusService.onFocus.subscribe((index) => {
if (this.index === index) {
this.renderer.addClass(this.element, 'k-focus');
this.renderer.setAttribute(this.element, 'tabindex', '0');
this.element.focus();
}
else {
this.renderer.setAttribute(this.element, 'tabindex', '-1');
this.renderer.removeClass(this.element, 'k-focus');
}
}));
}
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: FocusableDirective, deps: [{ token: i1.FocusService }, { token: i0.ElementRef }, { token: i0.Renderer2 }], target: i0.ɵɵFactoryTarget.Directive });
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.12", type: FocusableDirective, isStandalone: true, selector: "[kendoButtonFocusable]", inputs: { index: "index" }, ngImport: i0 });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: FocusableDirective, decorators: [{
type: Directive,
args: [{
selector: '[kendoButtonFocusable]',
standalone: true
}]
}], ctorParameters: function () { return [{ type: i1.FocusService }, { type: i0.ElementRef }, { type: i0.Renderer2 }]; }, propDecorators: { index: [{
type: Input
}] } });