]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: Add 'autofocus' directive
authorVolker Theile <vtheile@suse.com>
Fri, 20 Apr 2018 12:33:44 +0000 (14:33 +0200)
committerVolker Theile <vtheile@suse.com>
Mon, 23 Apr 2018 13:45:28 +0000 (15:45 +0200)
Signed-off-by: Volker Theile <vtheile@suse.com>
src/pybind/mgr/dashboard/frontend/src/app/shared/directives/autofocus.directive.spec.ts [new file with mode: 0644]
src/pybind/mgr/dashboard/frontend/src/app/shared/directives/autofocus.directive.ts [new file with mode: 0644]
src/pybind/mgr/dashboard/frontend/src/app/shared/shared.module.ts

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 (file)
index 0000000..3126b4c
--- /dev/null
@@ -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 (file)
index 0000000..3c5eae2
--- /dev/null
@@ -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);
+  }
+}
index 584ed0968170393020e136c14097060aa2cda4cf..1ed5da8f078643af1299d918abb66a2d1c118bd5 100644 (file)
@@ -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,