@angular/cdk 18.2.1 → 18.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/fesm2022/a11y.mjs CHANGED
@@ -737,21 +737,31 @@ class FocusKeyManager extends ListKeyManager {
737
737
  * keyboard events occur.
738
738
  */
739
739
  class TreeKeyManager {
740
- _initialFocus() {
741
- if (this._hasInitialFocused) {
740
+ _initializeFocus() {
741
+ if (this._hasInitialFocused || this._items.length === 0) {
742
742
  return;
743
743
  }
744
- if (!this._items.length) {
745
- return;
746
- }
747
- let focusIndex = 0;
744
+ let activeIndex = 0;
748
745
  for (let i = 0; i < this._items.length; i++) {
749
746
  if (!this._skipPredicateFn(this._items[i]) && !this._isItemDisabled(this._items[i])) {
750
- focusIndex = i;
747
+ activeIndex = i;
751
748
  break;
752
749
  }
753
750
  }
754
- this.focusItem(focusIndex);
751
+ const activeItem = this._items[activeIndex];
752
+ // Use `makeFocusable` here, because we want the item to just be focusable, not actually
753
+ // capture the focus since the user isn't interacting with it. See #29628.
754
+ if (activeItem.makeFocusable) {
755
+ this._activeItem?.unfocus();
756
+ this._activeItemIndex = activeIndex;
757
+ this._activeItem = activeItem;
758
+ this._typeahead?.setCurrentSelectedItemIndex(activeIndex);
759
+ activeItem.makeFocusable();
760
+ }
761
+ else {
762
+ // Backwards compatibility for items that don't implement `makeFocusable`.
763
+ this.focusItem(activeIndex);
764
+ }
755
765
  this._hasInitialFocused = true;
756
766
  }
757
767
  /**
@@ -800,7 +810,7 @@ class TreeKeyManager {
800
810
  this._items = newItems.toArray();
801
811
  this._typeahead?.setItems(this._items);
802
812
  this._updateActiveItemIndex(this._items);
803
- this._initialFocus();
813
+ this._initializeFocus();
804
814
  });
805
815
  }
806
816
  else if (isObservable(items)) {
@@ -808,12 +818,12 @@ class TreeKeyManager {
808
818
  this._items = newItems;
809
819
  this._typeahead?.setItems(newItems);
810
820
  this._updateActiveItemIndex(newItems);
811
- this._initialFocus();
821
+ this._initializeFocus();
812
822
  });
813
823
  }
814
824
  else {
815
825
  this._items = items;
816
- this._initialFocus();
826
+ this._initializeFocus();
817
827
  }
818
828
  if (typeof config.shouldActivationFollowFocus === 'boolean') {
819
829
  this._shouldActivationFollowFocus = config.shouldActivationFollowFocus;