mirror of
https://github.com/smartxworks/sunmao-ui.git
synced 2024-11-21 03:15:49 +08:00
feat(input): add updateWhenDefaultValueChanges property
This commit is contained in:
parent
96b3c98cad
commit
ebf9f073a1
@ -19,6 +19,7 @@ const exampleProperties: Static<typeof InputPropsSpec> = {
|
||||
disabled: false,
|
||||
readOnly: false,
|
||||
defaultValue: '',
|
||||
updateWhenDefaultValueChanges: false,
|
||||
placeholder: 'please input',
|
||||
error: false,
|
||||
size: 'default',
|
||||
@ -46,7 +47,14 @@ const options = {
|
||||
};
|
||||
|
||||
export const Input = implementRuntimeComponent(options)(props => {
|
||||
const { getElement, slotsElements, customStyle, callbackMap, mergeState } = props;
|
||||
const {
|
||||
getElement,
|
||||
updateWhenDefaultValueChanges,
|
||||
slotsElements,
|
||||
customStyle,
|
||||
callbackMap,
|
||||
mergeState,
|
||||
} = props;
|
||||
const { defaultValue, ...cProps } = getComponentProps(props);
|
||||
const ref = useRef<RefInputType | null>(null);
|
||||
const [value, setValue] = useState(defaultValue);
|
||||
@ -58,6 +66,13 @@ export const Input = implementRuntimeComponent(options)(props => {
|
||||
}
|
||||
}, [getElement, ref]);
|
||||
|
||||
useEffect(() => {
|
||||
if (updateWhenDefaultValueChanges) {
|
||||
setValue(defaultValue);
|
||||
mergeState({ value: defaultValue });
|
||||
}
|
||||
}, [defaultValue, updateWhenDefaultValueChanges]);
|
||||
|
||||
const onChange = useCallback(
|
||||
value => {
|
||||
setValue(value);
|
||||
|
@ -24,6 +24,7 @@ const exampleProperties: Static<typeof TextAreaPropsSpec> = {
|
||||
error: false,
|
||||
size: 'default',
|
||||
autoSize: true,
|
||||
updateWhenDefaultValueChanges:false
|
||||
};
|
||||
|
||||
const options = {
|
||||
@ -48,7 +49,13 @@ const options = {
|
||||
};
|
||||
|
||||
export const TextArea = implementRuntimeComponent(options)(props => {
|
||||
const { getElement, customStyle, callbackMap, mergeState } = props;
|
||||
const {
|
||||
getElement,
|
||||
updateWhenDefaultValueChanges,
|
||||
customStyle,
|
||||
callbackMap,
|
||||
mergeState,
|
||||
} = props;
|
||||
const { defaultValue, ...cProps } = getComponentProps(props);
|
||||
const [value, setValue] = useState(defaultValue);
|
||||
const ref = useRef<RefInputType | null>(null);
|
||||
@ -60,6 +67,13 @@ export const TextArea = implementRuntimeComponent(options)(props => {
|
||||
}
|
||||
}, [getElement, ref]);
|
||||
|
||||
useEffect(() => {
|
||||
if (updateWhenDefaultValueChanges) {
|
||||
setValue(defaultValue);
|
||||
mergeState({ value: defaultValue });
|
||||
}
|
||||
}, [defaultValue, updateWhenDefaultValueChanges]);
|
||||
|
||||
return (
|
||||
<BaseTextArea
|
||||
ref={ref}
|
||||
|
@ -15,7 +15,7 @@ export const InputPropsSpec = {
|
||||
}),
|
||||
updateWhenDefaultValueChanges: Type.Boolean({
|
||||
title: 'Update When Default Value Changes',
|
||||
category: 'Basic',
|
||||
category: Category.Basic,
|
||||
}),
|
||||
allowClear: Type.Boolean({
|
||||
title: 'Allow Clear',
|
||||
|
@ -19,6 +19,10 @@ export const TextAreaPropsSpec = {
|
||||
title: 'Disabled',
|
||||
category: Category.Basic,
|
||||
}),
|
||||
updateWhenDefaultValueChanges: Type.Boolean({
|
||||
title: 'Update When Default Value Changes',
|
||||
category: Category.Basic,
|
||||
}),
|
||||
size: StringUnion(['default', 'mini', 'small', 'large'], {
|
||||
title: 'Size',
|
||||
category: Category.Style,
|
||||
|
Loading…
Reference in New Issue
Block a user