| 757 | |
| 758 | /** The menu item ui pattern class. */ |
| 759 | export class MenuItemPattern<V> implements ListItem<V> { |
| 760 | /** The value of the menu item. */ |
| 761 | readonly value: SignalLike<V>; |
| 762 | |
| 763 | /** The unique ID of the menu item. */ |
| 764 | readonly id: SignalLike<string>; |
| 765 | |
| 766 | /** Whether the menu item is disabled. */ |
| 767 | readonly disabled = () => this.inputs.parent()?.disabled() || this.inputs.disabled(); |
| 768 | |
| 769 | /** The search term for the menu item. */ |
| 770 | readonly searchTerm: SignalLike<string>; |
| 771 | |
| 772 | /** The element of the menu item. */ |
| 773 | readonly element: SignalLike<HTMLElement | undefined>; |
| 774 | |
| 775 | /** Whether the menu item is active. */ |
| 776 | readonly active = computed(() => this.inputs.parent()?.inputs.activeItem() === this); |
| 777 | |
| 778 | /** Whether the menu item has received interaction. */ |
| 779 | readonly hasBeenInteracted = signal(false); |
| 780 | |
| 781 | /** The tab index of the menu item. */ |
| 782 | readonly tabIndex = computed(() => { |
| 783 | if (this.submenu() && this.submenu()?.inputs.activeItem()) { |
| 784 | return -1; |
| 785 | } |
| 786 | return this.inputs.parent()?.listBehavior.getItemTabindex(this) ?? -1; |
| 787 | }); |
| 788 | |
| 789 | /** The position of the menu item in the menu. */ |
| 790 | readonly index = computed(() => this.inputs.parent()?.inputs.items().indexOf(this) ?? -1); |
| 791 | |
| 792 | /** Whether the menu item is expanded. */ |
| 793 | readonly expanded = computed(() => (this.submenu() ? this._expanded() : null)); |
| 794 | |
| 795 | /** Whether the menu item is expanded. */ |
| 796 | readonly _expanded = signal(false); |
| 797 | |
| 798 | /** The ID of the menu that the menu item controls. */ |
| 799 | readonly controls = signal<string | undefined>(undefined); |
| 800 | |
| 801 | /** The role of the menu item. */ |
| 802 | readonly role = () => this.inputs.role(); |
| 803 | |
| 804 | /** Whether the menu item has a popup. */ |
| 805 | readonly hasPopup = computed(() => !!this.submenu()); |
| 806 | |
| 807 | /** The submenu associated with the menu item. */ |
| 808 | readonly submenu: SignalLike<MenuPattern<V> | undefined>; |
| 809 | |
| 810 | /** Whether the menu item is selectable. */ |
| 811 | readonly selectable: SignalLike<boolean>; |
| 812 | |
| 813 | constructor(readonly inputs: MenuItemInputs<V>) { |
| 814 | this.id = inputs.id; |
| 815 | this.value = inputs.value; |
| 816 | this.element = inputs.element; |
nothing calls this directly
no test coverage detected
searching dependent graphs…