Skip to content

Commit

Permalink
fix(ui5-avatar-group): width calculations for (non-)Chromium browsers…
Browse files Browse the repository at this point in the history
… adjusted (#5737)

Fixes #5643
  • Loading branch information
stbodurov authored Aug 29, 2022
1 parent 36cb3d2 commit 2741705
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
22 changes: 20 additions & 2 deletions packages/main/src/AvatarGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
isEnter,
isSpace,
} from "@ui5/webcomponents-base/dist/Keys.js";
import { isChrome } from "@ui5/webcomponents-base/dist/Device.js";

import {
AVATAR_GROUP_DISPLAYED_HIDDEN_LABEL,
Expand Down Expand Up @@ -376,13 +377,21 @@ class AvatarGroup extends UI5Element {
// if in "Group" mode overflow button size is equal to the offset from second item
if (this._isGroup) {
let item = this.items[1];
let ltrEffectiveWidth;

// in some cases when second avatar is overflowed the offset of the button is the right one
if (!item || item.hidden) {
item = button;
}

return this.effectiveDir === "rtl" ? this._getWidthToItem(item) : item.offsetLeft - this.offsetLeft;
ltrEffectiveWidth = item.offsetLeft;

if (!isChrome()) {
// additional subtractions required for non-Chromium browsers
ltrEffectiveWidth = item.offsetLeft - this.offsetLeft;
}

return this.effectiveDir === "rtl" ? this._getWidthToItem(item) : ltrEffectiveWidth;
}

return button.offsetWidth;
Expand Down Expand Up @@ -518,6 +527,7 @@ class AvatarGroup extends UI5Element {
*/
_getWidthToItem(item) {
const isRTL = this.effectiveDir === "rtl";
let ltrWidthToItem;

if (isRTL) {
// in RTL the total width is equal to difference of the parent container width and
Expand All @@ -526,7 +536,15 @@ class AvatarGroup extends UI5Element {
}

// in LTR the width is equal to item.offsetLeft
return item.offsetLeft - this.offsetLeft;
ltrWidthToItem = item.offsetLeft;

if (!isChrome()) {
// for non-Chromium browsers offsetLeft may differ
// to normalize it, the Avatar Group's offset-left is subtracted
ltrWidthToItem = item.offsetLeft - this.offsetLeft;
}

return ltrWidthToItem;
}

/**
Expand Down
1 change: 1 addition & 0 deletions packages/main/src/themes/AvatarGroup.css
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
border-radius: 50%;
display: inline-flex;
text-overflow: initial;
z-index: 0; /* prevent last visible avatar from covering half of the button */
}

::slotted([ui5-button][focused]),
Expand Down

0 comments on commit 2741705

Please sign in to comment.