@@ -113,6 +113,20 @@ const metadata = {
113
113
type : HTMLElement ,
114
114
propertyName : "items" ,
115
115
} ,
116
+ /**
117
+ * Defines the overflow button of <code>ui5-avatar-group</code>.
118
+ * <b>Note:</b> We recommend using the <code>ui5-button</code> component.
119
+ * <br><br>
120
+ * <b>Note:</b> If this slot is not used, the <code>ui5-avatar-group</code> will
121
+ * display the built-in overflow button.
122
+ * @type {HTMLElement }
123
+ * @slot overflowButton
124
+ * @public
125
+ * @since 1.0.0-rc.13
126
+ */
127
+ overflowButton : {
128
+ type : HTMLElement ,
129
+ } ,
116
130
} ,
117
131
events : /** @lends sap.ui.webcomponents.main.AvatarGroup.prototype */ {
118
132
/**
@@ -130,6 +144,14 @@ const metadata = {
130
144
overflowButtonClicked : { type : Boolean } ,
131
145
} ,
132
146
} ,
147
+ /**
148
+ * Fired when the count of visible <code>ui5-avatar</code> elements in the
149
+ * <code>ui5-avatar-group</code> has changed
150
+ * @event
151
+ * @public
152
+ * @since 1.0.0-rc.13
153
+ */
154
+ overflow : { } ,
133
155
} ,
134
156
} ;
135
157
@@ -241,6 +263,10 @@ class AvatarGroup extends UI5Element {
241
263
return this . items . map ( avatar => avatar . _effectiveBackgroundColor ) ;
242
264
}
243
265
266
+ get _customOverflowButton ( ) {
267
+ return this . overflowButton . length ? this . overflowButton [ 0 ] : undefined ;
268
+ }
269
+
244
270
get _hiddenStartIndex ( ) {
245
271
return this . _itemsCount - this . _hiddenItems ;
246
272
}
@@ -261,10 +287,6 @@ class AvatarGroup extends UI5Element {
261
287
return this . _isGroup ? "0" : "-1" ;
262
288
}
263
289
264
- get _overflowButtonTabIndex ( ) {
265
- return this . _isGroup ? "-1" : false ;
266
- }
267
-
268
290
get _overflowButton ( ) {
269
291
return this . shadowRoot . querySelector ( AVATAR_GROUP_OVERFLOW_BTN_SELECTOR ) ;
270
292
}
@@ -278,26 +300,31 @@ class AvatarGroup extends UI5Element {
278
300
* @private
279
301
*/
280
302
get _overflowButtonEffectiveWidth ( ) {
303
+ const button = this . _customOverflowButton ? this . _customOverflowButton : this . _overflowButton ;
281
304
// if in "Group" mode overflow button size is equal to the offset from second item
282
305
if ( this . _isGroup ) {
283
306
let item = this . items [ 1 ] ;
284
307
285
308
// in some cases when second avatar is overflowed the offset of the button is the right one
286
309
if ( ! item || item . hidden ) {
287
- item = this . _overflowButton ;
310
+ item = button ;
288
311
}
289
312
290
313
return this . effectiveDir === "rtl" ? this . _getWidthToItem ( item ) : item . offsetLeft ;
291
314
}
292
315
293
- return this . _overflowButton . offsetWidth ;
316
+ return button . offsetWidth ;
294
317
}
295
318
296
319
onAfterRendering ( ) {
297
320
this . _overflowItems ( ) ;
298
321
}
299
322
300
323
onBeforeRendering ( ) {
324
+ if ( this . _customOverflowButton ) {
325
+ this . _customOverflowButton . nonInteractive = this . _isGroup ;
326
+ }
327
+
301
328
this . _prepareAvatars ( ) ;
302
329
}
303
330
@@ -332,7 +359,7 @@ class AvatarGroup extends UI5Element {
332
359
}
333
360
334
361
_fireGroupEvent ( targetRef ) {
335
- const isOverflowButtonClicked = targetRef . classList . contains ( OVERFLOW_BTN_CLASS ) ;
362
+ const isOverflowButtonClicked = targetRef . classList . contains ( OVERFLOW_BTN_CLASS ) || targetRef === this . _customOverflowButton ;
336
363
337
364
this . fireEvent ( "click" , {
338
365
targetRef,
@@ -384,7 +411,7 @@ class AvatarGroup extends UI5Element {
384
411
}
385
412
386
413
// last avatar should not be offset as it breaks the container width and focus styles are no set correctly
387
- if ( index !== this . _itemsCount - 1 ) {
414
+ if ( index !== this . _itemsCount - 1 || this . _customOverflowButton ) {
388
415
// based on RTL margin left or right is set to avatars
389
416
avatar . style [ `margin-${ RTL ? "left" : "right" } ` ] = offsets [ avatar . _effectiveSize ] [ this . type ] ;
390
417
}
@@ -437,7 +464,7 @@ class AvatarGroup extends UI5Element {
437
464
// used to determine whether the following items will fit the container or not
438
465
let totalWidth = this . _getWidthToItem ( item ) + item . offsetWidth ;
439
466
440
- if ( index !== this . _itemsCount - 1 ) {
467
+ if ( index !== this . _itemsCount - 1 || this . _customOverflowButton ) {
441
468
totalWidth += this . _overflowButtonEffectiveWidth ;
442
469
}
443
470
@@ -460,13 +487,19 @@ class AvatarGroup extends UI5Element {
460
487
}
461
488
462
489
_setHiddenItems ( hiddenItems ) {
490
+ const shouldFireEvent = this . _hiddenItems !== hiddenItems ;
491
+
463
492
this . _hiddenItems = hiddenItems ;
464
493
465
494
this . items . forEach ( ( item , index ) => {
466
495
item . hidden = index >= this . _hiddenStartIndex ;
467
496
} ) ;
468
497
469
498
this . _overflowButtonText = `+${ hiddenItems > 99 ? 99 : hiddenItems } ` ;
499
+
500
+ if ( shouldFireEvent ) {
501
+ this . fireEvent ( "overflow" ) ;
502
+ }
470
503
}
471
504
}
472
505
0 commit comments