Skip to content

Commit

Permalink
feat(ui5-toolbar): fixed spacer behavior
Browse files Browse the repository at this point in the history
There was a bug where if there is a spacer before the last item, the
last item would always overflow.
This change fixes the issue

Fixes: SAP#10104
  • Loading branch information
plamenivanov91 committed Nov 13, 2024
1 parent 4382d4e commit 11f002c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
11 changes: 9 additions & 2 deletions packages/main/src/Toolbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,14 +384,15 @@ class Toolbar extends UI5Element {
processOverflowLayout() {
const containerWidth = this.offsetWidth - this.padding;
const contentWidth = this.itemsWidth;
const overflowSpace = contentWidth - containerWidth + this.overflowButtonSize;

// skip calculation if the width has not been changed or if the items width has not been changed
if (this.width === containerWidth && this.contentWidth === contentWidth) {
return;
}

this.distributeItems(overflowSpace);
// if there is not enough space, distribute items while calculating overflow button. Otherwise don't calc overflow space/area
this.distributeItems(contentWidth > containerWidth ? contentWidth - containerWidth + this.overflowButtonSize : 0);

this.width = containerWidth;
this.contentWidth = contentWidth;
}
Expand Down Expand Up @@ -505,6 +506,12 @@ class Toolbar extends UI5Element {
}

this.closeOverflow();

// re-calculate items width if there is a dynamic spacer
if (this.hasFlexibleSpacers) {
this.storeItemsWidth();
}

this.processOverflowLayout();
}

Expand Down
2 changes: 1 addition & 1 deletion packages/main/src/ToolbarSpacer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ToolbarSpacer extends ToolbarItem {
}

get hasFlexibleWidth() {
return this.width === "";
return this.width === undefined || this.width === "auto";
}

static get toolbarTemplate() {
Expand Down
11 changes: 11 additions & 0 deletions packages/main/test/pages/Toolbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@
</head>
<body>
<div id="toolbars-container">

<ui5-toolbar>
<ui5-toolbar-button icon="add" text="Plus" design="Default"></ui5-toolbar-button>
<ui5-toolbar-button icon="employee" text="Hire"></ui5-toolbar-button>
<ui5-toolbar-separator></ui5-toolbar-separator>
<ui5-toolbar-button icon="add" text="Add"></ui5-toolbar-button>
<ui5-toolbar-button icon="decline" text="Decline"></ui5-toolbar-button>
<ui5-toolbar-spacer></ui5-toolbar-spacer>
<ui5-toolbar-button icon="add" text="Append"></ui5-toolbar-button>
</ui5-toolbar>

<ui5-title level="H3">Basic</ui5-title>
<br /><br />
<ui5-toolbar id="clickCountToolbar">
Expand Down

0 comments on commit 11f002c

Please sign in to comment.