File tree Expand file tree Collapse file tree 1 file changed +13
-0
lines changed
src/components/forms/Fields Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,18 @@ import Button from '../../widgets/TheButton';
88import TextField from './TextField.js' ;
99import 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+
1123const 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 < >
You can’t perform that action at this time.
0 commit comments