* Synchronizes the internal state of the component based on a specific selected date. * @param value Currently selected date. * @param options Options rendered out in the timepicker. * @param fallback Option to set as active if no option is selected.
(
value: D | null,
options: readonly MatOption[],
fallback: MatOption | null,
)
| 433 | * @param fallback Option to set as active if no option is selected. |
| 434 | */ |
| 435 | private _syncSelectedState( |
| 436 | value: D | null, |
| 437 | options: readonly MatOption[], |
| 438 | fallback: MatOption | null, |
| 439 | ): void { |
| 440 | let hasSelected = false; |
| 441 | |
| 442 | for (const option of options) { |
| 443 | if (value && this._dateAdapter.sameTime(option.value, value)) { |
| 444 | option.select(false); |
| 445 | scrollOptionIntoView(option, 'center'); |
| 446 | untracked(() => this._keyManager.setActiveItem(option)); |
| 447 | hasSelected = true; |
| 448 | } else { |
| 449 | option.deselect(false); |
| 450 | } |
| 451 | } |
| 452 | |
| 453 | // If no option was selected, we need to reset the key manager since |
| 454 | // it might be holding onto an option that no longer exists. |
| 455 | if (!hasSelected) { |
| 456 | if (fallback) { |
| 457 | untracked(() => this._keyManager.setActiveItem(fallback)); |
| 458 | scrollOptionIntoView(fallback, 'center'); |
| 459 | } else { |
| 460 | untracked(() => this._keyManager.setActiveItem(-1)); |
| 461 | } |
| 462 | } |
| 463 | } |
| 464 | |
| 465 | /** Handles keyboard events while the overlay is open. */ |
| 466 | private _handleKeydown(event: KeyboardEvent): void { |
no test coverage detected