()
| 132 | }); |
| 133 | |
| 134 | constructor() { |
| 135 | afterNextRender(() => { |
| 136 | this._collection.startObserving(this.element); |
| 137 | }); |
| 138 | |
| 139 | afterRenderEffect(() => { |
| 140 | this._pattern.setDefaultStateEffect(); |
| 141 | }); |
| 142 | |
| 143 | // This needs to be in an afterRenderEffect to ensure the tabs have all been initialized. |
| 144 | // Otherwise, the lookup here can fail and it does not get re-run afterwards. |
| 145 | afterRenderEffect({ |
| 146 | write: () => { |
| 147 | const pattern = this._selectedTabPattern(); |
| 148 | const tab = this._collection.orderedItems().find(tab => tab._pattern == pattern); |
| 149 | this.selectedTab.set(tab?.value()); |
| 150 | }, |
| 151 | }); |
| 152 | |
| 153 | // Keep the active item in sync when selection changes programmatically while unfocused, |
| 154 | // or when focus leaves the tablist. |
| 155 | afterRenderEffect({ |
| 156 | write: () => { |
| 157 | const selectedTab = this._selectedTabPattern(); |
| 158 | const isFocused = this._pattern.isFocused(); |
| 159 | untracked(() => { |
| 160 | if (selectedTab && !isFocused) { |
| 161 | this._pattern.focusBehavior.sync(selectedTab); |
| 162 | } |
| 163 | }); |
| 164 | }, |
| 165 | }); |
| 166 | |
| 167 | // Ensure that if the active tab is removed from the list, the tablist updates its focus state. |
| 168 | afterRenderEffect({ |
| 169 | write: () => { |
| 170 | const items = this._tabPatterns(); |
| 171 | const activeItem = untracked(() => this._pattern.inputs.activeItem()); |
| 172 | |
| 173 | if (activeItem && !items.includes(activeItem)) { |
| 174 | this._pattern.isFocused.set(false); |
| 175 | this._pattern.setDefaultState(); |
| 176 | } |
| 177 | }, |
| 178 | }); |
| 179 | |
| 180 | // Check for any violations after the DOM has been updated. |
| 181 | if (typeof ngDevMode === 'undefined' || ngDevMode) { |
| 182 | afterRenderEffect({ |
| 183 | read: () => { |
| 184 | const violations: string[] = []; |
| 185 | |
| 186 | const values = this._collection.orderedItems().map(t => t.value()); |
| 187 | const duplicates = values.filter((item, index) => values.indexOf(item) !== index); |
| 188 | if (duplicates.length > 0) { |
| 189 | violations.push(`Duplicate value '${duplicates[0]}' detected inside ngTabList.`); |
| 190 | } |
| 191 |
nothing calls this directly
no test coverage detected