Skip to content

Commit 1d17d50

Browse files
authored
fix(ui5-avatar-group): use getSlottedNodes for transitive slot support (#13049)
1 parent 3e10f22 commit 1d17d50

1 file changed

Lines changed: 18 additions & 10 deletions

File tree

packages/main/src/AvatarGroup.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -259,12 +259,20 @@ class AvatarGroup extends UI5Element {
259259
_hiddenItems = 0;
260260
_itemNavigation: ItemNavigation;
261261

262+
/**
263+
* Returns the actual avatar items, handling transitive slotting.
264+
* @private
265+
*/
266+
get _slottedItems(): IAvatarGroupItem[] {
267+
return this.getSlottedNodes<IAvatarGroupItem>("items");
268+
}
269+
262270
constructor() {
263271
super();
264272

265273
this._itemNavigation = new ItemNavigation(this, {
266274
getItemsCallback: () => {
267-
return this._isGroup ? [] : this.items.slice(0, this._hiddenStartIndex);
275+
return this._isGroup ? [] : this._slottedItems.slice(0, this._hiddenStartIndex);
268276
},
269277
});
270278
this._onResizeHandler = this._onResize.bind(this);
@@ -276,7 +284,7 @@ class AvatarGroup extends UI5Element {
276284
* @public
277285
*/
278286
get hiddenItems(): IAvatarGroupItem[] {
279-
return this.items.slice(this._hiddenStartIndex);
287+
return this._slottedItems.slice(this._hiddenStartIndex);
280288
}
281289

282290
/**
@@ -285,7 +293,7 @@ class AvatarGroup extends UI5Element {
285293
* @public
286294
*/
287295
get colorScheme(): AvatarColorScheme[] {
288-
return this.items.map(avatar => avatar.effectiveBackgroundColor);
296+
return this._slottedItems.map(avatar => avatar.effectiveBackgroundColor);
289297
}
290298

291299
get _customOverflowButton() {
@@ -348,7 +356,7 @@ class AvatarGroup extends UI5Element {
348356
}
349357

350358
get _itemsCount() {
351-
return this.items.length;
359+
return this._slottedItems.length;
352360
}
353361

354362
get _groupTabIndex() {
@@ -376,7 +384,7 @@ class AvatarGroup extends UI5Element {
376384
}
377385

378386
if (this._isGroup) {
379-
let item: HTMLElement = this.items[1];
387+
let item: HTMLElement = this._slottedItems[1];
380388
const ltrEffectiveWidth = item.offsetLeft - this.offsetLeft;
381389

382390
// in some cases when second avatar is overflowed the offset of the button is the right one
@@ -391,7 +399,7 @@ class AvatarGroup extends UI5Element {
391399
}
392400

393401
get firstAvatarSize() {
394-
return this.items[0]?.size ?? AvatarSize.S;
402+
return this._slottedItems[0]?.size ?? AvatarSize.S;
395403
}
396404

397405
onAfterRendering() {
@@ -483,7 +491,7 @@ class AvatarGroup extends UI5Element {
483491
_prepareAvatars() {
484492
this._colorIndex = 0;
485493

486-
this.items.forEach((avatar, index) => {
494+
this._slottedItems.forEach((avatar, index) => {
487495
const colorIndex = this._getNextBackgroundColor();
488496
avatar.interactive = !this._isGroup;
489497

@@ -541,7 +549,7 @@ class AvatarGroup extends UI5Element {
541549
* @private
542550
*/
543551
_overflowItems() {
544-
if (this.items.length < 2) {
552+
if (this._slottedItems.length < 2) {
545553
// no need to overflow avatars
546554
this._setHiddenItems(0);
547555
return;
@@ -550,7 +558,7 @@ class AvatarGroup extends UI5Element {
550558
let hiddenItems = 0;
551559

552560
for (let index = 0; index < this._itemsCount; index++) {
553-
const item: IAvatarGroupItem = this.items[index];
561+
const item: IAvatarGroupItem = this._slottedItems[index];
554562

555563
// show item to determine if it will fit the new container size
556564
item.hidden = false;
@@ -586,7 +594,7 @@ class AvatarGroup extends UI5Element {
586594

587595
this._hiddenItems = hiddenItems;
588596

589-
this.items.forEach((item, index) => {
597+
this._slottedItems.forEach((item, index) => {
590598
item.hidden = index >= this._hiddenStartIndex;
591599
});
592600

0 commit comments

Comments
 (0)