| 23 | |
| 24 | /** Controls the state of a toolbar. */ |
| 25 | export class ToolbarPattern<V> { |
| 26 | /** The list behavior for the toolbar. */ |
| 27 | readonly listBehavior: List<ToolbarWidgetPattern<V>, V>; |
| 28 | |
| 29 | /** Whether the toolbar has been interacted with. */ |
| 30 | readonly hasBeenInteracted = signal(false); |
| 31 | |
| 32 | /** Whether the tablist is vertically or horizontally oriented. */ |
| 33 | readonly orientation: SignalLike<'vertical' | 'horizontal'>; |
| 34 | |
| 35 | /** Whether disabled items in the group should be focusable. */ |
| 36 | readonly softDisabled: SignalLike<boolean>; |
| 37 | |
| 38 | /** Whether the toolbar is disabled. */ |
| 39 | readonly disabled = computed(() => this.listBehavior.disabled()); |
| 40 | |
| 41 | /** The tab index of the toolbar (if using activedescendant). */ |
| 42 | readonly tabIndex = computed(() => this.listBehavior.tabIndex()); |
| 43 | |
| 44 | /** The id of the current active widget (if using activedescendant). */ |
| 45 | readonly activeDescendant = computed(() => this.listBehavior.activeDescendant()); |
| 46 | |
| 47 | /** The currently active item in the toolbar. */ |
| 48 | readonly activeItem = () => this.listBehavior.inputs.activeItem(); |
| 49 | |
| 50 | /** The key used to navigate to the previous widget. */ |
| 51 | private readonly _prevKey = computed(() => { |
| 52 | if (this.inputs.orientation() === 'vertical') { |
| 53 | return 'ArrowUp'; |
| 54 | } |
| 55 | return this.inputs.textDirection() === 'rtl' ? 'ArrowRight' : 'ArrowLeft'; |
| 56 | }); |
| 57 | |
| 58 | /** The key used to navigate to the next widget. */ |
| 59 | private readonly _nextKey = computed(() => { |
| 60 | if (this.inputs.orientation() === 'vertical') { |
| 61 | return 'ArrowDown'; |
| 62 | } |
| 63 | return this.inputs.textDirection() === 'rtl' ? 'ArrowLeft' : 'ArrowRight'; |
| 64 | }); |
| 65 | |
| 66 | /** The alternate key used to navigate to the previous widget. */ |
| 67 | private readonly _altPrevKey = computed(() => { |
| 68 | if (this.inputs.orientation() === 'vertical') { |
| 69 | return this.inputs.textDirection() === 'rtl' ? 'ArrowRight' : 'ArrowLeft'; |
| 70 | } |
| 71 | return 'ArrowUp'; |
| 72 | }); |
| 73 | |
| 74 | /** The alternate key used to navigate to the next widget. */ |
| 75 | private readonly _altNextKey = computed(() => { |
| 76 | if (this.inputs.orientation() === 'vertical') { |
| 77 | return this.inputs.textDirection() === 'rtl' ? 'ArrowLeft' : 'ArrowRight'; |
| 78 | } |
| 79 | return 'ArrowDown'; |
| 80 | }); |
| 81 | |
| 82 | /** The keydown event manager for the toolbar. */ |
nothing calls this directly
no test coverage detected