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