Skip to content

Commit

Permalink
chore(schematics): valid migration for tuiBlock (#10132)
Browse files Browse the repository at this point in the history
  • Loading branch information
splincode authored Jan 13, 2025
1 parent 1b3d68e commit be5fef1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type {DevkitFileSystem} from 'ng-morph';
import type {Location} from 'parse5/dist/common/token';

import {findElementsByTagNames} from '../../../../utils/templates/elements';
import {findAttr} from '../../../../utils/templates/inputs';
import {findAttr, isBinding} from '../../../../utils/templates/inputs';
import {
getTemplateFromTemplateResource,
getTemplateOffset,
Expand Down Expand Up @@ -53,8 +53,8 @@ export function migrateBlocked({
) || [];
const sizeAttr = findAttr(attrs, 'size');
const ngForAttr = findAttr(attrs, '*ngFor');

const newBlockAttr = `tuiBlock${sizeAttr ? `="${sizeAttr.value === 'xs' ? 's' : sizeAttr.value}"` : ''}`;
const tuiBlock = sizeAttr && isBinding(sizeAttr) ? '[tuiBlock]' : 'tuiBlock';
const newBlockAttr = `${tuiBlock}${sizeAttr ? `="${sizeAttr.value === 'xs' ? 's' : sizeAttr.value}"` : ''}`;

recorder.insertRight(
templateOffset + (sourceCodeLocation.startTag?.startOffset || 1) - 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ const TEMPLATE_BEFORE = `
</tui-radio-block>
<tui-primitive-textfield [(value)]="value" [pseudoFocus]="pseudoFocus">Type something</tui-primitive-textfield>
<tui-checkbox-block [formControl]="control" [size]="size">
{{ label() }}
</tui-checkbox-block>
`.trim();

const TEMPLATE_AFTER = `
Expand Down Expand Up @@ -142,6 +146,10 @@ const TEMPLATE_AFTER = `
</label>
<tui-primitive-textfield [(value)]="value" [pseudoFocus]="pseudoFocus">Type something</tui-primitive-textfield>
<label [tuiBlock]="size">
<input tuiCheckbox type="checkbox" [formControl]="control" >
{{ label() }}
</label>
`.trim();

describe('ng-update', () => {
Expand Down

0 comments on commit be5fef1

Please sign in to comment.