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