* Focuses the first chip in this chip grid, or the associated input when there * are no eligible chips.
()
| 323 | * are no eligible chips. |
| 324 | */ |
| 325 | override focus(): void { |
| 326 | if (this.disabled || this._chipInput?.focused) { |
| 327 | return; |
| 328 | } |
| 329 | |
| 330 | if (!this._chips.length || this._chips.first.disabled) { |
| 331 | if (!this._chipInput) { |
| 332 | return; |
| 333 | } |
| 334 | |
| 335 | // Delay until the next tick, because this can cause a "changed after checked" |
| 336 | // error if the input does something on focus (e.g. opens an autocomplete). |
| 337 | Promise.resolve().then(() => this._chipInput!.focus()); |
| 338 | } else { |
| 339 | const activeItem = this._keyManager.activeItem; |
| 340 | |
| 341 | if (activeItem) { |
| 342 | activeItem.focus(); |
| 343 | } else { |
| 344 | this._keyManager.setFirstItemActive(); |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | this.stateChanges.next(); |
| 349 | } |
| 350 | |
| 351 | /** |
| 352 | * Implemented as part of MatFormFieldControl. |
no test coverage detected