Skip to content

Commit fb7835b

Browse files
authored
fix: handle declarative columns nested in wrapping element (#35)
1 parent c0d93d1 commit fb7835b

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/components/grid.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ import IgcGridLiteHeaderRow from './header-row.js';
4040
import IgcGridLiteRow from './row.js';
4141
import IgcVirtualizer from './virtualizer.js';
4242

43+
/** Column reducer matching either direct column element or one nested in container */
44+
function columnReducer<T extends Element>(acc: T[], el: T): T[] {
45+
const tag = IgcGridLiteColumn.tagName;
46+
const column = el.matches(tag) ? el : el.querySelector(tag);
47+
if (column) acc.push(column as T);
48+
return acc;
49+
}
50+
4351
/**
4452
* Event object for the filtering event of the grid.
4553
*/
@@ -348,15 +356,15 @@ export class IgcGridLite<T extends object> extends EventEmitterBase<IgcGridLiteE
348356
const slot = this.renderRoot.querySelector('slot') as HTMLSlotElement;
349357
const assignedNodes = slot
350358
.assignedElements({ flatten: true })
351-
.filter((element) => element.matches(IgcGridLiteColumn.tagName));
359+
.reduce<Element[]>(columnReducer, []);
352360
return assignedNodes.length > 0;
353361
}
354362

355363
private _handleSlotChange(event: Event): void {
356364
const slot = event.target as HTMLSlotElement;
357365
const assignedNodes = slot
358366
.assignedElements({ flatten: true })
359-
.filter((element) => element.matches(IgcGridLiteColumn.tagName));
367+
.reduce<Element[]>(columnReducer, []);
360368

361369
this._stateController.setColumnConfiguration(
362370
assignedNodes as unknown as ColumnConfiguration<T>[]

test/column-config.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,14 @@ describe('Column configuration', () => {
2626
const newKeys: Array<Keys<TestData>> = ['id', 'name'];
2727

2828
TDD.grid.replaceChildren(
29-
...newKeys.map((key) => {
29+
...newKeys.map((key, i) => {
3030
const col = document.createElement(GRID_COLUMN_TAG) as IgcGridLiteColumn<TestData>;
3131
col.field = key;
32+
if (i % 2 === 0) {
33+
const div = document.createElement('div');
34+
div.appendChild(col);
35+
return div;
36+
}
3237
return col;
3338
})
3439
);

0 commit comments

Comments
 (0)