feat(arco): expose 'setInputValue' method for TextArea component

This commit is contained in:
Yun Feng 2022-06-17 00:22:54 +10:00
parent 130cce9532
commit 63d8c45c0c

View File

@ -42,7 +42,11 @@ export const TextArea = implementRuntimeComponent({
spec: {
properties: TextAreaPropsSpec,
state: TextAreaStateSpec,
methods: {},
methods: {
setInputValue: Type.Object({
value: Type.String(),
}),
},
slots: {},
styleSlots: ['TextArea'],
events: ['onChange', 'onBlur', 'onFocus', 'onClear', 'onPressEnter'],
@ -54,6 +58,7 @@ export const TextArea = implementRuntimeComponent({
customStyle,
callbackMap,
mergeState,
subscribeMethods,
} = props;
const { defaultValue, ...cProps } = getComponentProps(props);
const [value, setValue] = useStateValue(
@ -70,6 +75,16 @@ export const TextArea = implementRuntimeComponent({
}
}, [getElement, ref]);
useEffect(() => {
subscribeMethods({
setInputValue({ value }) {
setValue(value);
mergeState({ value });
callbackMap?.onChange?.();
},
});
}, [setValue, mergeState, callbackMap, subscribeMethods]);
return (
<BaseTextArea
ref={ref}