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