@@ -12,7 +12,7 @@ import {SignalLike} from '../behaviors/signal-like/signal-like';
1212import { List , ListInputs , ListItem } from '../behaviors/list/list' ;
1313
1414/** The inputs for the MenuBarPattern class. */
15- export interface MenuBarInputs < V > extends Omit < ListInputs < MenuItemPattern < V > , V > , 'disabled' > {
15+ export interface MenuBarInputs < V > extends ListInputs < MenuItemPattern < V > , V > {
1616 /** The menu items contained in the menu. */
1717 items : SignalLike < MenuItemPattern < V > [ ] > ;
1818
@@ -24,8 +24,7 @@ export interface MenuBarInputs<V> extends Omit<ListInputs<MenuItemPattern<V>, V>
2424}
2525
2626/** The inputs for the MenuPattern class. */
27- export interface MenuInputs < V >
28- extends Omit < ListInputs < MenuItemPattern < V > , V > , 'values' | 'disabled' > {
27+ export interface MenuInputs < V > extends Omit < ListInputs < MenuItemPattern < V > , V > , 'values' > {
2928 /** The unique ID of the menu. */
3029 id : SignalLike < string > ;
3130
@@ -55,6 +54,9 @@ export interface MenuTriggerInputs<V> {
5554
5655 /** The text direction of the menu bar. */
5756 textDirection : SignalLike < 'ltr' | 'rtl' > ;
57+
58+ /** Whether the menu trigger is disabled. */
59+ disabled : SignalLike < boolean > ;
5860}
5961
6062/** The inputs for the MenuItemPattern class. */
@@ -74,6 +76,9 @@ export class MenuPattern<V> {
7476 /** The role of the menu. */
7577 role = ( ) => 'menu' ;
7678
79+ /** Whether the menu is disabled. */
80+ disabled = ( ) => this . inputs . disabled ( ) ;
81+
7782 /** Whether the menu is visible. */
7883 isVisible = computed ( ( ) => ( this . inputs . parent ( ) ? ! ! this . inputs . parent ( ) ?. expanded ( ) : true ) ) ;
7984
@@ -92,6 +97,9 @@ export class MenuPattern<V> {
9297 /** Timeout used to close sub-menus on hover out. */
9398 _closeTimeout : any ;
9499
100+ /** The tab index of the menu. */
101+ tabIndex = ( ) => this . listBehavior . tabIndex ( ) ;
102+
95103 /** Whether the menu should be focused on mouse over. */
96104 shouldFocus = computed ( ( ) => {
97105 const root = this . root ( ) ;
@@ -166,14 +174,13 @@ export class MenuPattern<V> {
166174 this . listBehavior = new List < MenuItemPattern < V > , V > ( {
167175 ...inputs ,
168176 values : signal ( [ ] ) ,
169- disabled : ( ) => false ,
170177 } ) ;
171178 }
172179
173180 /** Sets the default state for the menu. */
174181 setDefaultState ( ) {
175182 if ( ! this . inputs . parent ( ) ) {
176- this . inputs . activeItem . set ( this . inputs . items ( ) [ 0 ] ) ;
183+ this . listBehavior . goto ( this . inputs . items ( ) [ 0 ] , { focusElement : false } ) ;
177184 }
178185 }
179186
@@ -225,7 +232,7 @@ export class MenuPattern<V> {
225232 this . _closeTimeout = setTimeout ( ( ) => {
226233 item . close ( ) ;
227234 this . _closeTimeout = undefined ;
228- } , this . inputs . expansionDelay ( ) ) ;
235+ } , this . inputs . expansionDelay ( ) * 1000 ) ;
229236 }
230237 }
231238
@@ -236,7 +243,7 @@ export class MenuPattern<V> {
236243 this . _openTimeout = setTimeout ( ( ) => {
237244 item . open ( ) ;
238245 this . _openTimeout = undefined ;
239- } , this . inputs . expansionDelay ( ) ) ;
246+ } , this . inputs . expansionDelay ( ) * 1000 ) ;
240247 }
241248
242249 /** Handles mouseout events for the menu. */
@@ -445,6 +452,9 @@ export class MenuBarPattern<V> {
445452 /** Controls list behavior for the menu items. */
446453 listBehavior : List < MenuItemPattern < V > , V > ;
447454
455+ /** The tab index of the menu. */
456+ tabIndex = ( ) => this . listBehavior . tabIndex ( ) ;
457+
448458 /** The key used to navigate to the next item. */
449459 private _nextKey = computed ( ( ) => {
450460 return this . inputs . textDirection ( ) === 'rtl' ? 'ArrowLeft' : 'ArrowRight' ;
@@ -467,6 +477,9 @@ export class MenuBarPattern<V> {
467477 /** Whether the menubar has been focused. */
468478 hasBeenFocused = signal ( false ) ;
469479
480+ /** Whether the menubar is disabled. */
481+ disabled = ( ) => this . inputs . disabled ( ) ;
482+
470483 /** Handles keyboard events for the menu. */
471484 keydownManager = computed ( ( ) => {
472485 return new KeyboardEventManager ( )
@@ -482,7 +495,7 @@ export class MenuBarPattern<V> {
482495 } ) ;
483496
484497 constructor ( readonly inputs : MenuBarInputs < V > ) {
485- this . listBehavior = new List < MenuItemPattern < V > , V > ( { ... inputs , disabled : ( ) => false } ) ;
498+ this . listBehavior = new List < MenuItemPattern < V > , V > ( inputs ) ;
486499 }
487500
488501 /** Sets the default state for the menubar. */
@@ -598,6 +611,9 @@ export class MenuTriggerPattern<V> {
598611 /** The tab index of the menu trigger. */
599612 tabIndex = computed ( ( ) => ( this . expanded ( ) && this . menu ( ) ?. inputs . activeItem ( ) ? - 1 : 0 ) ) ;
600613
614+ /** Whether the menu trigger is disabled. */
615+ disabled = ( ) => this . inputs . disabled ( ) ;
616+
601617 /** Handles keyboard events for the menu trigger. */
602618 keydownManager = computed ( ( ) => {
603619 return new KeyboardEventManager ( )
@@ -614,12 +630,16 @@ export class MenuTriggerPattern<V> {
614630
615631 /** Handles keyboard events for the menu trigger. */
616632 onKeydown ( event : KeyboardEvent ) {
617- this . keydownManager ( ) . handle ( event ) ;
633+ if ( ! this . inputs . disabled ( ) ) {
634+ this . keydownManager ( ) . handle ( event ) ;
635+ }
618636 }
619637
620638 /** Handles click events for the menu trigger. */
621639 onClick ( ) {
622- this . expanded ( ) ? this . close ( ) : this . open ( { first : true } ) ;
640+ if ( ! this . inputs . disabled ( ) ) {
641+ this . expanded ( ) ? this . close ( ) : this . open ( { first : true } ) ;
642+ }
623643 }
624644
625645 /** Handles focusin events for the menu trigger. */
@@ -681,7 +701,7 @@ export class MenuItemPattern<V> implements ListItem<V> {
681701 id : SignalLike < string > ;
682702
683703 /** Whether the menu item is disabled. */
684- disabled : SignalLike < boolean > ;
704+ disabled = ( ) => this . inputs . parent ( ) ?. disabled ( ) || this . inputs . disabled ( ) ;
685705
686706 /** The search term for the menu item. */
687707 searchTerm : SignalLike < string > ;
@@ -731,14 +751,17 @@ export class MenuItemPattern<V> implements ListItem<V> {
731751 this . id = inputs . id ;
732752 this . value = inputs . value ;
733753 this . element = inputs . element ;
734- this . disabled = inputs . disabled ;
735754 this . submenu = this . inputs . submenu ;
736755 this . searchTerm = inputs . searchTerm ;
737756 this . selectable = computed ( ( ) => ! this . submenu ( ) ) ;
738757 }
739758
740759 /** Opens the submenu. */
741760 open ( opts ?: { first ?: boolean ; last ?: boolean } ) {
761+ if ( this . disabled ( ) ) {
762+ return ;
763+ }
764+
742765 this . _expanded . set ( true ) ;
743766
744767 if ( opts ?. first ) {
0 commit comments