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