From a3664dfdc95897075e7b8abd670706e53f5a1ec3 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 24 Mar 2021 13:32:55 +0100 Subject: [PATCH] Auto focus plugin search input --- .../plugin-search/plugin-search.component.html | 2 +- client/src/app/+login/login.component.html | 2 +- client/src/app/+login/login.component.ts | 7 +------ .../shared-main/angular/autofocus.directive.ts | 12 ++++++++++++ client/src/app/shared/shared-main/angular/index.ts | 1 + .../src/app/shared/shared-main/shared-main.module.ts | 3 +++ 6 files changed, 19 insertions(+), 8 deletions(-) create mode 100644 client/src/app/shared/shared-main/angular/autofocus.directive.ts diff --git a/client/src/app/+admin/plugins/plugin-search/plugin-search.component.html b/client/src/app/+admin/plugins/plugin-search/plugin-search.component.html index f98ef690c..8edf03a89 100644 --- a/client/src/app/+admin/plugins/plugin-search/plugin-search.component.html +++ b/client/src/app/+admin/plugins/plugin-search/plugin-search.component.html @@ -3,7 +3,7 @@
diff --git a/client/src/app/+login/login.component.html b/client/src/app/+login/login.component.html index 3171e5b0f..0167066a0 100644 --- a/client/src/app/+login/login.component.html +++ b/client/src/app/+login/login.component.html @@ -21,7 +21,7 @@
diff --git a/client/src/app/+login/login.component.ts b/client/src/app/+login/login.component.ts index af747b7fa..d8ad49081 100644 --- a/client/src/app/+login/login.component.ts +++ b/client/src/app/+login/login.component.ts @@ -3,9 +3,9 @@ import { AfterViewInit, Component, ElementRef, OnInit, ViewChild } from '@angula import { ActivatedRoute } from '@angular/router' import { AuthService, Notifier, RedirectService, UserService } from '@app/core' import { HooksService } from '@app/core/plugins/hooks.service' -import { InstanceAboutAccordionComponent } from '@app/shared/shared-instance' import { LOGIN_PASSWORD_VALIDATOR, LOGIN_USERNAME_VALIDATOR } from '@app/shared/form-validators/login-validators' import { FormReactive, FormValidatorService } from '@app/shared/shared-forms' +import { InstanceAboutAccordionComponent } from '@app/shared/shared-instance' import { NgbAccordion, NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap' import { RegisteredExternalAuthConfig, ServerConfig } from '@shared/models' @@ -16,7 +16,6 @@ import { RegisteredExternalAuthConfig, ServerConfig } from '@shared/models' }) export class LoginComponent extends FormReactive implements OnInit, AfterViewInit { - @ViewChild('usernameInput', { static: false }) usernameInput: ElementRef @ViewChild('forgotPasswordModal', { static: true }) forgotPasswordModal: ElementRef accordion: NgbAccordion @@ -91,10 +90,6 @@ export class LoginComponent extends FormReactive implements OnInit, AfterViewIni } ngAfterViewInit () { - if (this.usernameInput) { - this.usernameInput.nativeElement.focus() - } - this.hooks.runAction('action:login.init', 'login') } diff --git a/client/src/app/shared/shared-main/angular/autofocus.directive.ts b/client/src/app/shared/shared-main/angular/autofocus.directive.ts new file mode 100644 index 000000000..5f087d79d --- /dev/null +++ b/client/src/app/shared/shared-main/angular/autofocus.directive.ts @@ -0,0 +1,12 @@ +import { AfterViewInit, Directive, ElementRef } from '@angular/core' + +@Directive({ + selector: '[autofocus]' +}) +export class AutofocusDirective implements AfterViewInit { + constructor (private host: ElementRef) { } + + ngAfterViewInit () { + this.host.nativeElement.focus() + } +} diff --git a/client/src/app/shared/shared-main/angular/index.ts b/client/src/app/shared/shared-main/angular/index.ts index 29f8b3650..8ea47bb33 100644 --- a/client/src/app/shared/shared-main/angular/index.ts +++ b/client/src/app/shared/shared-main/angular/index.ts @@ -1,3 +1,4 @@ +export * from './autofocus.directive' export * from './bytes.pipe' export * from './duration-formatter.pipe' export * from './from-now.pipe' diff --git a/client/src/app/shared/shared-main/shared-main.module.ts b/client/src/app/shared/shared-main/shared-main.module.ts index 9d550996d..3e21d491a 100644 --- a/client/src/app/shared/shared-main/shared-main.module.ts +++ b/client/src/app/shared/shared-main/shared-main.module.ts @@ -19,6 +19,7 @@ import { LoadingBarHttpClientModule } from '@ngx-loading-bar/http-client' import { SharedGlobalIconModule } from '../shared-icons' import { AccountService, ActorAvatarInfoComponent, VideoAvatarChannelComponent } from './account' import { + AutofocusDirective, BytesPipe, DurationFormatterPipe, FromNowPipe, @@ -71,6 +72,7 @@ import { VideoChannelService } from './video-channel' NumberFormatterPipe, BytesPipe, DurationFormatterPipe, + AutofocusDirective, InfiniteScrollerDirective, PeerTubeTemplateDirective, @@ -125,6 +127,7 @@ import { VideoChannelService } from './video-channel' BytesPipe, NumberFormatterPipe, DurationFormatterPipe, + AutofocusDirective, InfiniteScrollerDirective, PeerTubeTemplateDirective,