Skip to content

Commit 789c14c

Browse files
Angular: Add child validation method (fix T1269950) (DevExpress#28657)
1 parent 7f6c3dd commit 789c14c

File tree

50 files changed

+245
-404
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+245
-404
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"axe-core": "4.10.2",
4545
"cheerio": "1.0.0-rc.10",
4646
"codelyzer": "6.0.2",
47-
"devextreme-internal-tools": "16.0.0",
47+
"devextreme-internal-tools": "16.2.0",
4848
"http-server": "14.1.1",
4949
"husky": "8.0.3",
5050
"jest": "29.7.0",

packages/devextreme-angular/src/core/component.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,13 @@ export abstract class DxComponent implements OnChanges, OnInit, DoCheck, AfterCo
210210
}
211211
}
212212

213+
protected _setChildren(propertyName, value, className) {
214+
if (this.checkContentChildren(propertyName, value, className)) {
215+
this.setContentChildren(propertyName, value, className);
216+
this.setChildren(propertyName, value);
217+
}
218+
}
219+
213220
constructor(
214221
protected element: ElementRef,
215222
private readonly ngZone: NgZone,
@@ -293,7 +300,7 @@ export abstract class DxComponent implements OnChanges, OnInit, DoCheck, AfterCo
293300
contentChildren = {};
294301

295302
checkContentChildren<T>(propertyName: string, items: QueryList<T>, className: string) {
296-
if (this.contentChildren[propertyName]) {
303+
if (this.contentChildren[propertyName] && this.contentChildren[propertyName] !== className) {
297304
if (items.length > 0) {
298305
if (console && console.warn) {
299306
console.warn(`In ${this.constructor.name},

packages/devextreme-angular/src/ui/accordion/index.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -714,8 +714,7 @@ export class DxAccordionComponent<TItem = any, TKey = any> extends DxComponent i
714714
return this._getOption('items');
715715
}
716716
set itemsChildren(value) {
717-
this.setContentChildren('items', value, 'DxiAccordionItemComponent');
718-
this.setChildren('items', value);
717+
this._setChildren('items', value, 'DxiAccordionItemComponent');
719718
}
720719

721720

@@ -724,9 +723,7 @@ export class DxAccordionComponent<TItem = any, TKey = any> extends DxComponent i
724723
return this._getOption('items');
725724
}
726725
set itemsLegacyChildren(value) {
727-
if (this.checkContentChildren('items', value, 'DxiItemComponent')) {
728-
this.setChildren('items', value);
729-
}
726+
this._setChildren('items', value, 'DxiItemComponent');
730727
}
731728

732729

packages/devextreme-angular/src/ui/action-sheet/index.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -506,8 +506,7 @@ export class DxActionSheetComponent<TItem = any, TKey = any> extends DxComponent
506506
return this._getOption('items');
507507
}
508508
set itemsChildren(value) {
509-
this.setContentChildren('items', value, 'DxiActionSheetItemComponent');
510-
this.setChildren('items', value);
509+
this._setChildren('items', value, 'DxiActionSheetItemComponent');
511510
}
512511

513512

@@ -516,9 +515,7 @@ export class DxActionSheetComponent<TItem = any, TKey = any> extends DxComponent
516515
return this._getOption('items');
517516
}
518517
set itemsLegacyChildren(value) {
519-
if (this.checkContentChildren('items', value, 'DxiItemComponent')) {
520-
this.setChildren('items', value);
521-
}
518+
this._setChildren('items', value, 'DxiItemComponent');
522519
}
523520

524521

packages/devextreme-angular/src/ui/autocomplete/index.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,17 +1363,15 @@ export class DxAutocompleteComponent extends DxComponent implements OnDestroy, C
13631363
return this._getOption('buttons');
13641364
}
13651365
set buttonsChildren(value) {
1366-
this.setContentChildren('buttons', value, 'DxiAutocompleteButtonComponent');
1367-
this.setChildren('buttons', value);
1366+
this._setChildren('buttons', value, 'DxiAutocompleteButtonComponent');
13681367
}
13691368

13701369
@ContentChildren(DxiAutocompleteItemComponent)
13711370
get itemsChildren(): QueryList<DxiAutocompleteItemComponent> {
13721371
return this._getOption('items');
13731372
}
13741373
set itemsChildren(value) {
1375-
this.setContentChildren('items', value, 'DxiAutocompleteItemComponent');
1376-
this.setChildren('items', value);
1374+
this._setChildren('items', value, 'DxiAutocompleteItemComponent');
13771375
}
13781376

13791377

@@ -1382,19 +1380,15 @@ export class DxAutocompleteComponent extends DxComponent implements OnDestroy, C
13821380
return this._getOption('buttons');
13831381
}
13841382
set buttonsLegacyChildren(value) {
1385-
if (this.checkContentChildren('buttons', value, 'DxiButtonComponent')) {
1386-
this.setChildren('buttons', value);
1387-
}
1383+
this._setChildren('buttons', value, 'DxiButtonComponent');
13881384
}
13891385

13901386
@ContentChildren(DxiItemComponent)
13911387
get itemsLegacyChildren(): QueryList<DxiItemComponent> {
13921388
return this._getOption('items');
13931389
}
13941390
set itemsLegacyChildren(value) {
1395-
if (this.checkContentChildren('items', value, 'DxiItemComponent')) {
1396-
this.setChildren('items', value);
1397-
}
1391+
this._setChildren('items', value, 'DxiItemComponent');
13981392
}
13991393

14001394

packages/devextreme-angular/src/ui/box/index.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -419,8 +419,7 @@ export class DxBoxComponent<TItem = any, TKey = any> extends DxComponent impleme
419419
return this._getOption('items');
420420
}
421421
set itemsChildren(value) {
422-
this.setContentChildren('items', value, 'DxiBoxItemComponent');
423-
this.setChildren('items', value);
422+
this._setChildren('items', value, 'DxiBoxItemComponent');
424423
}
425424

426425

@@ -429,9 +428,7 @@ export class DxBoxComponent<TItem = any, TKey = any> extends DxComponent impleme
429428
return this._getOption('items');
430429
}
431430
set itemsLegacyChildren(value) {
432-
if (this.checkContentChildren('items', value, 'DxiItemComponent')) {
433-
this.setChildren('items', value);
434-
}
431+
this._setChildren('items', value, 'DxiItemComponent');
435432
}
436433

437434

packages/devextreme-angular/src/ui/button-group/index.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -499,8 +499,7 @@ export class DxButtonGroupComponent extends DxComponent implements OnDestroy, On
499499
return this._getOption('items');
500500
}
501501
set itemsChildren(value) {
502-
this.setContentChildren('items', value, 'DxiButtonGroupItemComponent');
503-
this.setChildren('items', value);
502+
this._setChildren('items', value, 'DxiButtonGroupItemComponent');
504503
}
505504

506505

@@ -509,9 +508,7 @@ export class DxButtonGroupComponent extends DxComponent implements OnDestroy, On
509508
return this._getOption('items');
510509
}
511510
set itemsLegacyChildren(value) {
512-
if (this.checkContentChildren('items', value, 'DxiItemComponent')) {
513-
this.setChildren('items', value);
514-
}
511+
this._setChildren('items', value, 'DxiItemComponent');
515512
}
516513

517514

packages/devextreme-angular/src/ui/chart/index.ts

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1447,35 +1447,31 @@ export class DxChartComponent extends DxComponent implements OnDestroy, OnChange
14471447
return this._getOption('annotations');
14481448
}
14491449
set annotationsChildren(value) {
1450-
this.setContentChildren('annotations', value, 'DxiChartAnnotationComponent');
1451-
this.setChildren('annotations', value);
1450+
this._setChildren('annotations', value, 'DxiChartAnnotationComponent');
14521451
}
14531452

14541453
@ContentChildren(DxiChartPaneComponent)
14551454
get panesChildren(): QueryList<DxiChartPaneComponent> {
14561455
return this._getOption('panes');
14571456
}
14581457
set panesChildren(value) {
1459-
this.setContentChildren('panes', value, 'DxiChartPaneComponent');
1460-
this.setChildren('panes', value);
1458+
this._setChildren('panes', value, 'DxiChartPaneComponent');
14611459
}
14621460

14631461
@ContentChildren(DxiChartSeriesComponent)
14641462
get seriesChildren(): QueryList<DxiChartSeriesComponent> {
14651463
return this._getOption('series');
14661464
}
14671465
set seriesChildren(value) {
1468-
this.setContentChildren('series', value, 'DxiChartSeriesComponent');
1469-
this.setChildren('series', value);
1466+
this._setChildren('series', value, 'DxiChartSeriesComponent');
14701467
}
14711468

14721469
@ContentChildren(DxiChartValueAxisComponent)
14731470
get valueAxesChildren(): QueryList<DxiChartValueAxisComponent> {
14741471
return this._getOption('valueAxis');
14751472
}
14761473
set valueAxesChildren(value) {
1477-
this.setContentChildren('valueAxis', value, 'DxiChartValueAxisComponent');
1478-
this.setChildren('valueAxis', value);
1474+
this._setChildren('valueAxis', value, 'DxiChartValueAxisComponent');
14791475
}
14801476

14811477

@@ -1484,39 +1480,31 @@ export class DxChartComponent extends DxComponent implements OnDestroy, OnChange
14841480
return this._getOption('annotations');
14851481
}
14861482
set annotationsLegacyChildren(value) {
1487-
if (this.checkContentChildren('annotations', value, 'DxiAnnotationComponent')) {
1488-
this.setChildren('annotations', value);
1489-
}
1483+
this._setChildren('annotations', value, 'DxiAnnotationComponent');
14901484
}
14911485

14921486
@ContentChildren(DxiPaneComponent)
14931487
get panesLegacyChildren(): QueryList<DxiPaneComponent> {
14941488
return this._getOption('panes');
14951489
}
14961490
set panesLegacyChildren(value) {
1497-
if (this.checkContentChildren('panes', value, 'DxiPaneComponent')) {
1498-
this.setChildren('panes', value);
1499-
}
1491+
this._setChildren('panes', value, 'DxiPaneComponent');
15001492
}
15011493

15021494
@ContentChildren(DxiSeriesComponent)
15031495
get seriesLegacyChildren(): QueryList<DxiSeriesComponent> {
15041496
return this._getOption('series');
15051497
}
15061498
set seriesLegacyChildren(value) {
1507-
if (this.checkContentChildren('series', value, 'DxiSeriesComponent')) {
1508-
this.setChildren('series', value);
1509-
}
1499+
this._setChildren('series', value, 'DxiSeriesComponent');
15101500
}
15111501

15121502
@ContentChildren(DxiValueAxisComponent)
15131503
get valueAxisLegacyChildren(): QueryList<DxiValueAxisComponent> {
15141504
return this._getOption('valueAxis');
15151505
}
15161506
set valueAxisLegacyChildren(value) {
1517-
if (this.checkContentChildren('valueAxis', value, 'DxiValueAxisComponent')) {
1518-
this.setChildren('valueAxis', value);
1519-
}
1507+
this._setChildren('valueAxis', value, 'DxiValueAxisComponent');
15201508
}
15211509

15221510

packages/devextreme-angular/src/ui/chat/index.ts

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -618,26 +618,23 @@ export class DxChatComponent extends DxComponent implements OnDestroy, OnChanges
618618
return this._getOption('alerts');
619619
}
620620
set alertsChildren(value) {
621-
this.setContentChildren('alerts', value, 'DxiChatAlertComponent');
622-
this.setChildren('alerts', value);
621+
this._setChildren('alerts', value, 'DxiChatAlertComponent');
623622
}
624623

625624
@ContentChildren(DxiChatItemComponent)
626625
get itemsChildren(): QueryList<DxiChatItemComponent> {
627626
return this._getOption('items');
628627
}
629628
set itemsChildren(value) {
630-
this.setContentChildren('items', value, 'DxiChatItemComponent');
631-
this.setChildren('items', value);
629+
this._setChildren('items', value, 'DxiChatItemComponent');
632630
}
633631

634632
@ContentChildren(DxiChatTypingUserComponent)
635633
get typingUsersChildren(): QueryList<DxiChatTypingUserComponent> {
636634
return this._getOption('typingUsers');
637635
}
638636
set typingUsersChildren(value) {
639-
this.setContentChildren('typingUsers', value, 'DxiChatTypingUserComponent');
640-
this.setChildren('typingUsers', value);
637+
this._setChildren('typingUsers', value, 'DxiChatTypingUserComponent');
641638
}
642639

643640

@@ -646,29 +643,23 @@ export class DxChatComponent extends DxComponent implements OnDestroy, OnChanges
646643
return this._getOption('alerts');
647644
}
648645
set alertsLegacyChildren(value) {
649-
if (this.checkContentChildren('alerts', value, 'DxiAlertComponent')) {
650-
this.setChildren('alerts', value);
651-
}
646+
this._setChildren('alerts', value, 'DxiAlertComponent');
652647
}
653648

654649
@ContentChildren(DxiItemComponent)
655650
get itemsLegacyChildren(): QueryList<DxiItemComponent> {
656651
return this._getOption('items');
657652
}
658653
set itemsLegacyChildren(value) {
659-
if (this.checkContentChildren('items', value, 'DxiItemComponent')) {
660-
this.setChildren('items', value);
661-
}
654+
this._setChildren('items', value, 'DxiItemComponent');
662655
}
663656

664657
@ContentChildren(DxiTypingUserComponent)
665658
get typingUsersLegacyChildren(): QueryList<DxiTypingUserComponent> {
666659
return this._getOption('typingUsers');
667660
}
668661
set typingUsersLegacyChildren(value) {
669-
if (this.checkContentChildren('typingUsers', value, 'DxiTypingUserComponent')) {
670-
this.setChildren('typingUsers', value);
671-
}
662+
this._setChildren('typingUsers', value, 'DxiTypingUserComponent');
672663
}
673664

674665

packages/devextreme-angular/src/ui/color-box/index.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,8 +1111,7 @@ export class DxColorBoxComponent extends DxComponent implements OnDestroy, Contr
11111111
return this._getOption('buttons');
11121112
}
11131113
set buttonsChildren(value) {
1114-
this.setContentChildren('buttons', value, 'DxiColorBoxButtonComponent');
1115-
this.setChildren('buttons', value);
1114+
this._setChildren('buttons', value, 'DxiColorBoxButtonComponent');
11161115
}
11171116

11181117

@@ -1121,9 +1120,7 @@ export class DxColorBoxComponent extends DxComponent implements OnDestroy, Contr
11211120
return this._getOption('buttons');
11221121
}
11231122
set buttonsLegacyChildren(value) {
1124-
if (this.checkContentChildren('buttons', value, 'DxiButtonComponent')) {
1125-
this.setChildren('buttons', value);
1126-
}
1123+
this._setChildren('buttons', value, 'DxiButtonComponent');
11271124
}
11281125

11291126

0 commit comments

Comments
 (0)