MCPcopy Create free account
hub / github.com/angular/angular / getBindingForFocus

Method getBindingForFocus

packages/forms/signals/src/field/node.ts:119–137  ·  view source on GitHub ↗

* Gets the Field directive binding that should be focused when the developer calls * `focusBoundControl` on this node. * * This will prioritize focusable bindings to this node, and if multiple exist, it will return * the first one in the DOM. If no focusable bindings exist on this node,

()

Source from the content-addressed store, hash-verified

117 * first focusable binding in the DOM for any descendant node of this one.
118 */
119 private getBindingForFocus():
120 (FormField<unknown> & {focus: (options?: FocusOptions) => void}) | undefined {
121 // First try to focus one of our own bindings.
122 const own = this.formFieldBindings()
123 .filter(
124 (b): b is FormField<unknown> & {focus: (options?: FocusOptions) => void} =>
125 b.focus !== undefined,
126 )
127 .reduce(
128 firstInDom<FormField<unknown> & {focus: (options?: FocusOptions) => void}>,
129 undefined,
130 );
131 if (own) return own;
132 // Fallback to focusing the bound control for one of our children.
133 return this.structure
134 .children()
135 .map((child) => child.getBindingForFocus())
136 .reduce(firstInDom, undefined);
137 }
138
139 /**
140 * The `AbortController` for the currently debounced sync, or `undefined` if there is none.

Callers 1

focusBoundControlMethod · 0.95

Calls 5

formFieldBindingsMethod · 0.95
reduceMethod · 0.80
mapMethod · 0.80
filterMethod · 0.45
childrenMethod · 0.45

Tested by

no test coverage detected