diff --git a/packages/react-vant/src/password-input/PasswordInput.tsx b/packages/react-vant/src/password-input/PasswordInput.tsx index ffcbe2dfc..ef17da65c 100644 --- a/packages/react-vant/src/password-input/PasswordInput.tsx +++ b/packages/react-vant/src/password-input/PasswordInput.tsx @@ -68,9 +68,7 @@ const PasswordInput = forwardRef((pro const handleChange = (e) => { const val = e.target.value; innerEffect.current = true; - formatValue(val, (v: string) => { - if (isFunction(props.onChange)) props.onChange(v); - }); + formatValue(val, props?.onChange); }; const renderPoints = () => { @@ -119,7 +117,7 @@ const PasswordInput = forwardRef((pro useEffect(() => { if (state.code.length >= props.length) { inputRef?.current?.blur?.(); - props.onSubmit(state.code); + props?.onSubmit(state.code); } }, [state.code]); @@ -157,7 +155,7 @@ const PasswordInput = forwardRef((pro onChange={handleChange} onFocus={() => { updateState({ focused: true }); - if (isFunction(props.onFocus)) props.onFocus(); + props?.onFocus(); }} onBlur={() => updateState({ focused: false })} />