| 50 | |
| 51 | /** Controls the state of a toolbar. */ |
| 52 | export class ToolbarPattern { |
| 53 | /** Controls focus for the toolbar. */ |
| 54 | readonly focusManager: ListFocus<ToolbarWidgetPattern>; |
| 55 | |
| 56 | /** Controls navigation for the toolbar. */ |
| 57 | readonly navigationBehavior: ListNavigation<ToolbarWidgetPattern>; |
| 58 | |
| 59 | /** Whether the toolbar has been interacted with. */ |
| 60 | readonly hasBeenInteracted = signal(false); |
| 61 | |
| 62 | /** Whether the toolbar is vertically or horizontally oriented. */ |
| 63 | readonly orientation: SignalLike<'vertical' | 'horizontal'>; |
| 64 | |
| 65 | /** Whether disabled items in the group should be focusable. */ |
| 66 | readonly softDisabled: SignalLike<boolean>; |
| 67 | |
| 68 | /** Whether the toolbar is disabled. */ |
| 69 | readonly disabled = computed(() => this.focusManager.isListDisabled()); |
| 70 | |
| 71 | /** The tab index of the toolbar. */ |
| 72 | readonly tabIndex = computed(() => this.focusManager.getListTabIndex()); |
| 73 | |
| 74 | /** The id of the current active widget. */ |
| 75 | readonly activeDescendant = computed(() => this.focusManager.getActiveDescendant()); |
| 76 | |
| 77 | /** The currently active item in the toolbar. */ |
| 78 | readonly activeItem = () => this.inputs.activeItem(); |
| 79 | |
| 80 | /** The key used to navigate to the previous widget. */ |
| 81 | private readonly _prevKey = computed(() => { |
| 82 | if (this.inputs.orientation() === 'vertical') { |
| 83 | return 'ArrowUp'; |
| 84 | } |
| 85 | return this.inputs.textDirection() === 'rtl' ? 'ArrowRight' : 'ArrowLeft'; |
| 86 | }); |
| 87 | |
| 88 | /** The key used to navigate to the next widget. */ |
| 89 | private readonly _nextKey = computed(() => { |
| 90 | if (this.inputs.orientation() === 'vertical') { |
| 91 | return 'ArrowDown'; |
| 92 | } |
| 93 | return this.inputs.textDirection() === 'rtl' ? 'ArrowLeft' : 'ArrowRight'; |
| 94 | }); |
| 95 | |
| 96 | /** The alternate key used to navigate to the previous widget. */ |
| 97 | private readonly _altPrevKey = computed(() => { |
| 98 | if (this.inputs.orientation() === 'vertical') { |
| 99 | return this.inputs.textDirection() === 'rtl' ? 'ArrowRight' : 'ArrowLeft'; |
| 100 | } |
| 101 | return 'ArrowUp'; |
| 102 | }); |
| 103 | |
| 104 | /** The alternate key used to navigate to the next widget. */ |
| 105 | private readonly _altNextKey = computed(() => { |
| 106 | if (this.inputs.orientation() === 'vertical') { |
| 107 | return this.inputs.textDirection() === 'rtl' ? 'ArrowLeft' : 'ArrowRight'; |
| 108 | } |
| 109 | return 'ArrowDown'; |
nothing calls this directly
no test coverage detected