Skip to content

Commit 1b8a0e3

Browse files
committed
Allowing expanding text field correctly process multi-line paste operations (splitting lines into separate fields).
1 parent c4f0238 commit 1b8a0e3

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/components/forms/Fields/ExpandingTextField.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,18 @@ import Button from '../../widgets/TheButton';
88
import TextField from './TextField.js';
99
import Icon, { AddIcon, CloseIcon } from '../../icons';
1010

11+
const handleMultilinePaste = (ev, fields, index) => {
12+
const text = (ev.clipboardData || window.clipboardData).getData('text');
13+
const lines = text.trim().split('\n');
14+
if (lines.length > 1) {
15+
ev.preventDefault();
16+
lines.forEach((line, idx) => fields.insert(index + idx + 1, line.trim()));
17+
if (!fields.get(index)) {
18+
fields.remove(index);
19+
}
20+
}
21+
};
22+
1123
const ExpandingTextField = ({
1224
fields = [],
1325
label = null,
@@ -30,6 +42,7 @@ const ExpandingTextField = ({
3042
validate={validateEach}
3143
disabled={readOnly}
3244
groupClassName="mb-1"
45+
onPaste={ev => handleMultilinePaste(ev, fields, index)}
3346
append={
3447
readOnly ? null : (
3548
<>

0 commit comments

Comments
 (0)