@@ -113,6 +113,20 @@ const metadata = {
113113 type : HTMLElement ,
114114 propertyName : "items" ,
115115 } ,
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+ } ,
116130 } ,
117131 events : /** @lends sap.ui.webcomponents.main.AvatarGroup.prototype */ {
118132 /**
@@ -130,6 +144,14 @@ const metadata = {
130144 overflowButtonClicked : { type : Boolean } ,
131145 } ,
132146 } ,
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 : { } ,
133155 } ,
134156} ;
135157
@@ -241,6 +263,10 @@ class AvatarGroup extends UI5Element {
241263 return this . items . map ( avatar => avatar . _effectiveBackgroundColor ) ;
242264 }
243265
266+ get _customOverflowButton ( ) {
267+ return this . overflowButton . length ? this . overflowButton [ 0 ] : undefined ;
268+ }
269+
244270 get _hiddenStartIndex ( ) {
245271 return this . _itemsCount - this . _hiddenItems ;
246272 }
@@ -261,10 +287,6 @@ class AvatarGroup extends UI5Element {
261287 return this . _isGroup ? "0" : "-1" ;
262288 }
263289
264- get _overflowButtonTabIndex ( ) {
265- return this . _isGroup ? "-1" : false ;
266- }
267-
268290 get _overflowButton ( ) {
269291 return this . shadowRoot . querySelector ( AVATAR_GROUP_OVERFLOW_BTN_SELECTOR ) ;
270292 }
@@ -278,26 +300,31 @@ class AvatarGroup extends UI5Element {
278300 * @private
279301 */
280302 get _overflowButtonEffectiveWidth ( ) {
303+ const button = this . _customOverflowButton ? this . _customOverflowButton : this . _overflowButton ;
281304 // if in "Group" mode overflow button size is equal to the offset from second item
282305 if ( this . _isGroup ) {
283306 let item = this . items [ 1 ] ;
284307
285308 // in some cases when second avatar is overflowed the offset of the button is the right one
286309 if ( ! item || item . hidden ) {
287- item = this . _overflowButton ;
310+ item = button ;
288311 }
289312
290313 return this . effectiveDir === "rtl" ? this . _getWidthToItem ( item ) : item . offsetLeft ;
291314 }
292315
293- return this . _overflowButton . offsetWidth ;
316+ return button . offsetWidth ;
294317 }
295318
296319 onAfterRendering ( ) {
297320 this . _overflowItems ( ) ;
298321 }
299322
300323 onBeforeRendering ( ) {
324+ if ( this . _customOverflowButton ) {
325+ this . _customOverflowButton . nonInteractive = this . _isGroup ;
326+ }
327+
301328 this . _prepareAvatars ( ) ;
302329 }
303330
@@ -332,7 +359,7 @@ class AvatarGroup extends UI5Element {
332359 }
333360
334361 _fireGroupEvent ( targetRef ) {
335- const isOverflowButtonClicked = targetRef . classList . contains ( OVERFLOW_BTN_CLASS ) ;
362+ const isOverflowButtonClicked = targetRef . classList . contains ( OVERFLOW_BTN_CLASS ) || targetRef === this . _customOverflowButton ;
336363
337364 this . fireEvent ( "click" , {
338365 targetRef,
@@ -384,7 +411,7 @@ class AvatarGroup extends UI5Element {
384411 }
385412
386413 // 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 ) {
388415 // based on RTL margin left or right is set to avatars
389416 avatar . style [ `margin-${ RTL ? "left" : "right" } ` ] = offsets [ avatar . _effectiveSize ] [ this . type ] ;
390417 }
@@ -437,7 +464,7 @@ class AvatarGroup extends UI5Element {
437464 // used to determine whether the following items will fit the container or not
438465 let totalWidth = this . _getWidthToItem ( item ) + item . offsetWidth ;
439466
440- if ( index !== this . _itemsCount - 1 ) {
467+ if ( index !== this . _itemsCount - 1 || this . _customOverflowButton ) {
441468 totalWidth += this . _overflowButtonEffectiveWidth ;
442469 }
443470
@@ -460,13 +487,19 @@ class AvatarGroup extends UI5Element {
460487 }
461488
462489 _setHiddenItems ( hiddenItems ) {
490+ const shouldFireEvent = this . _hiddenItems !== hiddenItems ;
491+
463492 this . _hiddenItems = hiddenItems ;
464493
465494 this . items . forEach ( ( item , index ) => {
466495 item . hidden = index >= this . _hiddenStartIndex ;
467496 } ) ;
468497
469498 this . _overflowButtonText = `+${ hiddenItems > 99 ? 99 : hiddenItems } ` ;
499+
500+ if ( shouldFireEvent ) {
501+ this . fireEvent ( "overflow" ) ;
502+ }
470503 }
471504}
472505
0 commit comments