Skip to content

Commit e6945b9

Browse files
authored
fix: content should display when column child is active (#1119)
* fix: content should display when column child is active
1 parent ef8b02d commit e6945b9

File tree

4 files changed

+116
-11
lines changed

4 files changed

+116
-11
lines changed

projects/swimlane/ngx-ui/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## HEAD (unreleased)
44

5+
- Fix (`ngx-column`): Content should display when column child is active on load.
6+
57
## 50.0.0-alpha.4 (2025-07-23)
68

79
- Breaking (`ngx-column`): Setting Dynamic Components in `content` now follow declarative syntax to support outputs, two-way data binding

projects/swimlane/ngx-ui/src/lib/components/column/column/column.component.spec.ts

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,43 @@ describe('ColumnComponent', () => {
106106
});
107107
});
108108

109+
it('should display active child with content', () => {
110+
const contentChild = {
111+
id: '3m',
112+
active: true,
113+
title: 'Column 3m',
114+
children: [
115+
{
116+
id: '3p',
117+
active: true,
118+
title: 'Column 3p',
119+
content: {
120+
component: ColumnTestContentComponent
121+
}
122+
}
123+
]
124+
};
125+
spyOn(component, 'displayContent').and.callThrough();
126+
component.ngOnChanges({
127+
column: {
128+
currentValue: contentChild,
129+
previousValue: undefined,
130+
firstChange: true,
131+
isFirstChange: () => true
132+
}
133+
});
134+
expect(component.activeChild).toEqual({
135+
id: '3p',
136+
active: true,
137+
title: 'Column 3p',
138+
content: {
139+
component: ColumnTestContentComponent
140+
}
141+
});
142+
expect(component.displayContent).toHaveBeenCalled();
143+
expect(component.componentRef).toBeDefined();
144+
});
145+
109146
it('should set height of scrollable view', () => {
110147
component.ngOnChanges({
111148
height: {
@@ -217,6 +254,66 @@ describe('ColumnComponent', () => {
217254
expect(component.tabClick.emit).toHaveBeenCalledWith({ columnId: activeColumn.id });
218255
});
219256

257+
it('should display content on click', () => {
258+
const activeColumn = {
259+
id: '3o',
260+
active: true,
261+
title: 'Column 3o',
262+
children: [
263+
{
264+
id: '3p',
265+
active: true,
266+
title: 'Column 3p',
267+
content: {
268+
component: ColumnTestContentComponent
269+
}
270+
}
271+
]
272+
};
273+
spyOn(component, 'displayContent').and.callThrough();
274+
component.ngOnChanges({
275+
column: {
276+
currentValue: activeColumn,
277+
previousValue: undefined,
278+
firstChange: true,
279+
isFirstChange: () => true
280+
}
281+
});
282+
component.onChildClick('3p');
283+
expect(component.displayContent).toHaveBeenCalled();
284+
expect(component.componentRef).toBeDefined();
285+
});
286+
287+
it('should display content on keyup', () => {
288+
const activeColumn = {
289+
id: '3o',
290+
active: true,
291+
title: 'Column 3o',
292+
children: [
293+
{
294+
id: '3p',
295+
active: true,
296+
title: 'Column 3p',
297+
content: {
298+
component: ColumnTestContentComponent
299+
}
300+
}
301+
]
302+
};
303+
spyOn(component, 'displayContent').and.callThrough();
304+
component.ngOnChanges({
305+
column: {
306+
currentValue: activeColumn,
307+
previousValue: undefined,
308+
firstChange: true,
309+
isFirstChange: () => true
310+
}
311+
});
312+
component.onChildKeyup({ key: ' ' } as any, '3p');
313+
expect(component.displayContent).toHaveBeenCalled();
314+
expect(component.componentRef).toBeDefined();
315+
});
316+
220317
it('should modify the list on input change', () => {
221318
const inputEvent = {
222319
target: {

projects/swimlane/ngx-ui/src/lib/components/column/column/column.component.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ export class ColumnComponent implements OnChanges {
4343
this.activeChild = changes.column.currentValue.children
4444
? changes.column.currentValue.children?.find(child => child.active)
4545
: null;
46+
if (this.activeChild?.content && this.activeChild?.content.component) {
47+
this.displayContent();
48+
}
4649
}
4750
}
4851
if (changes.height?.currentValue) {
@@ -54,11 +57,7 @@ export class ColumnComponent implements OnChanges {
5457
this.activeChild = this.column().children.find(child => child.id === columnId);
5558
this.tabClick.emit({ columnId });
5659
if (this.activeChild?.content && this.activeChild?.content.component) {
57-
this.vcr()?.clear();
58-
this.componentRef = this.vcr()?.createComponent(
59-
this.activeChild.content.component,
60-
this.activeChild.content.options || {}
61-
);
60+
this.displayContent();
6261
}
6362
}
6463

@@ -67,15 +66,22 @@ export class ColumnComponent implements OnChanges {
6766
this.activeChild = this.column().children.find(child => child.id === columnId);
6867
this.tabClick.emit({ columnId });
6968
if (this.activeChild?.content && this.activeChild?.content.component) {
70-
this.vcr()?.clear();
71-
this.componentRef = this.vcr()?.createComponent(
72-
this.activeChild.content.component,
73-
this.activeChild.content.options || {}
74-
);
69+
this.displayContent();
7570
}
7671
}
7772
}
7873

74+
displayContent() {
75+
if (!this.activeChild || !this.activeChild.content?.component) {
76+
return;
77+
}
78+
this.vcr()?.clear();
79+
this.componentRef = this.vcr()?.createComponent(
80+
this.activeChild.content.component,
81+
this.activeChild.content.options || {}
82+
);
83+
}
84+
7985
onInputChange(event: KeyboardEvent) {
8086
const change = (event.target as HTMLInputElement).value;
8187
if (!change.length) {

src/app/components/column-page/column-page.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export class ColumnPageComponent {
2525
children: [
2626
{
2727
id: '1d',
28-
active: false,
28+
active: true,
2929
title: 'Column 1d',
3030
content: {
3131
component: ColumnTestContentComponent,

0 commit comments

Comments
 (0)