Skip to content

Commit bc3f58e

Browse files
authored
Property Grid: Category icons are not displayed at startup fix #6665 (#6671)
1 parent 09c25a7 commit bc3f58e

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

packages/survey-creator-core/src/components/side-bar/tab-control-model.ts

+14-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import { SidebarModel } from "./side-bar-model";
33
import { MenuButton } from "../../utils/actions";
44

55
export class TabControlModel extends Base {
6-
public topToolbar: ActionContainer<MenuButton> = new ActionContainer<MenuButton>();
76
public bottomToolbar: ActionContainer<MenuButton> = new ActionContainer<MenuButton>();
87
public expandCollapseAction: MenuButton;
8+
public onTopToolbarItemCreated: (bar: ActionContainer<MenuButton>) => void;
99

1010
private updateExpandCollapseAction() {
1111
this.expandCollapseAction.iconName = this.sidePanel.visible ? "icon-collapse-panel" : "icon-expand-panel";
@@ -37,6 +37,19 @@ export class TabControlModel extends Base {
3737
this.updateExpandCollapseAction();
3838
});
3939
}
40+
private topToolbarValue: ActionContainer<MenuButton>;
41+
public get isTopToolbarCreated(): boolean {
42+
return !!this.topToolbarValue;
43+
}
44+
public get topToolbar(): ActionContainer<MenuButton> {
45+
if(!this.topToolbarValue) {
46+
this.topToolbarValue = new ActionContainer<MenuButton>();
47+
if(!!this.onTopToolbarItemCreated) {
48+
this.onTopToolbarItemCreated(this.topToolbarValue);
49+
}
50+
}
51+
return this.topToolbarValue;
52+
}
4053

4154
public get sideBarClassName(): string {
4255
return new CssClassBuilder().append("svc-sidebar-tabs").append("svc-sidebar-tabs--collapsed", !this.sidePanel.renderedIsVisible).toString();

packages/survey-creator-core/src/components/tabs/designer-plugin.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Base, SurveyModel, Action, ComputedUpdater, CurrentPageChangedEvent, PageVisibleChangedEvent, QuestionDropdownModel } from "survey-core";
1+
import { Base, SurveyModel, Action, ComputedUpdater, CurrentPageChangedEvent, PageVisibleChangedEvent, QuestionDropdownModel, ActionContainer } from "survey-core";
22
import { notShortCircuitAnd } from "../../utils/utils";
33
import { SurveyCreatorModel } from "../../creator-base";
44
import { ICreatorPlugin } from "../../creator-settings";
@@ -206,6 +206,9 @@ export class TabDesignerPlugin implements ICreatorPlugin {
206206
constructor(private creator: SurveyCreatorModel) {
207207
creator.addTab({ name: "designer", plugin: this, iconName: "icon-config" });
208208
this.tabControlModel = new TabControlModel(this.creator.sidebar);
209+
this.tabControlModel.onTopToolbarItemCreated = (bar) => {
210+
this.setupPropertyGridTabActions(bar);
211+
};
209212
this.propertyGrid = new PropertyGridModel(undefined, creator, creator.getPropertyGridDefinition());
210213
this.showOneCategoryInPropertyGrid = creator.showOneCategoryInPropertyGrid;
211214
this.propertyGrid.showOneCategoryInPropertyGrid = this.showOneCategoryInPropertyGrid;
@@ -280,7 +283,9 @@ export class TabDesignerPlugin implements ICreatorPlugin {
280283

281284
private updateTabControlActions() {
282285
if (this.showOneCategoryInPropertyGrid) {
283-
this.setupPropertyGridTabActions();
286+
if(this.tabControlModel.isTopToolbarCreated) {
287+
this.setupPropertyGridTabActions(this.tabControlModel.topToolbar);
288+
}
284289
this.propertyGrid.survey.onCurrentPageChanged.add((sender: SurveyModel, options: CurrentPageChangedEvent) => {
285290
const pgTabs = this.tabControlModel.topToolbar.actions;
286291
pgTabs.forEach(action => {
@@ -298,9 +303,9 @@ export class TabDesignerPlugin implements ICreatorPlugin {
298303
this.propertyGridViewModel.objectSelectionAction.title = this.propertyGrid.survey.currentPage?.title;
299304
}
300305
}
301-
private setupPropertyGridTabActions() {
306+
private setupPropertyGridTabActions(topToolbar: ActionContainer<MenuButton>) {
302307
const pgTabs = this.getPropertyGridTabActions();
303-
this.tabControlModel.topToolbar.setItems(pgTabs);
308+
topToolbar.setItems(pgTabs);
304309
this.propertyGridTab.activateCallback = () => {
305310
if (!this.propertyGrid.survey.currentPage) return;
306311

packages/survey-creator-core/tests/tabs/designer.test.ts

+10
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { SurveyLogicUI } from "../../src/components/tabs/logic-ui";
88
import { PageAdorner } from "../../src/components/page";
99
import { QuestionAdornerViewModel } from "../../src/components/question";
1010
import { TabDesignerViewModel } from "../../src/components/tabs/designer";
11+
import { TabControlModel } from "../../src/components/side-bar/tab-control-model";
1112
export * from "../../src/property-grid/matrices";
1213

1314
test("Survey/page title/description placeholders text", () => {
@@ -796,3 +797,12 @@ test("expand/collapse methods", () => {
796797
creator.expandElement(question);
797798
expect(questionAdorner.collapsed).toBeFalsy();
798799
});
800+
test("Create topToolbar on request and setup it, Bug#6665", () => {
801+
const creator = new CreatorTester();
802+
const tabBar = <TabControlModel>creator.sidebar.sideAreaComponentData;
803+
expect(tabBar).toBeTruthy();
804+
expect(tabBar.isTopToolbarCreated).toBeFalsy();
805+
const topToolbar = tabBar.topToolbar;
806+
expect(tabBar.isTopToolbarCreated).toBeTruthy();
807+
expect(topToolbar.actions.length > 3).toBeTruthy();
808+
});

0 commit comments

Comments
 (0)