Skip to content

Commit 225cf9a

Browse files
author
Felipe Lang
committed
WIP: fix: measure overflow button width instead of using magic 50px
1 parent ff8206a commit 225cf9a

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

src/main/resources/META-INF/resources/frontend/src/fc-days-of-week-selector.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,16 +135,38 @@ export class DaysOfWeekSelector extends ResizeMixin(ThemableMixin(LitElement)) {
135135
this._updateOnOverflow();
136136
}
137137

138+
/**
139+
* Returns overflow button width.
140+
*
141+
* @private
142+
*/
143+
private _getOverflowButtonWidth() {
144+
let overflowWidth = 0;
145+
const badge = this._overflowBadge;
146+
if (badge) {
147+
const wasHidden = badge.hasAttribute('hidden');
148+
if (wasHidden) {
149+
badge.removeAttribute('hidden');
150+
}
151+
overflowWidth = badge.getBoundingClientRect().width || 0;
152+
if (wasHidden) {
153+
badge.setAttribute('hidden', '');
154+
}
155+
}
156+
return overflowWidth;
157+
}
158+
138159
private _updateOnOverflow() {
139160
const containerWidth = this.getBoundingClientRect().width;
140161
let usedWidth = 0;
141162
const overflowButtons: Node[] = [];
163+
const overflowButtonWidth = this._getOverflowButtonWidth();
142164

143165
for (const button of this._daysOfWeek) {
144166
button.style.display = '';
145167
const width = button.getBoundingClientRect().width;
146168

147-
if (usedWidth + width > containerWidth - 50) {
169+
if (usedWidth + width > containerWidth - overflowButtonWidth) {
148170
const clonedButton = this._cloneButton(button);
149171
overflowButtons.push(clonedButton);
150172

0 commit comments

Comments
 (0)