MCPcopy
hub / github.com/angular/angular / getBindingForFocus

Method getBindingForFocus

packages/forms/signals/src/field/node.ts:119–138  ·  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})
121 | undefined {
122 // First try to focus one of our own bindings.
123 const own = this.formFieldBindings()
124 .filter(
125 (b): b is FormField<unknown> & {focus: (options?: FocusOptions) => void} =>
126 b.focus !== undefined,
127 )
128 .reduce(
129 firstInDom<FormField<unknown> & {focus: (options?: FocusOptions) => void}>,
130 undefined,
131 );
132 if (own) return own;
133 // Fallback to focusing the bound control for one of our children.
134 return this.structure
135 .children()
136 .map((child) => child.getBindingForFocus())
137 .reduce(firstInDom, undefined);
138 }
139
140 /**
141 * 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