Skip to content

Commit ab8c335

Browse files
committed
refactor(schematics): check for duplicate property on underlying igxInput elem
1 parent f81d19f commit ab8c335

File tree

2 files changed

+44
-15
lines changed

2 files changed

+44
-15
lines changed

projects/igniteui-angular/migrations/update-12_0_0/index.spec.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1787,4 +1787,30 @@ export class SimpleComponent {
17871787
`
17881788
);
17891789
});
1790+
1791+
it('Should not add duplicate disabled to igxInput when moving the property from input-group', async () => {
1792+
appTree.create(
1793+
`/testSrc/appPrefix/component/test.component.html`,
1794+
`
1795+
<igx-input-group [disabled]="true">
1796+
<input igxInput [(ngModel)]="name" disabled>
1797+
</igx-input-group>
1798+
`
1799+
);
1800+
1801+
const tree = await schematicRunner
1802+
.runSchematicAsync(migrationName, {}, appTree)
1803+
.toPromise();
1804+
// this is the expected output
1805+
// putting just the disabled attribute on an igx-input-group is an invalid scenario
1806+
expect(
1807+
tree.readContent('/testSrc/appPrefix/component/test.component.html')
1808+
).toEqual(
1809+
`
1810+
<igx-input-group>
1811+
<input igxInput [(ngModel)]="name" disabled>
1812+
</igx-input-group>
1813+
`
1814+
);
1815+
});
17901816
});

projects/igniteui-angular/migrations/update-12_0_0/index.ts

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -481,25 +481,28 @@ See https://www.infragistics.com/products/ignite-ui-angular/angular/components/t
481481
inputGroups.forEach((el) => {
482482
const parentEl = (el as Element);
483483
if (hasAttribute(parentEl, INPUT_GROUP_CHANGES.ATTRIBUTES)) {
484-
const inputChildren = findElementNodes([el], INPUT_GROUP_CHANGES.INPUT_TAG).reduce((prev, curr) => prev.concat(curr), [])
485-
.filter(template => hasAttribute(template as Element, INPUT_GROUP_CHANGES.DIRECTIVE));
484+
const inputChildren = findElementNodes([el], INPUT_GROUP_CHANGES.INPUT_TAG)
485+
.reduce((prev, curr) => prev.concat(curr), [])
486+
.filter(template => hasAttribute(template as Element, INPUT_GROUP_CHANGES.DIRECTIVE));
486487
INPUT_GROUP_CHANGES.ATTRIBUTES.forEach((a: string) => {
487488
const attr = getAttribute(parentEl, a)[0];
488489
if (attr) {
489-
inputChildren.forEach(node => {
490-
const { startTag, file } = getSourceOffset(node as Element);
491-
// input is self-closing, so the element === startTag
492-
const repTxt = file.content.substring(startTag.start, startTag.end);
493-
const matches = repTxt.match(/\/?>/g);
494-
// should always be only 1 match
495-
const lastIndex = repTxt.indexOf(matches[0]);
496-
let property =`${attr.name}`;
497-
if (attr.name === INPUT_GROUP_CHANGES.ATTRIBUTES[0] || attr.value) {
498-
property += `="${attr.value}"`;
490+
inputChildren.forEach((node: Element) => {
491+
if (!hasAttribute(node, INPUT_GROUP_CHANGES.ATTRIBUTES)) {
492+
const { startTag, file } = getSourceOffset(node as Element);
493+
// input is self-closing, so the element === startTag
494+
const repTxt = file.content.substring(startTag.start, startTag.end);
495+
const matches = repTxt.match(/\/?>/g);
496+
// should always be only 1 match
497+
const lastIndex = repTxt.indexOf(matches[0]);
498+
let property = `${attr.name}`;
499+
if (attr.name === INPUT_GROUP_CHANGES.ATTRIBUTES[0] || attr.value) {
500+
property += `="${attr.value}"`;
501+
}
502+
const addedAttr =
503+
`${repTxt.substring(0, lastIndex)} ${property}${repTxt.substring(lastIndex)}`;
504+
addChange(file.url, new FileChange(startTag.start, addedAttr, repTxt, 'replace'));
499505
}
500-
const addedAttr =
501-
`${repTxt.substring(0, lastIndex)} ${property}${repTxt.substring(lastIndex)}`;
502-
addChange(file.url, new FileChange(startTag.start, addedAttr, repTxt, 'replace'));
503506
});
504507
}
505508
});

0 commit comments

Comments
 (0)