Skip to content

Commit 6ae405b

Browse files
authored
fix(renderless/input): [input] fix value become empty when the input type changed (#1025)
1 parent 44af3ea commit 6ae405b

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

packages/renderless/src/input/index.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@
1010
*
1111
*/
1212

13-
import type { IInputApi, IInputClassPrefixConstants, IInputRenderlessParams, IInputState } from 'types/input.type'
13+
import type {
14+
IInputApi,
15+
IInputClassPrefixConstants,
16+
IInputRenderlessParamUtils,
17+
IInputRenderlessParams,
18+
IInputState
19+
} from 'types/input.type'
1420

1521
const HIDDEN_STYLE = `
1622
height:0 !important;visibility:hidden !important;overflow:hidden !important;
@@ -162,8 +168,8 @@ export const calcTextareaHeight =
162168
return textareaStyle
163169
}
164170

165-
export const getInput = (refs: IInputRenderlessParams['refs']) => (): HTMLTextAreaElement | HTMLInputElement =>
166-
refs.input || refs.textarea
171+
export const getInput = (vm: IInputRenderlessParamUtils['vm']) => (): HTMLTextAreaElement | HTMLInputElement =>
172+
vm.$refs.input || vm.$refs.textarea
167173

168174
export const blur = (api: IInputApi) => (): void => api.getInput().blur()
169175

packages/renderless/src/input/vue.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,14 @@ const initApi = ({
161161
dispatch,
162162
broadcast,
163163
emit,
164-
refs,
164+
vm,
165165
props,
166166
CLASS_PREFIX,
167167
parent
168-
}: Pick<IInputRenderlessParams, 'api' | 'state' | 'dispatch' | 'broadcast' | 'emit' | 'refs' | 'props' | 'parent'> & {
168+
}: Pick<
169+
IInputRenderlessParams,
170+
'api' | 'state' | 'dispatch' | 'broadcast' | 'emit' | 'refs' | 'props' | 'parent' | 'vm'
171+
> & {
169172
CLASS_PREFIX: IInputClassPrefixConstants
170173
}) => {
171174
Object.assign(api, {
@@ -174,7 +177,7 @@ const initApi = ({
174177
broadcast,
175178
showBox: showBox(state),
176179
clear: clear(emit),
177-
getInput: getInput(refs),
180+
getInput: getInput(vm),
178181
handleChange: handleChange(emit),
179182
watchFormSelect: watchFormSelect({ emit, props, state }),
180183
calcIconOffset: calcIconOffset({ CLASS_PREFIX, parent }),
@@ -327,7 +330,7 @@ export const renderless = (
327330
}
328331
const state = initState({ reactive, computed, mode, props, parent, constants, api })
329332

330-
initApi({ api, state, dispatch, broadcast, emit, refs, props, CLASS_PREFIX, parent })
333+
initApi({ api, state, dispatch, broadcast, emit, refs, props, CLASS_PREFIX, parent, vm })
331334

332335
const storages = useStorageBox({ api, props, reactive, toRefs })
333336

0 commit comments

Comments
 (0)