Skip to content

Commit fb3a1ca

Browse files
fix(ui5-toolbar): fix spacers with flexible width (#13274)
1 parent 46238a6 commit fb3a1ca

5 files changed

Lines changed: 58 additions & 8 deletions

File tree

packages/main/cypress/specs/Toolbar.cy.tsx

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,45 @@ describe("Toolbar general interaction", () => {
7171
.should("exist", "hidden class attached to tb button, meaning it's not shown as expected");
7272
});
7373

74+
it("Should apply fixed spacer widths without enabling flexible full-width layout", () => {
75+
cy.mount(
76+
<Toolbar id="otb_fixed_spacers">
77+
<ToolbarSpacer width="50px"></ToolbarSpacer>
78+
<ToolbarButton text="Left"></ToolbarButton>
79+
<ToolbarSpacer width="100px"></ToolbarSpacer>
80+
<ToolbarButton text="Right"></ToolbarButton>
81+
</Toolbar>
82+
);
83+
84+
cy.get("#otb_fixed_spacers")
85+
.as("toolbar");
86+
87+
cy.get("@toolbar")
88+
.shadow()
89+
.find(".ui5-tb-items")
90+
.should("not.have.class", "ui5-tb-items-full-width");
91+
92+
cy.get("@toolbar")
93+
.then($toolbar => {
94+
const toolbar = $toolbar[0] as Toolbar;
95+
const fixedSpacers = Array.from(toolbar.querySelectorAll("ui5-toolbar-spacer")) as ToolbarSpacer[];
96+
97+
expect(fixedSpacers).to.have.length(2);
98+
expect(fixedSpacers[0].hasFlexibleWidth).to.be.false;
99+
expect(fixedSpacers[1].hasFlexibleWidth).to.be.false;
100+
101+
cy.get("@toolbar")
102+
.shadow()
103+
.find(`#${fixedSpacers[0]._individualSlot}`)
104+
.should("have.css", "width", "50px");
105+
106+
cy.get("@toolbar")
107+
.shadow()
108+
.find(`#${fixedSpacers[1]._individualSlot}`)
109+
.should("have.css", "width", "100px");
110+
});
111+
});
112+
74113
it("shouldn't show overflow button if there is enough space", () => {
75114
cy.mount(
76115
<Toolbar style={{ width: "fit-content", " max-width": "100%;" }}>

packages/main/src/ToolbarItemBase.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,17 @@ class ToolbarItemBase extends UI5Element {
116116
return false;
117117
}
118118

119+
/**
120+
* Returns if the item is a spacer.
121+
* A spacer item is an item that takes space in the toolbar, but does not render any content.
122+
* @protected
123+
* @since 2.21.0
124+
*/
125+
126+
get isSpacer() {
127+
return false;
128+
}
129+
119130
get stableDomRef() {
120131
return this.getAttribute("stable-dom-ref") || `${this._id}-stable-dom-ref`;
121132
}
@@ -128,6 +139,10 @@ class ToolbarItemBase extends UI5Element {
128139
},
129140
};
130141
}
142+
143+
get styles() {
144+
return {};
145+
}
131146
}
132147

133148
export type {

packages/main/src/ToolbarSpacer.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ class ToolbarSpacer extends ToolbarItemBase {
4545
get isInteractive() {
4646
return false;
4747
}
48+
get isSpacer() {
49+
return true;
50+
}
4851
}
4952

5053
ToolbarSpacer.define();

packages/main/src/ToolbarTemplate.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@ export default function ToolbarTemplate(this: Toolbar) {
1717
return (
1818
<div class={{
1919
"ui5-tb-item": !item.hasFlexibleWidth,
20-
"ui5-tb-spacer": item.hasFlexibleWidth,
2120
"ui5-tb-self-overflow": item.hasOverflow,
22-
}} id={item._individualSlot}>
21+
}} id={item._individualSlot} style={item.isSpacer ? item.styles : undefined}>
2322
<slot name={item._individualSlot}></slot>
2423
</div>
2524
);

packages/main/src/themes/Toolbar.css

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,6 @@
3232
margin-inline-start: var(--_ui5-toolbar-item-margin-left);
3333
}
3434

35-
.ui5-tb-spacer {
36-
flex: 1 1 auto;
37-
margin-inline-end: var(--_ui5-toolbar-item-margin-right);
38-
margin-inline-start: var(--_ui5-toolbar-item-margin-left);
39-
}
40-
4135
.ui5-tb-self-overflow {
4236
min-width: 2.5rem;
4337
flex-shrink: 1;

0 commit comments

Comments
 (0)