diff --git a/src/components/list-input/hint-input.tsx b/src/components/list-input/hint-input.tsx index c1df138a..ec2862b3 100644 --- a/src/components/list-input/hint-input.tsx +++ b/src/components/list-input/hint-input.tsx @@ -8,13 +8,14 @@ interface HintInputProps { onChange: (value: string) => void; onBlur?: (e: any) => void; placeholder?: string; + trim?: boolean; sourceOptions?: Global.HintOptions[]; } const matchReg = /[^=]+=[^=]*$/; const HintInput: React.FC = (props) => { - const { value, label, onChange, onBlur, sourceOptions } = props; + const { value, label, onChange, onBlur, sourceOptions, trim = true } = props; const cursorPosRef = React.useRef(0); const contextBeforeCursorRef = React.useRef(''); const [options, setOptions] = React.useState< @@ -70,11 +71,7 @@ const HintInput: React.FC = (props) => { const handleInput = (e: any) => { getContextBeforeCursor(e); - onChange(e.target.value?.trim()); - }; - - const handleOnChange = (value: string) => { - onChange(value?.trim()); + onChange(e.target.value); }; const handleOnSelect = (value: string) => { @@ -93,9 +90,10 @@ const HintInput: React.FC = (props) => { onBlur={onBlur} label={label} options={options} + trim={trim} style={{ width: '100%' }} /> ); }; -export default React.memo(HintInput); +export default HintInput; diff --git a/src/components/list-input/index.tsx b/src/components/list-input/index.tsx index d4db84a3..ac4f8b73 100644 --- a/src/components/list-input/index.tsx +++ b/src/components/list-input/index.tsx @@ -1,4 +1,3 @@ -import { useIntl } from '@umijs/max'; import _ from 'lodash'; import React from 'react'; import Wrapper from '../label-selector/wrapper'; @@ -12,13 +11,13 @@ interface ListInputProps { options?: Global.HintOptions[]; placeholder?: string; labelExtra?: React.ReactNode; + trim?: boolean; onChange: (data: string[]) => void; onBlur?: (e: any, index: number) => void; onDelete?: (index: number) => void; } const ListInput: React.FC = (props) => { - const intl = useIntl(); const { dataList, label, @@ -28,7 +27,8 @@ const ListInput: React.FC = (props) => { onDelete, btnText, options, - labelExtra + labelExtra, + trim = true } = props; const [list, setList] = React.useState<{ value: string; uid: number }[]>([]); const countRef = React.useRef(0); @@ -97,6 +97,7 @@ const ListInput: React.FC = (props) => { onBlur={(e) => onBlur?.(e, index)} onRemove={() => handleOnRemove(index)} onChange={(val) => handleOnChange(val, index)} + trim={trim} /> ); })} diff --git a/src/components/list-input/list-item.tsx b/src/components/list-input/list-item.tsx index 7bc01570..1df76156 100644 --- a/src/components/list-input/list-item.tsx +++ b/src/components/list-input/list-item.tsx @@ -13,10 +13,19 @@ interface LabelItemProps { label?: string; placeholder?: string; options?: Global.HintOptions[]; + trim?: boolean; } const ListItem: React.FC = (props) => { - const { onRemove, onChange, onBlur, label, value, options } = props; + const { + onRemove, + onChange, + onBlur, + label, + value, + options, + trim = true + } = props; const handleOnChange = (value: any) => { onChange(value); @@ -30,6 +39,7 @@ const ListItem: React.FC = (props) => { onBlur={onBlur} label={label} sourceOptions={options} + trim={trim} placeholder={props.placeholder} />