1
1
import classNames from '../_util/classNames' ;
2
2
import { getComponent , getOptionProps } from '../_util/props-util' ;
3
+ import { cloneElement } from '../_util/vnode' ;
3
4
import Input from './Input' ;
4
5
import EyeOutlined from '@ant-design/icons-vue/EyeOutlined' ;
5
6
import EyeInvisibleOutlined from '@ant-design/icons-vue/EyeInvisibleOutlined' ;
@@ -23,6 +24,9 @@ export default defineComponent({
23
24
inputPrefixCls : PropTypes . string . def ( 'ant-input' ) ,
24
25
action : PropTypes . string . def ( 'click' ) ,
25
26
visibilityToggle : PropTypes . looseBool . def ( true ) ,
27
+ iconRender : PropTypes . func . def ( ( visible : boolean ) =>
28
+ visible ? < EyeOutlined /> : < EyeInvisibleOutlined /> ,
29
+ ) ,
26
30
} ,
27
31
setup ( ) {
28
32
return {
@@ -55,6 +59,8 @@ export default defineComponent({
55
59
getIcon ( ) {
56
60
const { prefixCls, action } = this . $props ;
57
61
const iconTrigger = ActionMap [ action ] || '' ;
62
+ const iconRender = this . $slots . iconRender || this . $props . iconRender ;
63
+ const icon = iconRender ( this . visible ) ;
58
64
const iconProps = {
59
65
[ iconTrigger ] : this . onVisibleChange ,
60
66
onMousedown : ( e : Event ) => {
@@ -70,11 +76,7 @@ export default defineComponent({
70
76
class : `${ prefixCls } -icon` ,
71
77
key : 'passwordIcon' ,
72
78
} ;
73
- return this . visible ? (
74
- < EyeOutlined { ...iconProps } />
75
- ) : (
76
- < EyeInvisibleOutlined { ...iconProps } />
77
- ) ;
79
+ return cloneElement ( icon , iconProps ) ;
78
80
} ,
79
81
} ,
80
82
render ( ) {
0 commit comments