Skip to content

Commit 92f8fbf

Browse files
committed
Fix reactive toolbar and update snapshots
1 parent d3603e0 commit 92f8fbf

File tree

3 files changed

+51
-33
lines changed

3 files changed

+51
-33
lines changed
1.52 KB
Loading
2.42 KB
Loading

packages/ui-components/src/components/toolbar.tsx

Lines changed: 51 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -459,43 +459,22 @@ export class ReactiveToolbar extends Toolbar<Widget> {
459459
}
460460

461461
private _onResize() {
462-
if (this.parent && this.parent.isAttached) {
463-
const toolbarWidth = this.node.clientWidth;
464-
const opener = this.popupOpener;
465-
const openerWidth = 30;
466-
const toolbarPadding = 2;
467-
const layout = this.layout as ToolbarLayout;
468-
469-
let width = opener.isHidden
470-
? toolbarPadding
471-
: toolbarPadding + openerWidth;
472-
let index = 0;
473-
const widgetsToRemove = [];
474-
const toIndex = layout.widgets.length - 1;
475-
476-
while (index < toIndex) {
477-
const widget = layout.widgets[index];
478-
this._saveWidgetWidth(widget);
479-
width += this._getWidgetWidth(widget);
480-
if (
481-
widgetsToRemove.length === 0 &&
482-
opener.isHidden &&
483-
width + openerWidth > toolbarWidth
484-
) {
485-
width += openerWidth;
486-
}
487-
if (width > toolbarWidth) {
488-
widgetsToRemove.push(widget);
489-
}
490-
index++;
491-
}
492-
462+
if (!(this.parent && this.parent.isAttached)) {
463+
return;
464+
}
465+
const toolbarWidth = this.node.clientWidth;
466+
const opener = this.popupOpener;
467+
const openerWidth = 30;
468+
const toolbarPadding = 2;
469+
let width = opener.isHidden ? toolbarPadding : toolbarPadding + openerWidth;
470+
471+
this._getWidgetsToRemove(width, toolbarWidth, openerWidth).then(values => {
472+
let { width, widgetsToRemove } = values;
493473
while (widgetsToRemove.length > 0) {
494474
const widget = widgetsToRemove.pop() as Widget;
495475
width -= this._getWidgetWidth(widget);
496476
opener.addWidget(widget);
497477
}
498-
499478
if (opener.widgetCount() > 0) {
500479
const widgetsToAdd = [];
501480
let index = 0;
@@ -531,11 +510,50 @@ export class ReactiveToolbar extends Toolbar<Widget> {
531510
} else {
532511
opener.hide();
533512
}
513+
});
514+
}
515+
516+
private async _getWidgetsToRemove(
517+
width: number,
518+
toolbarWidth: number,
519+
openerWidth: number
520+
) {
521+
const opener = this.popupOpener;
522+
const layout = this.layout as ToolbarLayout;
523+
const toIndex = layout.widgets.length - 1;
524+
525+
const widgetsToRemove = [];
526+
527+
let index = 0;
528+
while (index < toIndex) {
529+
const widget = layout.widgets[index];
530+
await this._saveWidgetWidth(widget);
531+
width += this._getWidgetWidth(widget);
532+
if (
533+
widgetsToRemove.length === 0 &&
534+
opener.isHidden &&
535+
width + openerWidth > toolbarWidth
536+
) {
537+
width += openerWidth;
538+
}
539+
if (width > toolbarWidth) {
540+
widgetsToRemove.push(widget);
541+
}
542+
index++;
534543
}
544+
545+
return {
546+
width: width,
547+
widgetsToRemove: widgetsToRemove
548+
};
535549
}
536550

537-
private _saveWidgetWidth(widget: Widget) {
551+
private async _saveWidgetWidth(widget: Widget) {
552+
if (widget instanceof ReactWidget) {
553+
await widget.renderPromise;
554+
}
538555
const widgetName = Private.nameProperty.get(widget);
556+
539557
this._widgetWidths![widgetName] = widget.hasClass(TOOLBAR_SPACER_CLASS)
540558
? 2
541559
: // Add button margin and toolbar items gap = 2 * (4 + 1.5)

0 commit comments

Comments
 (0)