This codemod helps automate the migration from TextField with multiline prop to the Textarea component.
- Node.js 14 or higher
- jscodeshift installed globally or as a dev dependency
npm install -g jscodeshift
# or
pnpm add -D jscodeshift# Run on a single file
npx jscodeshift -t textfield-to-textarea.codemod.js src/components/MyComponent.tsx
# Run on a directory
npx jscodeshift -t textfield-to-textarea.codemod.js src/
# With TypeScript parser
npx jscodeshift -t textfield-to-textarea.codemod.js --parser=tsx src/# Dry run (see what would change without modifying files)
npx jscodeshift -t textfield-to-textarea.codemod.js --dry src/
# Show diff
npx jscodeshift -t textfield-to-textarea.codemod.js --print src/
# Verbose output
npx jscodeshift -t textfield-to-textarea.codemod.js -v 2 src/- Finds TextField components with
multilineprop set totrue - Replaces component name from
TextFieldtoTextarea - Removes multiline prop
- Renames textareaRef to ref (if present)
- Updates imports to include
Textareainstead of (or in addition to)TextField - Removes TextField import if no longer used in the file
Before:
import { TextField } from '@equinor/eds-core-react'
function MyComponent() {
return (
<TextField
multiline
label="Description"
placeholder="Enter text"
/>
)
}After:
import { Textarea } from '@equinor/eds-core-react'
function MyComponent() {
return (
<Textarea
label="Description"
placeholder="Enter text"
/>
)
}Before:
import { TextField } from '@equinor/eds-core-react'
import { useRef } from 'react'
function MyComponent() {
const ref = useRef<HTMLTextAreaElement>(null)
return (
<TextField
multiline
textareaRef={ref}
label="Notes"
/>
)
}After:
import { Textarea } from '@equinor/eds-core-react'
import { useRef } from 'react'
function MyComponent() {
const ref = useRef<HTMLTextAreaElement>(null)
return (
<Textarea
ref={ref}
label="Notes"
/>
)
}Before:
import { TextField } from '@equinor/eds-core-react'
function MyComponent() {
return (
<>
<TextField label="Name" />
<TextField multiline label="Description" />
</>
)
}After:
import { TextField, Textarea } from '@equinor/eds-core-react'
function MyComponent() {
return (
<>
<TextField label="Name" />
<Textarea label="Description" />
</>
)
}The codemod handles most common cases but has limitations:
-
Conditional multiline prop:
<TextField multiline={someCondition} />
→ Manual review needed
-
Dynamic prop spreading:
const props = { multiline: true, label: "Text" } <TextField {...props} />
→ Manual review needed
-
Props not available on Textarea:
<TextField multiline inputIcon={<Icon />} />
→ Manual refactoring needed (remove inputIcon)
-
Complex ref patterns:
<TextField multiline ref={combineRefs(ref1, ref2)} />
→ Manual review needed
After running the codemod, review the following:
- Check for TextField components with conditional
multilineprops - Verify all Textarea components have correct props
- Remove any Textarea-incompatible props (inputIcon, unit, meta)
- Update TypeScript types if using TextFieldProps
- Test all migrated components
- Update tests if they reference TextField with multiline
- Check console for any warnings
# Using grep
grep -r "TextField.*multiline" src/
# Using ripgrep (faster)
rg "TextField.*multiline" src/
# Using ag (the silver searcher)
ag "TextField.*multiline" src/# Find TextField with multiline spread in props
rg "TextField.*\{\.\.\..*\}" src/
# Find conditional multiline
rg "multiline=\{" src/Test the codemod on sample files before running on your entire codebase:
# Create a test file
cat > test-file.tsx << 'EOF'
import { TextField } from '@equinor/eds-core-react'
export const TestComponent = () => (
<TextField multiline label="Test" />
)
EOF
# Run codemod
npx jscodeshift -t textfield-to-textarea.codemod.js --dry test-file.tsx
# Check the output
cat test-file.tsxIf you need to rollback the changes:
# If you have git
git checkout -- src/
# If you made a backup
cp -r src.backup/* src/If you encounter issues with the codemod:
- Check the limitations section above
- Review the manual review checklist
- Try running with
-v 2for verbose output - Create an issue with a minimal reproduction case
# For JavaScript files
npx jscodeshift -t textfield-to-textarea.codemod.js --parser=babylon src/
# For Flow
npx jscodeshift -t textfield-to-textarea.codemod.js --parser=flow src/# Ignore specific directories
npx jscodeshift -t textfield-to-textarea.codemod.js \
--ignore-pattern="**/node_modules/**" \
--ignore-pattern="**/build/**" \
src/# Only .tsx files
find src -name "*.tsx" -exec npx jscodeshift -t textfield-to-textarea.codemod.js {} \;
# Both .tsx and .ts files
npx jscodeshift -t textfield-to-textarea.codemod.js \
--extensions=tsx,ts \
src/