MCPcopy Create free account
hub / github.com/angular/components / setDefaultState

Method setDefaultState

src/aria/private/listbox/listbox.ts:267–288  ·  view source on GitHub ↗

* Sets the listbox to it's default initial state. * * Sets the active index of the listbox to the first focusable selected * item if one exists. Otherwise, sets focus to the first focusable item. * * This method should be called once the listbox and it's options are properly initializ

()

Source from the content-addressed store, hash-verified

265 * is called.
266 */
267 setDefaultState() {
268 let firstItem: OptionPattern<V> | null = null;
269
270 for (const item of this.inputs.items()) {
271 if (this.listBehavior.isFocusable(item)) {
272 if (!firstItem) {
273 firstItem = item;
274 }
275 if (item.selected()) {
276 this.inputs.activeItem.set(item);
277 return;
278 }
279 }
280 }
281
282 if (firstItem) {
283 this.inputs.activeItem.set(firstItem);
284 if (this.followFocus()) {
285 this.listBehavior.select();
286 }
287 }
288 }
289
290 /**
291 * Sets the default active state of the listbox before receiving interaction for the first time.

Callers 2

setDefaultStateEffectMethod · 0.95
listbox.spec.tsFile · 0.45

Calls 4

setMethod · 0.80
selectMethod · 0.65
isFocusableMethod · 0.45
selectedMethod · 0.45

Tested by

no test coverage detected