fix(renderless/input): [input] fix value become empty when the input type changed (#1025)

This commit is contained in:
yoyo 2023-12-05 17:13:07 +08:00 committed by GitHub
parent 44af3ea51d
commit 6ae405b20d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 7 deletions

View File

@ -10,7 +10,13 @@
*
*/
import type { IInputApi, IInputClassPrefixConstants, IInputRenderlessParams, IInputState } from 'types/input.type'
import type {
IInputApi,
IInputClassPrefixConstants,
IInputRenderlessParamUtils,
IInputRenderlessParams,
IInputState
} from 'types/input.type'
const HIDDEN_STYLE = `
height:0 !important;visibility:hidden !important;overflow:hidden !important;
@ -162,8 +168,8 @@ export const calcTextareaHeight =
return textareaStyle
}
export const getInput = (refs: IInputRenderlessParams['refs']) => (): HTMLTextAreaElement | HTMLInputElement =>
refs.input || refs.textarea
export const getInput = (vm: IInputRenderlessParamUtils['vm']) => (): HTMLTextAreaElement | HTMLInputElement =>
vm.$refs.input || vm.$refs.textarea
export const blur = (api: IInputApi) => (): void => api.getInput().blur()

View File

@ -161,11 +161,14 @@ const initApi = ({
dispatch,
broadcast,
emit,
refs,
vm,
props,
CLASS_PREFIX,
parent
}: Pick<IInputRenderlessParams, 'api' | 'state' | 'dispatch' | 'broadcast' | 'emit' | 'refs' | 'props' | 'parent'> & {
}: Pick<
IInputRenderlessParams,
'api' | 'state' | 'dispatch' | 'broadcast' | 'emit' | 'refs' | 'props' | 'parent' | 'vm'
> & {
CLASS_PREFIX: IInputClassPrefixConstants
}) => {
Object.assign(api, {
@ -174,7 +177,7 @@ const initApi = ({
broadcast,
showBox: showBox(state),
clear: clear(emit),
getInput: getInput(refs),
getInput: getInput(vm),
handleChange: handleChange(emit),
watchFormSelect: watchFormSelect({ emit, props, state }),
calcIconOffset: calcIconOffset({ CLASS_PREFIX, parent }),
@ -327,7 +330,7 @@ export const renderless = (
}
const state = initState({ reactive, computed, mode, props, parent, constants, api })
initApi({ api, state, dispatch, broadcast, emit, refs, props, CLASS_PREFIX, parent })
initApi({ api, state, dispatch, broadcast, emit, refs, props, CLASS_PREFIX, parent, vm })
const storages = useStorageBox({ api, props, reactive, toRefs })