11import classNames from '../_util/classNames' ;
22import { getComponent , getOptionProps } from '../_util/props-util' ;
3+ import { cloneElement } from '../_util/vnode' ;
34import Input from './Input' ;
45import EyeOutlined from '@ant-design/icons-vue/EyeOutlined' ;
56import EyeInvisibleOutlined from '@ant-design/icons-vue/EyeInvisibleOutlined' ;
@@ -23,6 +24,9 @@ export default defineComponent({
2324 inputPrefixCls : PropTypes . string . def ( 'ant-input' ) ,
2425 action : PropTypes . string . def ( 'click' ) ,
2526 visibilityToggle : PropTypes . looseBool . def ( true ) ,
27+ iconRender : PropTypes . func . def ( ( visible : boolean ) =>
28+ visible ? < EyeOutlined /> : < EyeInvisibleOutlined /> ,
29+ ) ,
2630 } ,
2731 setup ( ) {
2832 return {
@@ -55,6 +59,8 @@ export default defineComponent({
5559 getIcon ( ) {
5660 const { prefixCls, action } = this . $props ;
5761 const iconTrigger = ActionMap [ action ] || '' ;
62+ const iconRender = this . $slots . iconRender || this . $props . iconRender ;
63+ const icon = iconRender ( this . visible ) ;
5864 const iconProps = {
5965 [ iconTrigger ] : this . onVisibleChange ,
6066 onMousedown : ( e : Event ) => {
@@ -70,11 +76,7 @@ export default defineComponent({
7076 class : `${ prefixCls } -icon` ,
7177 key : 'passwordIcon' ,
7278 } ;
73- return this . visible ? (
74- < EyeOutlined { ...iconProps } />
75- ) : (
76- < EyeInvisibleOutlined { ...iconProps } />
77- ) ;
79+ return cloneElement ( icon , iconProps ) ;
7880 } ,
7981 } ,
8082 render ( ) {
0 commit comments