Skip to content

Commit d00b0be

Browse files
authoredMay 22, 2020
fix(ui5-segmentedbutton): fix measuring when parent is not displayed (#1657)
1 parent fd9a221 commit d00b0be

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed
 

‎packages/main/src/SegmentedButton.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,16 @@ class SegmentedButton extends UI5Element {
130130
await this.measureButtonsWidth();
131131
}
132132

133+
prepareToMeasureButtons() {
134+
this.style.width = "";
135+
this.buttons.forEach(button => {
136+
button.style.width = "";
137+
});
138+
}
139+
133140
async measureButtonsWidth() {
134141
await RenderScheduler.whenDOMUpdated();
142+
this.prepareToMeasureButtons();
135143

136144
this.widths = this.buttons.map(button => {
137145
// +1 is added because for width 100.44px the offsetWidth property returns 100px and not 101px
@@ -202,7 +210,12 @@ class SegmentedButton extends UI5Element {
202210
}
203211
}
204212

205-
_handleResize() {
213+
async _handleResize() {
214+
const buttonsHaveWidth = this.widths.some(button => button.offsetWidth > 2); // 2 are the pixel's added for rounding & IE
215+
if (!buttonsHaveWidth) {
216+
await this.measureButtonsWidth();
217+
}
218+
206219
const parentWidth = this.parentNode.offsetWidth;
207220

208221
if (!this.style.width || this.percentageWidthSet) {

0 commit comments

Comments
 (0)
Please sign in to comment.