[PM-9673] Autofocus newly added input in the excluded domains view (#10641)

* autofocus newly added input in the excluded domains view

* update subscription
This commit is contained in:
Jonathan Prusik 2024-08-26 10:03:32 -04:00 committed by GitHub
parent 86f3a679ae
commit 53e69e6dc6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 30 additions and 13 deletions

View File

@ -78,8 +78,8 @@ export class AutofillComponent implements OnInit {
* Default values set here are used in component state operations * Default values set here are used in component state operations
* until corresponding stored settings have loaded on init. * until corresponding stored settings have loaded on init.
*/ */
protected canOverrideBrowserAutofillSetting = false; protected canOverrideBrowserAutofillSetting: boolean = false;
protected defaultBrowserAutofillDisabled = false; protected defaultBrowserAutofillDisabled: boolean = false;
protected inlineMenuVisibility: InlineMenuVisibilitySetting = protected inlineMenuVisibility: InlineMenuVisibilitySetting =
AutofillOverlayVisibility.OnFieldFocus; AutofillOverlayVisibility.OnFieldFocus;
protected browserClientVendor: BrowserClientVendor = BrowserClientVendors.Unknown; protected browserClientVendor: BrowserClientVendor = BrowserClientVendors.Unknown;
@ -90,21 +90,21 @@ export class AutofillComponent implements OnInit {
protected autofillOnPageLoadFromPolicy$ = protected autofillOnPageLoadFromPolicy$ =
this.autofillSettingsService.activateAutofillOnPageLoadFromPolicy$; this.autofillSettingsService.activateAutofillOnPageLoadFromPolicy$;
enableAutofillOnPageLoad = false; enableAutofillOnPageLoad: boolean = false;
enableInlineMenu = false; enableInlineMenu: boolean = false;
enableInlineMenuOnIconSelect = false; enableInlineMenuOnIconSelect: boolean = false;
autofillOnPageLoadDefault = false; autofillOnPageLoadDefault: boolean = false;
autofillOnPageLoadOptions: { name: string; value: boolean }[]; autofillOnPageLoadOptions: { name: string; value: boolean }[];
enableContextMenuItem = false; enableContextMenuItem: boolean = false;
enableAutoTotpCopy = false; enableAutoTotpCopy: boolean = false;
clearClipboard: ClearClipboardDelaySetting; clearClipboard: ClearClipboardDelaySetting;
clearClipboardOptions: { name: string; value: ClearClipboardDelaySetting }[]; clearClipboardOptions: { name: string; value: ClearClipboardDelaySetting }[];
defaultUriMatch: UriMatchStrategySetting = UriMatchStrategy.Domain; defaultUriMatch: UriMatchStrategySetting = UriMatchStrategy.Domain;
uriMatchOptions: { name: string; value: UriMatchStrategySetting }[]; uriMatchOptions: { name: string; value: UriMatchStrategySetting }[];
showCardsCurrentTab = true; showCardsCurrentTab: boolean = true;
showIdentitiesCurrentTab = true; showIdentitiesCurrentTab: boolean = true;
autofillKeyboardHelperText: string; autofillKeyboardHelperText: string;
accountSwitcherEnabled = false; accountSwitcherEnabled: boolean = false;
constructor( constructor(
private i18nService: I18nService, private i18nService: I18nService,

View File

@ -27,6 +27,7 @@
}}</bit-label> }}</bit-label>
<input <input
*ngIf="i >= fieldsEditThreshold" *ngIf="i >= fieldsEditThreshold"
#uriInput
appInputVerbatim appInputVerbatim
bitInput bitInput
id="excludedDomain{{ i }}" id="excludedDomain{{ i }}"

View File

@ -1,8 +1,8 @@
import { CommonModule } from "@angular/common"; import { CommonModule } from "@angular/common";
import { Component, OnDestroy, OnInit } from "@angular/core"; import { QueryList, Component, ElementRef, OnDestroy, OnInit, ViewChildren } from "@angular/core";
import { FormsModule } from "@angular/forms"; import { FormsModule } from "@angular/forms";
import { Router, RouterModule } from "@angular/router"; import { Router, RouterModule } from "@angular/router";
import { firstValueFrom } from "rxjs"; import { firstValueFrom, Subject, takeUntil } from "rxjs";
import { JslibModule } from "@bitwarden/angular/jslib.module"; import { JslibModule } from "@bitwarden/angular/jslib.module";
import { DomainSettingsService } from "@bitwarden/common/autofill/services/domain-settings.service"; import { DomainSettingsService } from "@bitwarden/common/autofill/services/domain-settings.service";
@ -56,6 +56,8 @@ const BroadcasterSubscriptionId = "excludedDomainsState";
], ],
}) })
export class ExcludedDomainsComponent implements OnInit, OnDestroy { export class ExcludedDomainsComponent implements OnInit, OnDestroy {
@ViewChildren("uriInput") uriInputElements: QueryList<ElementRef<HTMLInputElement>>;
accountSwitcherEnabled = false; accountSwitcherEnabled = false;
dataIsPristine = true; dataIsPristine = true;
excludedDomainsState: string[] = []; excludedDomainsState: string[] = [];
@ -63,6 +65,8 @@ export class ExcludedDomainsComponent implements OnInit, OnDestroy {
// How many fields should be non-editable before editable fields // How many fields should be non-editable before editable fields
fieldsEditThreshold: number = 0; fieldsEditThreshold: number = 0;
private destroy$ = new Subject<void>();
constructor( constructor(
private domainSettingsService: DomainSettingsService, private domainSettingsService: DomainSettingsService,
private i18nService: I18nService, private i18nService: I18nService,
@ -84,10 +88,22 @@ export class ExcludedDomainsComponent implements OnInit, OnDestroy {
// Do not allow the first x (pre-existing) fields to be edited // Do not allow the first x (pre-existing) fields to be edited
this.fieldsEditThreshold = this.storedExcludedDomains.length; this.fieldsEditThreshold = this.storedExcludedDomains.length;
this.uriInputElements.changes.pipe(takeUntil(this.destroy$)).subscribe(({ last }) => {
this.focusNewUriInput(last);
});
} }
ngOnDestroy() { ngOnDestroy() {
this.broadcasterService.unsubscribe(BroadcasterSubscriptionId); this.broadcasterService.unsubscribe(BroadcasterSubscriptionId);
this.destroy$.next();
this.destroy$.complete();
}
focusNewUriInput(elementRef: ElementRef) {
if (elementRef?.nativeElement) {
elementRef.nativeElement.focus();
}
} }
async addNewDomain() { async addNewDomain() {