Skip to content

Commit ea4e682

Browse files
authored
fix(combo): default value with delayed data (#1555)
* Added form integration tests with delayed data * Preserve pristine state on data set * Avoid triggering pipeline for state updates setting same data
1 parent e7224ee commit ea4e682

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

src/components/combo/combo.spec.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1431,6 +1431,45 @@ describe('Combo', () => {
14311431
});
14321432
});
14331433

1434+
describe('Form integration with delayed data', () => {
1435+
const spec = createFormAssociatedTestBed<IgcComboComponent<City>>(html`
1436+
<igc-combo name="combo" value-key="id" display-key="name"></igc-combo>
1437+
`);
1438+
1439+
function initDataDefaultValue(single = false) {
1440+
spec.element.singleSelect = single;
1441+
// assign data after init to simulate async data
1442+
spec.element.data = cities;
1443+
spec.element.defaultValue = value;
1444+
}
1445+
1446+
beforeEach(async () => {
1447+
await spec.setup(IgcComboComponent.tagName);
1448+
});
1449+
1450+
it('correct initial state (single)', () => {
1451+
initDataDefaultValue(true);
1452+
spec.assertIsPristine();
1453+
expect(spec.element.value).to.eql([first(value)]);
1454+
});
1455+
1456+
it('correct initial state (multiple)', () => {
1457+
initDataDefaultValue();
1458+
spec.assertIsPristine();
1459+
expect(spec.element.value).to.eql(value);
1460+
});
1461+
1462+
it('is correctly submitted (single)', () => {
1463+
initDataDefaultValue(true);
1464+
spec.assertSubmitHasValue(first(value));
1465+
});
1466+
1467+
it('is correctly submitted (multiple)', () => {
1468+
initDataDefaultValue();
1469+
spec.assertSubmitHasValues(value);
1470+
});
1471+
});
1472+
14341473
describe('Validation', () => {
14351474
const spec = createFormAssociatedTestBed<IgcComboComponent<City>>(html`
14361475
<igc-combo

src/components/combo/combo.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,13 @@ export default class IgcComboComponent<
181181
/* treatAsRef */
182182
@property({ attribute: false })
183183
public set data(value: T[]) {
184+
if (this._data === value) {
185+
return;
186+
}
184187
this._data = asArray(value);
188+
const pristine = this._pristine;
185189
this.value = asArray(this.value);
190+
this._pristine = pristine;
186191
this._state.runPipeline();
187192
}
188193

0 commit comments

Comments
 (0)