From: Volker Theile Date: Fri, 20 Apr 2018 12:33:44 +0000 (+0200) Subject: mgr/dashboard: Add 'autofocus' directive X-Git-Tag: v13.1.0~133^2~1 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=1daa8b0ab382e745d23c2140bae0749d1a1dd4b1;p=ceph.git mgr/dashboard: Add 'autofocus' directive Signed-off-by: Volker Theile --- diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/directives/autofocus.directive.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/directives/autofocus.directive.spec.ts new file mode 100644 index 0000000000000..3126b4cfba76f --- /dev/null +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/directives/autofocus.directive.spec.ts @@ -0,0 +1,8 @@ +import { AutofocusDirective } from './autofocus.directive'; + +describe('AutofocusDirective', () => { + it('should create an instance', () => { + const directive = new AutofocusDirective(null); + expect(directive).toBeTruthy(); + }); +}); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/directives/autofocus.directive.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/directives/autofocus.directive.ts new file mode 100644 index 0000000000000..3c5eae227eed6 --- /dev/null +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/directives/autofocus.directive.ts @@ -0,0 +1,17 @@ +import { Directive, ElementRef, OnInit } from '@angular/core'; + +@Directive({ + selector: '[autofocus]' // tslint:disable-line +}) +export class AutofocusDirective implements OnInit { + + constructor(private elementRef: ElementRef) {} + + ngOnInit() { + setTimeout(() => { + if (this.elementRef && this.elementRef.nativeElement) { + this.elementRef.nativeElement.focus(); + } + }, 0); + } +} diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/shared.module.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/shared.module.ts index 584ed09681703..1ed5da8f07864 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/shared.module.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/shared.module.ts @@ -4,6 +4,7 @@ import { NgModule } from '@angular/core'; import { ApiModule } from './api/api.module'; import { ComponentsModule } from './components/components.module'; import { DataTableModule } from './datatable/datatable.module'; +import { AutofocusDirective } from './directives/autofocus.directive'; import { DimlessBinaryDirective } from './directives/dimless-binary.directive'; import { PasswordButtonDirective } from './directives/password-button.directive'; import { PipesModule } from './pipes/pipes.module'; @@ -23,7 +24,8 @@ import { ServicesModule } from './services/services.module'; ], declarations: [ PasswordButtonDirective, - DimlessBinaryDirective + DimlessBinaryDirective, + AutofocusDirective ], exports: [ ComponentsModule,