{"record":{"id":"331b41a9a4106af4","repo":"angular/components","slug":"expected-an-instance-of-pointerfocustracker-to-be","errorCode":null,"errorMessage":"expected an instance of PointerFocusTracker to be provided","messagePattern":"expected an instance of PointerFocusTracker to be provided","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/cdk/menu/menu-errors.ts","lineNumber":14,"sourceCode":"/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.dev/license\n */\n\n/**\n * Throws an exception when an instance of the PointerFocusTracker is not provided.\n * @docs-private\n */\nexport function throwMissingPointerFocusTracker() {\n  throw Error('expected an instance of PointerFocusTracker to be provided');\n}\n\n/**\n * Throws an exception when a reference to the parent menu is not provided.\n * @docs-private\n */\nexport function throwMissingMenuReference() {\n  throw Error('expected a reference to the parent menu');\n}\n","sourceCodeStart":1,"sourceCodeEnd":24,"githubUrl":"https://github.com/angular/components/blob/0411926e7d8ae06b32236ec1048a888cfad5abf2/src/cdk/menu/menu-errors.ts#L1-L24","documentation":"CDK menu directives require an instance of PointerFocusTracker to be configured. throwMissingPointerFocusTracker is raised from _checkConfigured when the expected tracker is missing — i.e. a menu's required sibling/parent pieces (cdkMenu triggers, menubar, or menu-group wiring) were not assembled correctly.","triggerScenarios":"Using cdkMenuItem / cdkMenuGroup outside a cdkMenu or cdkMenuBar context so the injected PointerFocusTracker is undefined; manually instantiating menu directives without the surrounding menu infrastructure.","commonSituations":"Copy-pasting a submenu template without its parent cdkMenu; using menu item directives inside a plain div instead of cdkMenu; version upgrades where directive wiring changed.","solutions":["Place cdkMenuItem inside a cdkMenu (or cdkMenuBar) element so the PointerFocusTracker is provided by the menu context.","If building a submenu, nest cdkMenu inside the parent menu structure rather than standalone.","Restore the surrounding wrapper markup if a refactor removed the cdkMenu host element.","Check that you're not overriding the menu directives' providers in a custom component."],"exampleFix":"// before\n<div>\n  <button cdkMenuItem>Open</button> <!-- no cdkMenu context -->\n</div>\n// after\n<div cdkMenu>\n  <button cdkMenuItem>Open</button>\n</div>","handlingStrategy":"try-catch","validationCode":"import { CdkMenu } from '@angular/cdk/menu';\n// Ensure the host component declares or inherits a cdkMenu/cdkMenuBar ancestor\nconst hasMenuContext = !!injector.get(CdkMenu, null);\nif (!hasMenuContext) {\n  console.error('cdkMenuItem used outside cdkMenu/cdkMenuBar');\n}","typeGuard":"function hasMenuAncestor(el: HTMLElement): boolean {\n  return !!el.closest('[cdkMenu], [cdkMenuBar]');\n}","tryCatchPattern":"try {\n  this._checkConfigured();\n} catch (e) {\n  if ((e as Error).message.includes('PointerFocusTracker')) {\n    console.error('Wrap the item in cdkMenu or cdkMenuBar.');\n  } else { throw e; }\n}","preventionTips":["Always render cdkMenuItem inside a cdkMenu or cdkMenuBar element.","Keep submenu templates attached via the menu trigger's ng-template context.","Avoid portal-hosting menu items outside the menu injector tree.","Add a dev-mode check that menu markup has the menu ancestor."],"tags":["angular","cdk","menu","dependency-injection"],"backgroundTag":"missing-menu-context","analyzedSha":"0411926e7d8ae06b32236ec1048a888cfad5abf2","analyzedAt":"2026-08-31T11:58:23.400Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}