* Sets the listbox to it's default initial state. * * Sets the active index of the listbox to the first focusable selected * item if one exists. Otherwise, sets focus to the first focusable item. * * This method should be called once the listbox and it's options are properly initializ
()
| 265 | * is called. |
| 266 | */ |
| 267 | setDefaultState() { |
| 268 | let firstItem: OptionPattern<V> | null = null; |
| 269 | |
| 270 | for (const item of this.inputs.items()) { |
| 271 | if (this.listBehavior.isFocusable(item)) { |
| 272 | if (!firstItem) { |
| 273 | firstItem = item; |
| 274 | } |
| 275 | if (item.selected()) { |
| 276 | this.inputs.activeItem.set(item); |
| 277 | return; |
| 278 | } |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | if (firstItem) { |
| 283 | this.inputs.activeItem.set(firstItem); |
| 284 | if (this.followFocus()) { |
| 285 | this.listBehavior.select(); |
| 286 | } |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | /** |
| 291 | * Sets the default active state of the listbox before receiving interaction for the first time. |
no test coverage detected