Skip to content

Commit d6a7191

Browse files
authored
Update Password.tsx
1 parent eec5e40 commit d6a7191

File tree

1 file changed

+21
-32
lines changed

1 file changed

+21
-32
lines changed

components/input/Password.tsx

+21-32
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,17 @@ import EyeOutlined from '@ant-design/icons-vue/EyeOutlined';
66
import EyeInvisibleOutlined from '@ant-design/icons-vue/EyeInvisibleOutlined';
77
import type { InputProps } from './inputProps';
88
import inputProps from './inputProps';
9-
import type { PropType, Ref, ShallowRef } from 'vue';
10-
import { computed, defineComponent, shallowRef, watch } from 'vue';
9+
import { computed, defineComponent, shallowRef, watch, watchEffect } from 'vue';
1110
import useConfigInject from '../config-provider/hooks/useConfigInject';
1211
import omit from '../_util/omit';
13-
14-
type VisibilityToggleProps =
15-
| boolean
16-
| {
17-
visible: Ref<boolean>;
18-
onVisibleChange: (visible: boolean) => void;
19-
};
12+
import { functionType } from '../_util/type';
2013

2114
const ActionMap = {
2215
click: 'onClick',
2316
hover: 'onMouseover',
2417
};
25-
2618
const defaultIconRender = (visible: boolean) =>
2719
visible ? <EyeOutlined /> : <EyeInvisibleOutlined />;
28-
2920
export default defineComponent({
3021
compatConfig: { MODE: 3 },
3122
name: 'AInputPassword',
@@ -35,28 +26,28 @@ export default defineComponent({
3526
prefixCls: String,
3627
inputPrefixCls: String,
3728
action: { type: String, default: 'click' },
38-
visibilityToggle: {
39-
type: [Boolean, Object] as PropType<VisibilityToggleProps>,
40-
default: true,
41-
},
42-
iconRender: Function,
29+
visibilityToggle: { type: Boolean, default: true },
4330
visible: { type: Boolean, default: undefined },
44-
onUpdate:visible: Function as PropType<(visible: boolean) => void>;
31+
'onUpdate:visible': functionType<(visible: boolean) => void>,
32+
iconRender: Function,
4533
},
46-
setup(props, { slots, attrs, expose }) {
34+
setup(props, { slots, attrs, expose, emit }) {
4735
const visible = shallowRef(false);
48-
const onVisibleChange(v: boolean) {
49-
const { disabled } = props;
50-
if (disabled) {
51-
return;
52-
}
53-
props['onUpdate:visible']?.(!v);
54-
}
55-
watchEffect(()=> {
56-
if(props.visible !== undefined) {
57-
visible.value = props.visible;
36+
const onVisibleChange = () => {
37+
const { disabled } = props;
38+
if (disabled) {
39+
return;
40+
}
41+
if (props.visible === undefined) {
42+
visible.value = !visible.value;
5843
}
59-
})
44+
emit('update:visible', !visible.value);
45+
};
46+
watchEffect(() => {
47+
if (props.visible !== undefined) {
48+
visible.value = !!props.visible;
49+
}
50+
});
6051
const inputRef = shallowRef();
6152
const focus = () => {
6253
inputRef.value?.focus();
@@ -94,9 +85,7 @@ export default defineComponent({
9485
const renderPassword = () => {
9586
const { size, visibilityToggle, ...restProps } = props;
9687

97-
const suffixIcon =
98-
(typeof visibilityToggle === 'boolean' ? visibilityToggle : true) &&
99-
getIcon(prefixCls.value);
88+
const suffixIcon = visibilityToggle && getIcon(prefixCls.value);
10089
const inputClassName = classNames(prefixCls.value, attrs.class, {
10190
[`${prefixCls.value}-${size}`]: !!size,
10291
});

0 commit comments

Comments
 (0)