()
| 150 | readonly expansionDelay = input<number>(100); // Arbitrarily chosen. |
| 151 | |
| 152 | constructor() { |
| 153 | this._pattern = new MenuPattern({ |
| 154 | ...this, |
| 155 | parent: computed(() => this.parent()?._pattern), |
| 156 | items: this._itemPatterns, |
| 157 | multi: () => false, |
| 158 | focusMode: () => 'roving', |
| 159 | orientation: () => 'vertical', |
| 160 | selectionMode: () => 'explicit', |
| 161 | activeItem: signal(undefined), |
| 162 | element: computed(() => this._elementRef.nativeElement), |
| 163 | itemSelected: (value: V) => this.itemSelected.emit(value), |
| 164 | }); |
| 165 | |
| 166 | afterRenderEffect({ |
| 167 | write: () => { |
| 168 | const parent = this.parent(); |
| 169 | if (parent instanceof MenuItem && parent.parent instanceof MenuBar) { |
| 170 | this._deferredContentAware?.contentVisible.set(true); |
| 171 | } else { |
| 172 | this._deferredContentAware?.contentVisible.set( |
| 173 | this._pattern.visible() || !!this.parent()?._pattern.hasBeenInteracted(), |
| 174 | ); |
| 175 | } |
| 176 | }, |
| 177 | }); |
| 178 | |
| 179 | // Focuses an active menu item when the menu becomes visible. This is needed to |
| 180 | // properly restore focus to the active item when returning to a menu, and to |
| 181 | // focus the first item when navigating into a submenu with hover. |
| 182 | afterRenderEffect({ |
| 183 | write: () => { |
| 184 | if (this.visible()) { |
| 185 | const activeItem = untracked(() => this._pattern.inputs.activeItem()); |
| 186 | this._pattern.listBehavior.goto(activeItem!); |
| 187 | } |
| 188 | }, |
| 189 | }); |
| 190 | |
| 191 | afterRenderEffect({write: () => this._pattern.setDefaultStateEffect()}); |
| 192 | |
| 193 | // Check for any violations after the DOM has been updated. |
| 194 | if (typeof ngDevMode === 'undefined' || ngDevMode) { |
| 195 | afterRenderEffect({ |
| 196 | read: () => { |
| 197 | reportViolations(this._pattern.validate(), this.element); |
| 198 | }, |
| 199 | }); |
| 200 | } |
| 201 | |
| 202 | afterNextRender(() => { |
| 203 | this._collection.startObserving(this.element); |
| 204 | }); |
| 205 | } |
| 206 | |
| 207 | ngOnDestroy() { |
| 208 | this._collection.stopObserving(); |
nothing calls this directly
no test coverage detected