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