| 73 | |
| 74 | /** The menu ui pattern class. */ |
| 75 | export class MenuPattern<V> { |
| 76 | /** The unique ID of the menu. */ |
| 77 | readonly id: SignalLike<string>; |
| 78 | |
| 79 | /** The role of the menu. */ |
| 80 | readonly role = () => 'menu'; |
| 81 | |
| 82 | /** Whether the menu is disabled. */ |
| 83 | readonly disabled = () => this.inputs.disabled(); |
| 84 | |
| 85 | /** Whether the menu is visible. */ |
| 86 | readonly visible = computed(() => |
| 87 | this.inputs.parent() ? !!this.inputs.parent()?.expanded() : true, |
| 88 | ); |
| 89 | |
| 90 | /** Controls list behavior for the menu items. */ |
| 91 | readonly listBehavior: List<MenuItemPattern<V>, V>; |
| 92 | |
| 93 | /** Whether the menu or any of its child elements are currently focused. */ |
| 94 | readonly isFocused = signal(false); |
| 95 | |
| 96 | /** Whether the menu has received interaction. */ |
| 97 | readonly hasBeenInteracted = signal(false); |
| 98 | |
| 99 | /** Whether the menu trigger has been hovered. */ |
| 100 | readonly hasBeenHovered = signal(false); |
| 101 | |
| 102 | /** Timeout used to open sub-menus on hover. */ |
| 103 | _openTimeout: any; |
| 104 | |
| 105 | /** Timeout used to close sub-menus on hover out. */ |
| 106 | _closeTimeout: any; |
| 107 | |
| 108 | /** The tab index of the menu. */ |
| 109 | readonly tabIndex = () => this.listBehavior.tabIndex(); |
| 110 | |
| 111 | /** Whether the menu should be focused on mouse over. */ |
| 112 | readonly shouldFocus = computed(() => { |
| 113 | const root = this.root(); |
| 114 | |
| 115 | if (root instanceof MenuTriggerPattern) { |
| 116 | return true; |
| 117 | } |
| 118 | |
| 119 | if (root instanceof MenuBarPattern || root instanceof MenuPattern) { |
| 120 | return root.isFocused(); |
| 121 | } |
| 122 | |
| 123 | return false; |
| 124 | }); |
| 125 | |
| 126 | /** The key used to expand sub-menus. */ |
| 127 | private readonly _expandKey = computed(() => { |
| 128 | return this.inputs.textDirection() === 'rtl' ? 'ArrowLeft' : 'ArrowRight'; |
| 129 | }); |
| 130 | |
| 131 | /** The key used to collapse sub-menus. */ |
| 132 | private readonly _collapseKey = computed(() => { |
nothing calls this directly
no test coverage detected