From 5594a535c19a9026c7461b7bbb173f389bf21d11 Mon Sep 17 00:00:00 2001 From: SkyZeroZx <73321943+SkyZeroZx@users.noreply.github.com> Date: Tue, 13 Jan 2026 19:54:40 -0500 Subject: [PATCH] docs(docs-infra): use Signals Forms focusBoundControl Removes direct `ViewChild` access from `TextField` components and relies on Signals Forms via the `focusBoundControl` to manage focus. (cherry picked from commit 074666b2e8c3c8e2b7bc473f8d5772ebec4fc586) --- .../components/search-dialog/search-dialog.component.ts | 3 +-- .../api-reference-list/api-reference-list.component.ts | 7 ++----- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/adev/shared-docs/components/search-dialog/search-dialog.component.ts b/adev/shared-docs/components/search-dialog/search-dialog.component.ts index 4eb83ac6988..688d3fa7e96 100644 --- a/adev/shared-docs/components/search-dialog/search-dialog.component.ts +++ b/adev/shared-docs/components/search-dialog/search-dialog.component.ts @@ -54,7 +54,6 @@ export class SearchDialog { readonly onClose = output(); readonly dialog = viewChild.required>('searchDialog'); readonly items = viewChildren(SearchItem); - readonly textField = viewChild(TextField); readonly history = inject(SearchHistory); private readonly search = inject(Search); @@ -98,7 +97,7 @@ export class SearchDialog { } // We want to select the pre-existing text on opening // In order to change the search input with minimal user interaction. - this.textField()?.input().nativeElement.select(); + this.searchForm().focusBoundControl(); }, }); diff --git a/adev/src/app/features/references/api-reference-list/api-reference-list.component.ts b/adev/src/app/features/references/api-reference-list/api-reference-list.component.ts index e4099e3e2ab..770395add8b 100644 --- a/adev/src/app/features/references/api-reference-list/api-reference-list.component.ts +++ b/adev/src/app/features/references/api-reference-list/api-reference-list.component.ts @@ -18,7 +18,6 @@ import { inject, input, linkedSignal, - viewChild, } from '@angular/core'; import {Select, SelectOption, TextField} from '@angular/docs'; import {FormField, form} from '@angular/forms/signals'; @@ -62,7 +61,6 @@ export default class ApiReferenceList { // services private readonly apiReferenceManager = inject(ApiReferenceManager); private readonly router = inject(Router); - private readonly filterInput = viewChild.required(TextField); private readonly injector = inject(EnvironmentInjector); // inputs @@ -137,13 +135,12 @@ export default class ApiReferenceList { constructor() { effect(() => { - const filterInput = this.filterInput(); + const filterInput = this.form.query(); afterNextRender( { write: () => { - // Why not improve this once https://github.com/orgs/angular/projects/60?pane=issue&itemId=143488813 is done if (matchMedia('(hover: hover) and (pointer:fine)').matches) { - scheduleOnIdle(() => filterInput.focus()); + scheduleOnIdle(() => filterInput.focusBoundControl()); } }, },