Skip to content

Commit 71b11d6

Browse files
committed
Merge branch 'main' into feature/2178-time-field
2 parents d72ee83 + 3fd461e commit 71b11d6

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

.changeset/gentle-phones-cover.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sl-design-system/grid': patch
3+
---
4+
5+
Reset the selection state when the data source is replaced

packages/components/grid/src/grid.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,8 @@ export class Grid<T = any> extends ScopedElementsMixin(LitElement) {
219219
/** Provide your own implementation for getting the data. */
220220
@property({ attribute: false })
221221
set dataSource(dataSource: ListDataSource<T> | undefined) {
222+
const replacement = !!this.#dataSource;
223+
222224
if (this.#dataSource) {
223225
this.#dataSource.removeEventListener('sl-update', this.#onDataSourceUpdate);
224226
this.#dataSource.removeEventListener('sl-selection-change', this.#onSelectionChange);
@@ -227,6 +229,10 @@ export class Grid<T = any> extends ScopedElementsMixin(LitElement) {
227229
this.#dataSource = dataSource;
228230
this.#dataSource?.addEventListener('sl-update', this.#onDataSourceUpdate);
229231
this.#dataSource?.addEventListener('sl-selection-change', this.#onSelectionChange);
232+
233+
if (replacement) {
234+
this.#onSelectionChange();
235+
}
230236
}
231237

232238
/**

0 commit comments

Comments
 (0)