Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
AfterViewInit, ChangeDetectorRef, Component, ContentChildren, HostBinding, Input, OnChanges, QueryList, Type,
AfterViewInit, ChangeDetectorRef, Component, ContentChildren, ElementRef, HostBinding, Input, OnChanges, QueryList, Type, ViewChild,
} from "@angular/core";
import { FormControl } from "@angular/forms";
import { AsyncTask, Dto, ServerError, autobind } from "@batch-flask/core";
Expand Down Expand Up @@ -71,6 +71,8 @@ export class ComplexFormComponent extends FormBase implements AfterViewInit, OnC

@ContentChildren(FormPageComponent) public pages: QueryList<FormPageComponent>;

@ViewChild('formElement') formElement: ElementRef;

public mainPage: FormPageComponent;
public currentPage: FormPageComponent;
public showJsonEditor = false;
Expand All @@ -95,6 +97,9 @@ export class ComplexFormComponent extends FormBase implements AfterViewInit, OnC
this.currentPage = page;
this.mainPage = page;
this.changeDetector.detectChanges();
setTimeout(() => {
this.focusFirstFocusableElement();
})
}

public ngOnChanges(changes) {
Expand Down Expand Up @@ -168,6 +173,10 @@ export class ComplexFormComponent extends FormBase implements AfterViewInit, OnC
}
this._pageStack.push(this.currentPage);
this.currentPage = page;

setTimeout(() => {
this.focusFirstFocusableElement()
});
}

@autobind()
Expand Down Expand Up @@ -268,4 +277,8 @@ export class ComplexFormComponent extends FormBase implements AfterViewInit, OnC
multiUse: this.multiUse,
};
}

private focusFirstFocusableElement() {
this.formElement.nativeElement?.querySelector('[autofocus], button, input, textarea, select')?.focus()
}
Comment on lines +281 to +283
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The existing autofocus directive will not work as expected when used on an element nested inside of complex-form because those elements seem to be injected/rendered in the DOM before they're visible/shown. We'll have to explicitly focus those elements after the nested form page is opened.

}
2 changes: 1 addition & 1 deletion src/@batch-flask/ui/form/complex-form/complex-form.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ <h1 *ngIf="currentPage.title">{{currentPage.title}}</h1>
</div>
</div>
<div *ngIf="!showJsonEditor" class="classic-form-container">
<form novalidate>
<form #formElement novalidate>
<ng-template [ngTemplateOutlet]="currentPage.content"></ng-template>
</form>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,13 @@ export class AutoStorageAccountPickerComponent implements OnInit, ControlValueAc
* to define a custom handler.
*/
onKeydown(event: KeyboardEvent) {
this.classicTooltip.hide();
this.classicTooltip?.hide();
if (event.key === "ArrowDown" || event.key === "ArrowUp" ||
event.key === "Tab") {
if (this.selectedStorageAccounts.size === 1) {
const id = this.selectedStorageAccounts.values().next().value;
if (this.classicAccounts.has(id)) {
this.classicTooltip.show();
this.classicTooltip?.show();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<bl-loading [status]="loadingStatus">
<div *ngIf="loadingStatus">
<bl-button type="wide" (do)="pickStorageAccount(noSelectionKey)">
<bl-button type="wide" (do)="pickStorageAccount(noSelectionKey)" autofocus>
{{'auto-storage-account-picker.clear-button-label' | i18n}}
</bl-button>
<h3>{{'auto-storage-account-picker.same-region-title' | i18n: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<bl-form-page [title]="title" main-form-page [formGroup]="form">
<bl-form-section title="Mode" *ngIf="multipleModes">
<div class="modes">
<bl-button type="wide" [class.selected]="modeState === NcjTemplateMode.NewPoolAndJob" (do)="pickMode(NcjTemplateMode.NewPoolAndJob)">Run job with auto pool</bl-button>
<bl-button type="wide" [class.selected]="modeState === NcjTemplateMode.NewPoolAndJob" (do)="pickMode(NcjTemplateMode.NewPoolAndJob)" autofocus>Run job with auto pool</bl-button>
<bl-button type="wide" [class.selected]="modeState === NcjTemplateMode.ExistingPoolAndJob" (do)="pickMode(NcjTemplateMode.ExistingPoolAndJob)">Run job with existing pool</bl-button>
<bl-button type="wide" [class.selected]="modeState === NcjTemplateMode.NewPool" (do)="pickMode(NcjTemplateMode.NewPool)">Create pool for later use</bl-button>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div [formGroup]="form">
<div class="form-element">
<bl-form-field>
<input blInput formControlName="id" placeholder="ID">
<input blInput autofocus formControlName="id" placeholder="ID">
</bl-form-field>
<bl-error controlName="id" code="required">ID is a required field</bl-error>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div [formGroup]="form">
<div class="form-element">
<bl-form-field>
<input blInput formControlName="id" placeholder="ID">
<input blInput autofocus formControlName="id" placeholder="ID">
</bl-form-field>
<bl-error controlName="id" code="required">ID is a required field</bl-error>
</div>
Expand Down