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

Method constructor

src/aria/listbox/listbox.ts:143–198  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

141 );
142
143 constructor() {
144 const inputs = {
145 ...this,
146 id: this.id,
147 items: this._orderedItemPatterns,
148 activeItem: signal(undefined),
149 textDirection: this.textDirection,
150 element: () => this._elementRef.nativeElement,
151 };
152
153 this._pattern = new ListboxPattern<V>(inputs);
154
155 this.activeDescendant = computed(() => this._pattern.activeDescendant());
156
157 afterNextRender(() => {
158 this._collection.startObserving(this.element);
159 });
160
161 // Check for any violations after the DOM has been updated.
162 if (typeof ngDevMode === 'undefined' || ngDevMode) {
163 afterRenderEffect({
164 read: () => {
165 reportViolations(this._pattern.validate(), this.element);
166 },
167 });
168 }
169
170 afterRenderEffect({write: () => this._pattern.setDefaultStateEffect()});
171
172 // Ensure that if the active item is removed from
173 // the list, the listbox updates it's focus state.
174 afterRenderEffect({
175 write: () => {
176 const items = inputs.items();
177 const activeItem = untracked(() => inputs.activeItem());
178
179 if (activeItem && !items.some(i => i === activeItem)) {
180 this._pattern.listBehavior.unfocus();
181 this._pattern.setDefaultState();
182 }
183 },
184 });
185
186 // Ensure that the value is always in sync with the available options.
187 // This needs to be after the render for the value to always be available.
188 afterRenderEffect({
189 write: () => {
190 const items = inputs.items();
191 const value = untracked(() => this.value());
192
193 if (items && value.some(v => !items.some(i => i.value() === v))) {
194 this.value.set(value.filter(v => items.some(i => i.value() === v)));
195 }
196 },
197 });
198 }
199
200 ngOnDestroy() {

Callers

nothing calls this directly

Calls 12

reportViolationsFunction · 0.90
signalFunction · 0.85
computedFunction · 0.85
startObservingMethod · 0.80
activeItemMethod · 0.80
setMethod · 0.80
unfocusMethod · 0.65
validateMethod · 0.45
setDefaultStateEffectMethod · 0.45
setDefaultStateMethod · 0.45
valueMethod · 0.45
filterMethod · 0.45

Tested by

no test coverage detected