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

Class MenuItemPattern

src/aria/private/menu/menu.ts:799–934  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

797
798/** The menu item ui pattern class. */
799export class MenuItemPattern<V> implements ListItem<V | undefined> {
800 /** The value of the menu item. */
801 readonly value: SignalLike<V | undefined>;
802
803 /** The unique ID of the menu item. */
804 readonly id: SignalLike<string>;
805
806 /** Whether the menu item is disabled. */
807 readonly disabled = () => this.inputs.parent()?.disabled() || this.inputs.disabled();
808
809 /** The search term for the menu item. */
810 readonly searchTerm: SignalLike<string>;
811
812 /** The element of the menu item. */
813 readonly element: SignalLike<HTMLElement | undefined>;
814
815 /** Whether the menu item is active. */
816 readonly active = computed(() => this.inputs.parent()?.inputs.activeItem() === this);
817
818 /** Whether the menu item has received interaction. */
819 readonly hasBeenInteracted = signal(false);
820
821 /** The tab index of the menu item. */
822 readonly tabIndex = computed(() => {
823 if (this.submenu() && this.submenu()?.inputs.activeItem()) {
824 return -1;
825 }
826 return this.inputs.parent()?.listBehavior.getItemTabindex(this) ?? -1;
827 });
828
829 /** The position of the menu item in the menu. */
830 readonly index = computed(() => this.inputs.parent()?.inputs.items().indexOf(this) ?? -1);
831
832 /** Whether the menu item is expanded. */
833 readonly expanded = computed(() => (this.submenu() ? this._expanded() : null));
834
835 /** Whether the menu item is expanded. */
836 readonly _expanded = signal(false);
837
838 /** The ID of the menu that the menu item controls. */
839 readonly controls = signal<string | undefined>(undefined);
840
841 /** The role of the menu item. */
842 readonly role = () => this.inputs.role();
843
844 /** Whether the menu item has a popup. */
845 readonly hasPopup = computed(() => !!this.submenu());
846
847 /** The submenu associated with the menu item. */
848 readonly submenu: SignalLike<MenuPattern<V> | undefined>;
849
850 /** Whether the menu item is selectable. */
851 readonly selectable: SignalLike<boolean>;
852
853 /** The pending focus target when the submenu is opened before the submenu instance is available. */
854 readonly pendingFocus = signal<'first' | 'last' | null>(null);
855
856 constructor(readonly inputs: MenuItemInputs<V>) {

Callers

nothing calls this directly

Calls 7

computedFunction · 0.90
signalFunction · 0.90
parentMethod · 0.80
activeItemMethod · 0.80
disabledMethod · 0.45
getItemTabindexMethod · 0.45
roleMethod · 0.45

Tested by

no test coverage detected