@@ -6,26 +6,17 @@ import EyeOutlined from '@ant-design/icons-vue/EyeOutlined';
6
6
import EyeInvisibleOutlined from '@ant-design/icons-vue/EyeInvisibleOutlined' ;
7
7
import type { InputProps } from './inputProps' ;
8
8
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' ;
11
10
import useConfigInject from '../config-provider/hooks/useConfigInject' ;
12
11
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' ;
20
13
21
14
const ActionMap = {
22
15
click : 'onClick' ,
23
16
hover : 'onMouseover' ,
24
17
} ;
25
-
26
18
const defaultIconRender = ( visible : boolean ) =>
27
19
visible ? < EyeOutlined /> : < EyeInvisibleOutlined /> ;
28
-
29
20
export default defineComponent ( {
30
21
compatConfig : { MODE : 3 } ,
31
22
name : 'AInputPassword' ,
@@ -35,28 +26,28 @@ export default defineComponent({
35
26
prefixCls : String ,
36
27
inputPrefixCls : String ,
37
28
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 } ,
43
30
visible : { type : Boolean , default : undefined } ,
44
- onUpdate :visible : Function as PropType < ( visible : boolean ) => void > ;
31
+ 'onUpdate:visible' : functionType < ( visible : boolean ) => void > ,
32
+ iconRender : Function ,
45
33
} ,
46
- setup ( props , { slots, attrs, expose } ) {
34
+ setup ( props , { slots, attrs, expose, emit } ) {
47
35
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 ;
58
43
}
59
- } )
44
+ emit ( 'update:visible' , ! visible . value ) ;
45
+ } ;
46
+ watchEffect ( ( ) => {
47
+ if ( props . visible !== undefined ) {
48
+ visible . value = ! ! props . visible ;
49
+ }
50
+ } ) ;
60
51
const inputRef = shallowRef ( ) ;
61
52
const focus = ( ) => {
62
53
inputRef . value ?. focus ( ) ;
@@ -94,9 +85,7 @@ export default defineComponent({
94
85
const renderPassword = ( ) => {
95
86
const { size, visibilityToggle, ...restProps } = props ;
96
87
97
- const suffixIcon =
98
- ( typeof visibilityToggle === 'boolean' ? visibilityToggle : true ) &&
99
- getIcon ( prefixCls . value ) ;
88
+ const suffixIcon = visibilityToggle && getIcon ( prefixCls . value ) ;
100
89
const inputClassName = classNames ( prefixCls . value , attrs . class , {
101
90
[ `${ prefixCls . value } -${ size } ` ] : ! ! size ,
102
91
} ) ;
0 commit comments