mirror of
https://github.com/smartxworks/sunmao-ui.git
synced 2024-11-27 08:39:59 +08:00
Merge pull request #458 from Mark-Fenng/main
feat(arco): expose 'setInputValue' method for Input and Textarea
This commit is contained in:
commit
e121c79679
@ -40,7 +40,11 @@ const options = {
|
||||
spec: {
|
||||
properties: InputPropsSpec,
|
||||
state: InputStateSpec,
|
||||
methods: {},
|
||||
methods: {
|
||||
setInputValue: Type.Object({
|
||||
value: Type.String(),
|
||||
}),
|
||||
},
|
||||
slots: {
|
||||
addAfter: { slotProps: Type.Object({}) },
|
||||
prefix: { slotProps: Type.Object({}) },
|
||||
@ -53,7 +57,14 @@ const options = {
|
||||
};
|
||||
|
||||
export const Input = implementRuntimeComponent(options)(props => {
|
||||
const { getElement, slotsElements, customStyle, callbackMap, mergeState } = props;
|
||||
const {
|
||||
getElement,
|
||||
slotsElements,
|
||||
customStyle,
|
||||
callbackMap,
|
||||
mergeState,
|
||||
subscribeMethods,
|
||||
} = props;
|
||||
|
||||
const { updateWhenDefaultValueChanges, defaultValue, ...cProps } =
|
||||
getComponentProps(props);
|
||||
@ -77,9 +88,19 @@ export const Input = implementRuntimeComponent(options)(props => {
|
||||
mergeState({ value });
|
||||
callbackMap?.onChange?.();
|
||||
},
|
||||
[mergeState, callbackMap]
|
||||
[setValue, mergeState, callbackMap]
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
subscribeMethods({
|
||||
setInputValue({ value }) {
|
||||
setValue(value);
|
||||
mergeState({ value });
|
||||
callbackMap?.onChange?.();
|
||||
},
|
||||
});
|
||||
}, [setValue, mergeState, callbackMap, subscribeMethods]);
|
||||
|
||||
return (
|
||||
<BaseInput
|
||||
className={css(customStyle?.input)}
|
||||
|
@ -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}
|
||||
|
Loading…
Reference in New Issue
Block a user