Skip to content

Commit

Permalink
Fix missing selected tab reset when closing tabbed window
Browse files Browse the repository at this point in the history
  • Loading branch information
Basssiiie committed May 21, 2024
1 parent 57816d4 commit b3dae29
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/windows/baseWindowControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ export abstract class BaseWindowControl implements WindowTemplate, ParentWindow
this._invoke(frame => frame.open(window, activeWidgets));
}

private _close(): void
protected _close(): void
{
Log.debug("BaseWindowControl.close()");
this._invoke(frame => frame.close());
Expand Down
5 changes: 3 additions & 2 deletions src/windows/tabs/tabWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,10 @@ class TabWindowControl extends BaseWindowControl
super._open(description, binder);
}

override close(): void
protected override _close(): void
{
super.close();
Log.debug("TabWindow.close()");
super._close();
this._selectedTab = this._description.tabIndex || 0;
}

Expand Down
41 changes: 41 additions & 0 deletions tests/windows/tabwindow.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1531,3 +1531,44 @@ test("Window with tabs does auto resizes to body size changes", t =>

t.false(button2.isVisible);
});


test("Window with tabs and bindings resets properly to first tab after close", t =>
{
globalThis.ui = Mock.ui();

const text = store("my bla");
const template = tabwindow({
width: 200, height: 100,
tabs: [
tab({ image: 3, content: [] }),
tab({ image: 4, content: [ button({ text }) ]})
]
});
template.open();

const created1 = (globalThis.ui as UiMock).createdWindows[0];
t.is(created1.width, 200);
t.is(created1.height, 100);
t.deepEqual(created1.widgets, []);

created1.tabIndex = 1;
created1.onTabChange!();

const tab1widgets = created1.widgets;
t.is(tab1widgets.length, 1);

const button1 = created1.widgets[0] as ButtonWidget;
t.is(button1.x, 5);
t.is(button1.y, 44 + 5);
t.is(button1.width, 200 - 10);
t.is(button1.height, 100 - (44 + 10));
t.is(button1.text, "my bla");

created1.onClose!();
template.open();

const created2 = (globalThis.ui as UiMock).createdWindows[0];
t.is(created2.tabIndex, 0);
t.deepEqual(created2.widgets, []);
});

0 comments on commit b3dae29

Please sign in to comment.